@Test public void shouldPopulateShipmentLineItemDTO() throws Exception { List<String> fieldsInOneRow = asList("OYELL_FVR00000123R", "P10", "2", "45", "12-10-2013", "14-09-2013"); Collection<EDIFileColumn> shipmentFileColumns = asList(new EDIFileColumn("orderId", "label.order.id", true, true, 1, ""), new EDIFileColumn("productCode", "label.product.code", true, true, 2, "")); ShipmentLineItemDTO shipmentLineItemDTO = ShipmentLineItemDTO.populate(fieldsInOneRow, shipmentFileColumns); assertThat(shipmentLineItemDTO.getOrderNumber(), is("OYELL_FVR00000123R")); assertThat(shipmentLineItemDTO.getProductCode(), is("P10")); assertThat(shipmentLineItemDTO.getCost(), is(nullValue())); assertThat(shipmentLineItemDTO.getPackedDate(), is(nullValue())); assertThat(shipmentLineItemDTO.getShippedDate(), is(nullValue())); assertThat(shipmentLineItemDTO.getQuantityShipped(), is(nullValue())); }
public static ShipmentLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> shipmentFileColumns) { ShipmentLineItemDTO dto = new ShipmentLineItemDTO(); for (EDIFileColumn shipmentFileColumn : shipmentFileColumns) { Integer position = shipmentFileColumn.getPosition(); String name = shipmentFileColumn.getName(); try { Field field = ShipmentLineItemDTO.class.getDeclaredField(name); field.setAccessible(true); field.set(dto, fieldsInOneRow.get(position - 1)); } catch (Exception e) { logger.error("Unable to set field '" + name + "' in ShipmentLinetItemDTO, check mapping between DTO and ShipmentFileColumn", e); } } return dto; }
ShipmentLineItemDTO { public static ShipmentLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> shipmentFileColumns) { ShipmentLineItemDTO dto = new ShipmentLineItemDTO(); for (EDIFileColumn shipmentFileColumn : shipmentFileColumns) { Integer position = shipmentFileColumn.getPosition(); String name = shipmentFileColumn.getName(); try { Field field = ShipmentLineItemDTO.class.getDeclaredField(name); field.setAccessible(true); field.set(dto, fieldsInOneRow.get(position - 1)); } catch (Exception e) { logger.error("Unable to set field '" + name + "' in ShipmentLinetItemDTO, check mapping between DTO and ShipmentFileColumn", e); } } return dto; } }
ShipmentLineItemDTO { public static ShipmentLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> shipmentFileColumns) { ShipmentLineItemDTO dto = new ShipmentLineItemDTO(); for (EDIFileColumn shipmentFileColumn : shipmentFileColumns) { Integer position = shipmentFileColumn.getPosition(); String name = shipmentFileColumn.getName(); try { Field field = ShipmentLineItemDTO.class.getDeclaredField(name); field.setAccessible(true); field.set(dto, fieldsInOneRow.get(position - 1)); } catch (Exception e) { logger.error("Unable to set field '" + name + "' in ShipmentLinetItemDTO, check mapping between DTO and ShipmentFileColumn", e); } } return dto; } ShipmentLineItemDTO(String orderNumber, String productCode, String replacedProductCode, String quantityShipped,
                             String cost, String packedDate, String shippedDate); }
ShipmentLineItemDTO { public static ShipmentLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> shipmentFileColumns) { ShipmentLineItemDTO dto = new ShipmentLineItemDTO(); for (EDIFileColumn shipmentFileColumn : shipmentFileColumns) { Integer position = shipmentFileColumn.getPosition(); String name = shipmentFileColumn.getName(); try { Field field = ShipmentLineItemDTO.class.getDeclaredField(name); field.setAccessible(true); field.set(dto, fieldsInOneRow.get(position - 1)); } catch (Exception e) { logger.error("Unable to set field '" + name + "' in ShipmentLinetItemDTO, check mapping between DTO and ShipmentFileColumn", e); } } return dto; } ShipmentLineItemDTO(String orderNumber, String productCode, String replacedProductCode, String quantityShipped,
                             String cost, String packedDate, String shippedDate); void checkMandatoryFields(); static ShipmentLineItemDTO populate(List<String> fieldsInOneRow,
                                             Collection<EDIFileColumn> shipmentFileColumns); }
ShipmentLineItemDTO { public static ShipmentLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> shipmentFileColumns) { ShipmentLineItemDTO dto = new ShipmentLineItemDTO(); for (EDIFileColumn shipmentFileColumn : shipmentFileColumns) { Integer position = shipmentFileColumn.getPosition(); String name = shipmentFileColumn.getName(); try { Field field = ShipmentLineItemDTO.class.getDeclaredField(name); field.setAccessible(true); field.set(dto, fieldsInOneRow.get(position - 1)); } catch (Exception e) { logger.error("Unable to set field '" + name + "' in ShipmentLinetItemDTO, check mapping between DTO and ShipmentFileColumn", e); } } return dto; } ShipmentLineItemDTO(String orderNumber, String productCode, String replacedProductCode, String quantityShipped,
                             String cost, String packedDate, String shippedDate); void checkMandatoryFields(); static ShipmentLineItemDTO populate(List<String> fieldsInOneRow,
                                             Collection<EDIFileColumn> shipmentFileColumns);  }