@Test public void shouldGetTemplateForNewProgram() throws Exception { List<LogisticsColumn> masterColumns = new ArrayList<LogisticsColumn>(); masterColumns.add(new LogisticsColumn()); List<LogisticsColumn> emptyList = new ArrayList<>(); ProgramColumnTemplateDTO dto = new ProgramColumnTemplateDTO(); dto.setProgramId(1L); dto.setColumns(emptyList); when(repository.getTemplateForProgram(1L)).thenReturn(emptyList); when(repository.getMasterColumns()).thenReturn(masterColumns); ProgramColumnTemplateDTO columnsDto = service.getTemplate(1L); assertThat(columnsDto.getColumns().size(), is(1)); assertThat(columnsDto.getProgramId(), is(1L)); }
public ProgramColumnTemplateDTO getTemplate(Long programId) { List<LogisticsColumn> columns = repository.getTemplateForProgram(programId); if(columns == null || columns.isEmpty()){ columns = repository.getMasterColumns(); for(LogisticsColumn column: columns){ column.setProgramId(programId); column.setId(null); column.setVisible(true); } } ProgramColumnTemplateDTO dto = new ProgramColumnTemplateDTO(); dto.setProgramId(programId); dto.setColumns(columns); return dto; }
VaccineColumnTemplateService { public ProgramColumnTemplateDTO getTemplate(Long programId) { List<LogisticsColumn> columns = repository.getTemplateForProgram(programId); if(columns == null || columns.isEmpty()){ columns = repository.getMasterColumns(); for(LogisticsColumn column: columns){ column.setProgramId(programId); column.setId(null); column.setVisible(true); } } ProgramColumnTemplateDTO dto = new ProgramColumnTemplateDTO(); dto.setProgramId(programId); dto.setColumns(columns); return dto; } }
VaccineColumnTemplateService { public ProgramColumnTemplateDTO getTemplate(Long programId) { List<LogisticsColumn> columns = repository.getTemplateForProgram(programId); if(columns == null || columns.isEmpty()){ columns = repository.getMasterColumns(); for(LogisticsColumn column: columns){ column.setProgramId(programId); column.setId(null); column.setVisible(true); } } ProgramColumnTemplateDTO dto = new ProgramColumnTemplateDTO(); dto.setProgramId(programId); dto.setColumns(columns); return dto; }  }
VaccineColumnTemplateService { public ProgramColumnTemplateDTO getTemplate(Long programId) { List<LogisticsColumn> columns = repository.getTemplateForProgram(programId); if(columns == null || columns.isEmpty()){ columns = repository.getMasterColumns(); for(LogisticsColumn column: columns){ column.setProgramId(programId); column.setId(null); column.setVisible(true); } } ProgramColumnTemplateDTO dto = new ProgramColumnTemplateDTO(); dto.setProgramId(programId); dto.setColumns(columns); return dto; }  ProgramColumnTemplateDTO getTemplate(Long programId); void saveChanges(List<LogisticsColumn> columns); }
VaccineColumnTemplateService { public ProgramColumnTemplateDTO getTemplate(Long programId) { List<LogisticsColumn> columns = repository.getTemplateForProgram(programId); if(columns == null || columns.isEmpty()){ columns = repository.getMasterColumns(); for(LogisticsColumn column: columns){ column.setProgramId(programId); column.setId(null); column.setVisible(true); } } ProgramColumnTemplateDTO dto = new ProgramColumnTemplateDTO(); dto.setProgramId(programId); dto.setColumns(columns); return dto; }  ProgramColumnTemplateDTO getTemplate(Long programId); void saveChanges(List<LogisticsColumn> columns);  }