@Test public void shouldGetRightsForAUserOnSupervisedFacilityAndProgram() { Long userId = 1L; Facility facility = new Facility(2L); Program program = new Program(3L); List<Right> expected = asList(new Right(CREATE_REQUISITION, ADMIN)); 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); List<Right> result = roleRightsService.getRightsForUserAndFacilityProgram(userId, facility, program); verify(roleRightsRepository).getRightsForUserOnSupervisoryNodeAndProgram(userId, supervisoryNodes, program); assertThat(result.containsAll(expected), is(true)); }
public List<Right> getRightsForUserAndFacilityProgram(Long userId, Facility facility, Program program) { List<Right> result = new ArrayList<>(); result.addAll(getHomeFacilityRights(userId, facility, program)); result.addAll(getSupervisoryRights(userId, facility, program)); return result; }
RoleRightsService { public List<Right> getRightsForUserAndFacilityProgram(Long userId, Facility facility, Program program) { List<Right> result = new ArrayList<>(); result.addAll(getHomeFacilityRights(userId, facility, program)); result.addAll(getSupervisoryRights(userId, facility, program)); return result; } }
RoleRightsService { public List<Right> getRightsForUserAndFacilityProgram(Long userId, Facility facility, Program program) { List<Right> result = new ArrayList<>(); result.addAll(getHomeFacilityRights(userId, facility, program)); result.addAll(getSupervisoryRights(userId, facility, program)); return result; } @Autowired  RoleRightsService(RoleRightsRepository roleRightsRepository,
                           SupervisoryNodeService supervisoryNodeService,
                           FacilityService facilityService,
                           ProgramService programService,
                           ProgramProductService programProductService); }
RoleRightsService { public List<Right> getRightsForUserAndFacilityProgram(Long userId, Facility facility, Program program) { List<Right> result = new ArrayList<>(); result.addAll(getHomeFacilityRights(userId, facility, program)); result.addAll(getSupervisoryRights(userId, facility, program)); return result; } @Autowired  RoleRightsService(RoleRightsRepository roleRightsRepository,
                           SupervisoryNodeService supervisoryNodeService,
                           FacilityService facilityService,
                           ProgramService programService,
                           ProgramProductService programProductService); @Transactional void saveRole(Role role); Map<String, List<Role>> getAllRolesMap(); Role getRole(Long id); List<Role> getAllRoles(); void updateRole(Role role); List<Right> getRights(Long userId); List<Right> getRightsForUserAndFacilityProgram(Long userId, Facility facility, Program program); List<Right> getRightsForUserAndWarehouse(Long userId, Long warehouseId); List<Right> getRightsForUserFacilityAndProductCode(Long userId, Long facilityId, String productCode); RightType getRightTypeForRoleId(Long roleId); }
RoleRightsService { public List<Right> getRightsForUserAndFacilityProgram(Long userId, Facility facility, Program program) { List<Right> result = new ArrayList<>(); result.addAll(getHomeFacilityRights(userId, facility, program)); result.addAll(getSupervisoryRights(userId, facility, program)); return result; } @Autowired  RoleRightsService(RoleRightsRepository roleRightsRepository,
                           SupervisoryNodeService supervisoryNodeService,
                           FacilityService facilityService,
                           ProgramService programService,
                           ProgramProductService programProductService); @Transactional void saveRole(Role role); Map<String, List<Role>> getAllRolesMap(); Role getRole(Long id); List<Role> getAllRoles(); void updateRole(Role role); List<Right> getRights(Long userId); List<Right> getRightsForUserAndFacilityProgram(Long userId, Facility facility, Program program); List<Right> getRightsForUserAndWarehouse(Long userId, Long warehouseId); List<Right> getRightsForUserFacilityAndProductCode(Long userId, Long facilityId, String productCode); RightType getRightTypeForRoleId(Long roleId);  }