@Test public void shouldThrowExceptionIfBaseFacilityIsVirtualFacility() throws Exception { Agent agent = make(a(defaultCHW)); Facility baseFacility = getBaseFacility(agent); baseFacility.setVirtualFacility(true); when(facilityService.getFacilityWithReferenceDataForCode(agent.getParentFacilityCode())).thenReturn(baseFacility); expectedException.expect(DataException.class); expectedException.expectMessage("error.reference.data.parent.facility.virtual"); restAgentService.create(agent, user.getId()); }
@Transactional public void create(Agent agent, Long userId) { agent.validate(); if (getExistingFacilityForCode(agent.getAgentCode()) != null) { throw new DataException("error.agent.already.registered"); } Facility facility = createFacilityFrom(agent); facility.setCreatedBy(userId); facility.setModifiedBy(userId); facilityService.save(facility); programSupportedService.updateSupportedPrograms(facility); saveRequisitionGroupMembers(facility, userId); }
RestAgentService { @Transactional public void create(Agent agent, Long userId) { agent.validate(); if (getExistingFacilityForCode(agent.getAgentCode()) != null) { throw new DataException("error.agent.already.registered"); } Facility facility = createFacilityFrom(agent); facility.setCreatedBy(userId); facility.setModifiedBy(userId); facilityService.save(facility); programSupportedService.updateSupportedPrograms(facility); saveRequisitionGroupMembers(facility, userId); } }
RestAgentService { @Transactional public void create(Agent agent, Long userId) { agent.validate(); if (getExistingFacilityForCode(agent.getAgentCode()) != null) { throw new DataException("error.agent.already.registered"); } Facility facility = createFacilityFrom(agent); facility.setCreatedBy(userId); facility.setModifiedBy(userId); facilityService.save(facility); programSupportedService.updateSupportedPrograms(facility); saveRequisitionGroupMembers(facility, userId); }  }
RestAgentService { @Transactional public void create(Agent agent, Long userId) { agent.validate(); if (getExistingFacilityForCode(agent.getAgentCode()) != null) { throw new DataException("error.agent.already.registered"); } Facility facility = createFacilityFrom(agent); facility.setCreatedBy(userId); facility.setModifiedBy(userId); facilityService.save(facility); programSupportedService.updateSupportedPrograms(facility); saveRequisitionGroupMembers(facility, userId); }  @Transactional void create(Agent agent, Long userId); void update(Agent agent, Long userId); }
RestAgentService { @Transactional public void create(Agent agent, Long userId) { agent.validate(); if (getExistingFacilityForCode(agent.getAgentCode()) != null) { throw new DataException("error.agent.already.registered"); } Facility facility = createFacilityFrom(agent); facility.setCreatedBy(userId); facility.setModifiedBy(userId); facilityService.save(facility); programSupportedService.updateSupportedPrograms(facility); saveRequisitionGroupMembers(facility, userId); }  @Transactional void create(Agent agent, Long userId); void update(Agent agent, Long userId);  }