コード例 #1
0
ファイル: FacilityService.java プロジェクト: rahulj/open-lmis
 public List<Facility> getUserSupervisedFacilities(Long userId, Long programId, Right... rights) {
   List<SupervisoryNode> supervisoryNodes =
       supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, programId, rights);
   List<RequisitionGroup> requisitionGroups =
       requisitionGroupService.getRequisitionGroupsBy(supervisoryNodes);
   return facilityRepository.getFacilitiesBy(programId, requisitionGroups);
 }
コード例 #2
0
ファイル: FacilityService.java プロジェクト: rahulj/open-lmis
  public List<Facility> getForUserAndRights(Long userId, Right... rights) {
    List<SupervisoryNode> supervisoryNodesInHierarchy =
        supervisoryNodeService.getAllSupervisoryNodesInHierarchyBy(userId, rights);
    List<RequisitionGroup> requisitionGroups =
        requisitionGroupService.getRequisitionGroupsBy(supervisoryNodesInHierarchy);
    final Set<Facility> userFacilities =
        new HashSet<>(facilityRepository.getAllInRequisitionGroups(requisitionGroups));
    final Facility homeFacility = facilityRepository.getHomeFacilityForRights(userId, rights);

    if (homeFacility != null) userFacilities.add(homeFacility);

    return new ArrayList<>(userFacilities);
  }
コード例 #3
0
  @Test
  public void shouldGetRightsForAUserOnSupervisedFacilityAndProgram() throws Exception {
    Long userId = 1L;
    Facility facility = new Facility(2L);
    Program program = new Program(3L);
    List<Right> expected = asList(CREATE_REQUISITION);
    SupervisoryNode supervisoryNode = new SupervisoryNode(4L);
    List<SupervisoryNode> supervisoryNodes = asList(supervisoryNode);

    when(supervisoryNodeService.getFor(facility, program)).thenReturn(supervisoryNode);
    when(supervisoryNodeService.getAllParentSupervisoryNodesInHierarchy(supervisoryNode))
        .thenReturn(supervisoryNodes);
    when(roleRightsRepository.getRightsForUserOnSupervisoryNodeAndProgram(
            userId, supervisoryNodes, program))
        .thenReturn(expected);

    Set<Right> result =
        roleRightsService.getRightsForUserAndFacilityProgram(userId, facility, program);

    verify(roleRightsRepository)
        .getRightsForUserOnSupervisoryNodeAndProgram(userId, supervisoryNodes, program);
    assertThat(result.containsAll(expected), is(true));
  }