@Test public void shouldInsertProgramSupportedIfDoesNotExist() { ProgramSupported programSupported = new ProgramSupported(); programSupported.setFacilityCode("F1"); Program program = new Program(); program.setCode("P1"); programSupported.setProgram(program); programSupported.setModifiedDate(new Date()); Facility facility = new Facility(); facility.setCode("F1"); when(facilityService.getByCode(facility)).thenReturn(new Facility(1L)); when(programService.getByCode("P1")).thenReturn(new Program(1L)); service.uploadSupportedProgram(programSupported); }
public void uploadSupportedProgram(ProgramSupported programSupported) { programSupported.isValid(); Facility facility = new Facility(); facility.setCode(programSupported.getFacilityCode()); facility = facilityService.getByCode(facility); programSupported.setFacilityId(facility.getId()); Program program = programService.getByCode(programSupported.getProgram().getCode()); programSupported.setProgram(program); if (programSupported.getId() == null) { repository.addSupportedProgram(programSupported); } else { repository.updateSupportedProgram(programSupported); } }
ProgramSupportedService { public void uploadSupportedProgram(ProgramSupported programSupported) { programSupported.isValid(); Facility facility = new Facility(); facility.setCode(programSupported.getFacilityCode()); facility = facilityService.getByCode(facility); programSupported.setFacilityId(facility.getId()); Program program = programService.getByCode(programSupported.getProgram().getCode()); programSupported.setProgram(program); if (programSupported.getId() == null) { repository.addSupportedProgram(programSupported); } else { repository.updateSupportedProgram(programSupported); } } }
ProgramSupportedService { public void uploadSupportedProgram(ProgramSupported programSupported) { programSupported.isValid(); Facility facility = new Facility(); facility.setCode(programSupported.getFacilityCode()); facility = facilityService.getByCode(facility); programSupported.setFacilityId(facility.getId()); Program program = programService.getByCode(programSupported.getProgram().getCode()); programSupported.setProgram(program); if (programSupported.getId() == null) { repository.addSupportedProgram(programSupported); } else { repository.updateSupportedProgram(programSupported); } }  }
ProgramSupportedService { public void uploadSupportedProgram(ProgramSupported programSupported) { programSupported.isValid(); Facility facility = new Facility(); facility.setCode(programSupported.getFacilityCode()); facility = facilityService.getByCode(facility); programSupported.setFacilityId(facility.getId()); Program program = programService.getByCode(programSupported.getProgram().getCode()); programSupported.setProgram(program); if (programSupported.getId() == null) { repository.addSupportedProgram(programSupported); } else { repository.updateSupportedProgram(programSupported); } }  List<ProgramSupported> getAllByFacilityId(Long facilityId); void updateSupportedPrograms(Facility facility); ProgramSupported getFilledByFacilityIdAndProgramId(Long facilityId, Long programId); ProgramSupported getByFacilityIdAndProgramId(Long facilityId, Long programId); void uploadSupportedProgram(ProgramSupported programSupported); ProgramSupported getProgramSupported(ProgramSupported programSupported); void notifyProgramSupportedUpdated(Facility facility); List<ProgramSupported> getActiveByFacilityId(Long facilityId); void updateForVirtualFacilities(Facility parentFacility); }
ProgramSupportedService { public void uploadSupportedProgram(ProgramSupported programSupported) { programSupported.isValid(); Facility facility = new Facility(); facility.setCode(programSupported.getFacilityCode()); facility = facilityService.getByCode(facility); programSupported.setFacilityId(facility.getId()); Program program = programService.getByCode(programSupported.getProgram().getCode()); programSupported.setProgram(program); if (programSupported.getId() == null) { repository.addSupportedProgram(programSupported); } else { repository.updateSupportedProgram(programSupported); } }  List<ProgramSupported> getAllByFacilityId(Long facilityId); void updateSupportedPrograms(Facility facility); ProgramSupported getFilledByFacilityIdAndProgramId(Long facilityId, Long programId); ProgramSupported getByFacilityIdAndProgramId(Long facilityId, Long programId); void uploadSupportedProgram(ProgramSupported programSupported); ProgramSupported getProgramSupported(ProgramSupported programSupported); void notifyProgramSupportedUpdated(Facility facility); List<ProgramSupported> getActiveByFacilityId(Long facilityId); void updateForVirtualFacilities(Facility parentFacility);  }