@Test public void shouldThrowExceptionIfCHWIsNotVirtualOnUpdate() throws Exception { Agent agent = make(a(defaultCHW)); Facility nonVirtualFacility = new Facility(); nonVirtualFacility.setVirtualFacility(false); nonVirtualFacility.setCode(agent.getAgentCode()); when(facilityService.getByCode(nonVirtualFacility)).thenReturn(nonVirtualFacility); expectedException.expect(DataException.class); expectedException.expectMessage("error.agent.not.virtual"); restAgentService.update(agent, user.getId()); }
public void update(Agent agent, Long userId) { if (agent.getActive() == null) { throw new DataException("error.mandatory.fields.missing"); } agent.validate(); Facility chwFacility = getExistingFacilityForCode(agent.getAgentCode()); validateCHWForUpdate(chwFacility); chwFacility.setName(agent.getAgentName()); chwFacility.setMainPhone(agent.getPhoneNumber() == null ? chwFacility.getMainPhone() : agent.getPhoneNumber()); chwFacility.setActive(Boolean.parseBoolean(agent.getActive())); Long previousParent = chwFacility.getParentFacilityId(); fillBaseFacility(agent, chwFacility); if (!previousParent.equals(chwFacility.getParentFacilityId())) { requisitionGroupMemberService.deleteMembersFor(chwFacility); saveRequisitionGroupMembers(chwFacility, userId); } chwFacility.setModifiedDate(new Date()); chwFacility.setModifiedBy(userId); facilityService.update(chwFacility); }
RestAgentService { public void update(Agent agent, Long userId) { if (agent.getActive() == null) { throw new DataException("error.mandatory.fields.missing"); } agent.validate(); Facility chwFacility = getExistingFacilityForCode(agent.getAgentCode()); validateCHWForUpdate(chwFacility); chwFacility.setName(agent.getAgentName()); chwFacility.setMainPhone(agent.getPhoneNumber() == null ? chwFacility.getMainPhone() : agent.getPhoneNumber()); chwFacility.setActive(Boolean.parseBoolean(agent.getActive())); Long previousParent = chwFacility.getParentFacilityId(); fillBaseFacility(agent, chwFacility); if (!previousParent.equals(chwFacility.getParentFacilityId())) { requisitionGroupMemberService.deleteMembersFor(chwFacility); saveRequisitionGroupMembers(chwFacility, userId); } chwFacility.setModifiedDate(new Date()); chwFacility.setModifiedBy(userId); facilityService.update(chwFacility); } }
RestAgentService { public void update(Agent agent, Long userId) { if (agent.getActive() == null) { throw new DataException("error.mandatory.fields.missing"); } agent.validate(); Facility chwFacility = getExistingFacilityForCode(agent.getAgentCode()); validateCHWForUpdate(chwFacility); chwFacility.setName(agent.getAgentName()); chwFacility.setMainPhone(agent.getPhoneNumber() == null ? chwFacility.getMainPhone() : agent.getPhoneNumber()); chwFacility.setActive(Boolean.parseBoolean(agent.getActive())); Long previousParent = chwFacility.getParentFacilityId(); fillBaseFacility(agent, chwFacility); if (!previousParent.equals(chwFacility.getParentFacilityId())) { requisitionGroupMemberService.deleteMembersFor(chwFacility); saveRequisitionGroupMembers(chwFacility, userId); } chwFacility.setModifiedDate(new Date()); chwFacility.setModifiedBy(userId); facilityService.update(chwFacility); }  }
RestAgentService { public void update(Agent agent, Long userId) { if (agent.getActive() == null) { throw new DataException("error.mandatory.fields.missing"); } agent.validate(); Facility chwFacility = getExistingFacilityForCode(agent.getAgentCode()); validateCHWForUpdate(chwFacility); chwFacility.setName(agent.getAgentName()); chwFacility.setMainPhone(agent.getPhoneNumber() == null ? chwFacility.getMainPhone() : agent.getPhoneNumber()); chwFacility.setActive(Boolean.parseBoolean(agent.getActive())); Long previousParent = chwFacility.getParentFacilityId(); fillBaseFacility(agent, chwFacility); if (!previousParent.equals(chwFacility.getParentFacilityId())) { requisitionGroupMemberService.deleteMembersFor(chwFacility); saveRequisitionGroupMembers(chwFacility, userId); } chwFacility.setModifiedDate(new Date()); chwFacility.setModifiedBy(userId); facilityService.update(chwFacility); }  @Transactional void create(Agent agent, Long userId); void update(Agent agent, Long userId); }
RestAgentService { public void update(Agent agent, Long userId) { if (agent.getActive() == null) { throw new DataException("error.mandatory.fields.missing"); } agent.validate(); Facility chwFacility = getExistingFacilityForCode(agent.getAgentCode()); validateCHWForUpdate(chwFacility); chwFacility.setName(agent.getAgentName()); chwFacility.setMainPhone(agent.getPhoneNumber() == null ? chwFacility.getMainPhone() : agent.getPhoneNumber()); chwFacility.setActive(Boolean.parseBoolean(agent.getActive())); Long previousParent = chwFacility.getParentFacilityId(); fillBaseFacility(agent, chwFacility); if (!previousParent.equals(chwFacility.getParentFacilityId())) { requisitionGroupMemberService.deleteMembersFor(chwFacility); saveRequisitionGroupMembers(chwFacility, userId); } chwFacility.setModifiedDate(new Date()); chwFacility.setModifiedBy(userId); facilityService.update(chwFacility); }  @Transactional void create(Agent agent, Long userId); void update(Agent agent, Long userId);  }