@Test public void shouldPopulateBudgetLineItemDTO() throws Exception { List<String> fieldsInOneRow = asList("HIV", "F10", "2013-12-10", "345.45", "My good notes"); Collection<EDIFileColumn> columns = new ArrayList<EDIFileColumn>() {{ add(new EDIFileColumn("facilityCode", "header.facility.code", true, true, 2, "")); add(new EDIFileColumn("programCode", "header.program.code", true, true, 1, "")); }}; BudgetLineItemDTO budgetLineItemDTO = BudgetLineItemDTO.populate(fieldsInOneRow, columns); assertEquals("F10", budgetLineItemDTO.getFacilityCode()); assertEquals("HIV", budgetLineItemDTO.getProgramCode()); assertEquals(null, budgetLineItemDTO.getPeriodStartDate()); assertEquals(null, budgetLineItemDTO.getAllocatedBudget()); assertEquals(null, budgetLineItemDTO.getNotes()); }
public static BudgetLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> budgetFileColumns) { BudgetLineItemDTO lineItemDTO = new BudgetLineItemDTO(); for (EDIFileColumn budgetFileColumn : budgetFileColumns) { Integer position = budgetFileColumn.getPosition(); String name = budgetFileColumn.getName(); try { Field field = BudgetLineItemDTO.class.getDeclaredField(name); field.setAccessible(true); field.set(lineItemDTO, fieldsInOneRow.get(position - 1).trim()); } catch (Exception e) { logger.error("Unable to set field '" + name + "' in BudgetLinetItemDTO, check mapping between DTO and BudgetFileColumn", e); } } return lineItemDTO; }
BudgetLineItemDTO { public static BudgetLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> budgetFileColumns) { BudgetLineItemDTO lineItemDTO = new BudgetLineItemDTO(); for (EDIFileColumn budgetFileColumn : budgetFileColumns) { Integer position = budgetFileColumn.getPosition(); String name = budgetFileColumn.getName(); try { Field field = BudgetLineItemDTO.class.getDeclaredField(name); field.setAccessible(true); field.set(lineItemDTO, fieldsInOneRow.get(position - 1).trim()); } catch (Exception e) { logger.error("Unable to set field '" + name + "' in BudgetLinetItemDTO, check mapping between DTO and BudgetFileColumn", e); } } return lineItemDTO; } }
BudgetLineItemDTO { public static BudgetLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> budgetFileColumns) { BudgetLineItemDTO lineItemDTO = new BudgetLineItemDTO(); for (EDIFileColumn budgetFileColumn : budgetFileColumns) { Integer position = budgetFileColumn.getPosition(); String name = budgetFileColumn.getName(); try { Field field = BudgetLineItemDTO.class.getDeclaredField(name); field.setAccessible(true); field.set(lineItemDTO, fieldsInOneRow.get(position - 1).trim()); } catch (Exception e) { logger.error("Unable to set field '" + name + "' in BudgetLinetItemDTO, check mapping between DTO and BudgetFileColumn", e); } } return lineItemDTO; }  }
BudgetLineItemDTO { public static BudgetLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> budgetFileColumns) { BudgetLineItemDTO lineItemDTO = new BudgetLineItemDTO(); for (EDIFileColumn budgetFileColumn : budgetFileColumns) { Integer position = budgetFileColumn.getPosition(); String name = budgetFileColumn.getName(); try { Field field = BudgetLineItemDTO.class.getDeclaredField(name); field.setAccessible(true); field.set(lineItemDTO, fieldsInOneRow.get(position - 1).trim()); } catch (Exception e) { logger.error("Unable to set field '" + name + "' in BudgetLinetItemDTO, check mapping between DTO and BudgetFileColumn", e); } } return lineItemDTO; }  static BudgetLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> budgetFileColumns); void checkMandatoryFields(); }
BudgetLineItemDTO { public static BudgetLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> budgetFileColumns) { BudgetLineItemDTO lineItemDTO = new BudgetLineItemDTO(); for (EDIFileColumn budgetFileColumn : budgetFileColumns) { Integer position = budgetFileColumn.getPosition(); String name = budgetFileColumn.getName(); try { Field field = BudgetLineItemDTO.class.getDeclaredField(name); field.setAccessible(true); field.set(lineItemDTO, fieldsInOneRow.get(position - 1).trim()); } catch (Exception e) { logger.error("Unable to set field '" + name + "' in BudgetLinetItemDTO, check mapping between DTO and BudgetFileColumn", e); } } return lineItemDTO; }  static BudgetLineItemDTO populate(List<String> fieldsInOneRow, Collection<EDIFileColumn> budgetFileColumns); void checkMandatoryFields();  }