@Test public void shouldNotGetHomeFacilityWhenItIsNull() throws Exception { String[] rightNames = {VIEW_REQUISITION, APPROVE_REQUISITION}; Facility supervisedFacility = new Facility(); List<Facility> supervisedFacilities = new ArrayList<>(); supervisedFacilities.add(supervisedFacility); List<SupervisoryNode> supervisoryNodes = new ArrayList<>(); List<RequisitionGroup> requisitionGroups = new ArrayList<>(); when(facilityRepository.getHomeFacilityForRights(1L, rightNames)).thenReturn(null); when(supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(1L, rightNames)).thenReturn(supervisoryNodes); when(requisitionGroupService.getRequisitionGroupsBy(supervisoryNodes)).thenReturn(requisitionGroups); when(facilityRepository.getAllInRequisitionGroups(requisitionGroups)).thenReturn(supervisedFacilities); List<Facility> actualFacilities = facilityService.getForUserAndRights(1L, rightNames); assertThat(actualFacilities, is(supervisedFacilities)); assertThat(actualFacilities.size(), is(1)); verify(facilityRepository).getHomeFacilityForRights(1L, rightNames); verify(supervisoryNodeService).getAllSupervisoryNodesInHierarchyBy(1L, rightNames); verify(requisitionGroupService).getRequisitionGroupsBy(supervisoryNodes); verify(facilityRepository).getAllInRequisitionGroups(requisitionGroups); }
public List<Facility> getForUserAndRights(Long userId, String... rightNames) { List<SupervisoryNode> supervisoryNodesInHierarchy = supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, rightNames); List<RequisitionGroup> requisitionGroups = requisitionGroupService.getRequisitionGroupsBy(supervisoryNodesInHierarchy); final Set<Facility> userFacilities = new HashSet<>(facilityRepository.getAllInRequisitionGroups(requisitionGroups)); final Facility homeFacility = facilityRepository.getHomeFacilityForRights(userId, rightNames); if (homeFacility != null) userFacilities.add(homeFacility); return new ArrayList<>(userFacilities); }
FacilityService { public List<Facility> getForUserAndRights(Long userId, String... rightNames) { List<SupervisoryNode> supervisoryNodesInHierarchy = supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, rightNames); List<RequisitionGroup> requisitionGroups = requisitionGroupService.getRequisitionGroupsBy(supervisoryNodesInHierarchy); final Set<Facility> userFacilities = new HashSet<>(facilityRepository.getAllInRequisitionGroups(requisitionGroups)); final Facility homeFacility = facilityRepository.getHomeFacilityForRights(userId, rightNames); if (homeFacility != null) userFacilities.add(homeFacility); return new ArrayList<>(userFacilities); } }
FacilityService { public List<Facility> getForUserAndRights(Long userId, String... rightNames) { List<SupervisoryNode> supervisoryNodesInHierarchy = supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, rightNames); List<RequisitionGroup> requisitionGroups = requisitionGroupService.getRequisitionGroupsBy(supervisoryNodesInHierarchy); final Set<Facility> userFacilities = new HashSet<>(facilityRepository.getAllInRequisitionGroups(requisitionGroups)); final Facility homeFacility = facilityRepository.getHomeFacilityForRights(userId, rightNames); if (homeFacility != null) userFacilities.add(homeFacility); return new ArrayList<>(userFacilities); }  }
FacilityService { public List<Facility> getForUserAndRights(Long userId, String... rightNames) { List<SupervisoryNode> supervisoryNodesInHierarchy = supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, rightNames); List<RequisitionGroup> requisitionGroups = requisitionGroupService.getRequisitionGroupsBy(supervisoryNodesInHierarchy); final Set<Facility> userFacilities = new HashSet<>(facilityRepository.getAllInRequisitionGroups(requisitionGroups)); final Facility homeFacility = facilityRepository.getHomeFacilityForRights(userId, rightNames); if (homeFacility != null) userFacilities.add(homeFacility); return new ArrayList<>(userFacilities); }  @Transactional void update(Facility facility); List<FacilityType> getAllTypes(); List<GeographicZone> getAllZones(); Facility getHomeFacility(Long userId); Facility getById(Long id); @Transactional void updateEnabledAndActiveFor(Facility facility); List<Facility> getUserSupervisedFacilities(Long userId, Long programId, String... rightNames); void save(Facility newFacility); void updateAndNotifyForVirtualFacilities(Facility parentFacility); List<Facility> getForUserAndRights(Long userId, String... rightNames); FacilityType getFacilityTypeByCode(FacilityType facilityType); Facility getByCode(Facility facility); List<Facility> getAllForDeliveryZoneAndProgram(Long deliveryZoneId, Long programId); List<Facility> getAllByProgramSupportedModifiedDate(Date dateModified); Facility getFacilityWithReferenceDataForCode(String facilityCode); List<Facility> searchBy(String searchParam, String columnName, Pagination pagination); List<Facility> getEnabledWarehouses(); Facility getFacilityByCode(String facilityCode); List<Facility> getChildFacilities(Facility facility); List<Facility> getAllByRequisitionGroupMemberModifiedDate(Date modifiedDate); List<Facility> getAllParentsByModifiedDate(Date modifiedDate); Facility getOperativeFacilityByCode(String facilityCode); List<Facility> getCompleteListInRequisitionGroups(List<RequisitionGroup> requisitionGroups); List<FacilityContact> getContactList(Long facilityId, String notificationMedium); List<FacilitySupervisor> getFacilitySupervisors(Long facilityId); List<Facility> getUserSupervisedFacilities(Long userId); List<Facility> getAllForGeographicZone(Long geographizZoneId); Integer getFacilitiesCountBy(String searchParam, Long facilityTypeId, Long geoZoneId, Boolean virtualFacility, Boolean enabled); List<Facility> searchFacilitiesBy(String searchParam, Long facilityTypeId, Long geoZoneId, Boolean virtualFacility, Boolean enabled); Integer getTotalSearchResultCountByColumnName(String searchParam, String columnName); List<Facility> getFacilityByTypeAndRequisitionGroupId(Long facilityTypeId, Long rgroupId); List<FacilityGeoTreeDto> getGeoRegionFacilityTree(Long userId); List<FacilityGeoTreeDto> getGeoDistrictFacility(Long userId); List<FacilityGeoTreeDto> getGeoFlatFacilityTree(Long userId); Facility getFacilityById(Long id); }
FacilityService { public List<Facility> getForUserAndRights(Long userId, String... rightNames) { List<SupervisoryNode> supervisoryNodesInHierarchy = supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, rightNames); List<RequisitionGroup> requisitionGroups = requisitionGroupService.getRequisitionGroupsBy(supervisoryNodesInHierarchy); final Set<Facility> userFacilities = new HashSet<>(facilityRepository.getAllInRequisitionGroups(requisitionGroups)); final Facility homeFacility = facilityRepository.getHomeFacilityForRights(userId, rightNames); if (homeFacility != null) userFacilities.add(homeFacility); return new ArrayList<>(userFacilities); }  @Transactional void update(Facility facility); List<FacilityType> getAllTypes(); List<GeographicZone> getAllZones(); Facility getHomeFacility(Long userId); Facility getById(Long id); @Transactional void updateEnabledAndActiveFor(Facility facility); List<Facility> getUserSupervisedFacilities(Long userId, Long programId, String... rightNames); void save(Facility newFacility); void updateAndNotifyForVirtualFacilities(Facility parentFacility); List<Facility> getForUserAndRights(Long userId, String... rightNames); FacilityType getFacilityTypeByCode(FacilityType facilityType); Facility getByCode(Facility facility); List<Facility> getAllForDeliveryZoneAndProgram(Long deliveryZoneId, Long programId); List<Facility> getAllByProgramSupportedModifiedDate(Date dateModified); Facility getFacilityWithReferenceDataForCode(String facilityCode); List<Facility> searchBy(String searchParam, String columnName, Pagination pagination); List<Facility> getEnabledWarehouses(); Facility getFacilityByCode(String facilityCode); List<Facility> getChildFacilities(Facility facility); List<Facility> getAllByRequisitionGroupMemberModifiedDate(Date modifiedDate); List<Facility> getAllParentsByModifiedDate(Date modifiedDate); Facility getOperativeFacilityByCode(String facilityCode); List<Facility> getCompleteListInRequisitionGroups(List<RequisitionGroup> requisitionGroups); List<FacilityContact> getContactList(Long facilityId, String notificationMedium); List<FacilitySupervisor> getFacilitySupervisors(Long facilityId); List<Facility> getUserSupervisedFacilities(Long userId); List<Facility> getAllForGeographicZone(Long geographizZoneId); Integer getFacilitiesCountBy(String searchParam, Long facilityTypeId, Long geoZoneId, Boolean virtualFacility, Boolean enabled); List<Facility> searchFacilitiesBy(String searchParam, Long facilityTypeId, Long geoZoneId, Boolean virtualFacility, Boolean enabled); Integer getTotalSearchResultCountByColumnName(String searchParam, String columnName); List<Facility> getFacilityByTypeAndRequisitionGroupId(Long facilityTypeId, Long rgroupId); List<FacilityGeoTreeDto> getGeoRegionFacilityTree(Long userId); List<FacilityGeoTreeDto> getGeoDistrictFacility(Long userId); List<FacilityGeoTreeDto> getGeoFlatFacilityTree(Long userId); Facility getFacilityById(Long id); static final String FACILITY_CATEGORY; static final String FACILITY_TITLE; static final String ERROR_FACILITY_CODE_INVALID; static final String SMS; static final String EMAIL; }