@Test public void shouldSaveUserRoleAssignments() throws Exception { User user = new User(); final RoleAssignment homeRoleAssignment = new RoleAssignment(); homeRoleAssignment.setProgramId(1L); final RoleAssignment supervisorRoleAssignment = new RoleAssignment(); supervisorRoleAssignment.setProgramId(2L); final RoleAssignment allocationRoleAssignment = new RoleAssignment(); allocationRoleAssignment.setProgramId(3L); List<RoleAssignment> homeFacilityRoles = asList(homeRoleAssignment); List<RoleAssignment> supervisorRoles = asList(supervisorRoleAssignment); List<RoleAssignment> allocationRoles = asList(allocationRoleAssignment); user.setHomeFacilityRoles(homeFacilityRoles); user.setSupervisorRoles(supervisorRoles); user.setAllocationRoles(allocationRoles); final RoleAssignment adminRole = new RoleAssignment(user.getId(), 1L, null, null); final RoleAssignment reportingRole = new RoleAssignment(user.getId(), 2L, null, null); user.setAdminRole(adminRole); user.setReportingRole(reportingRole); service.saveRolesForUser(user); verify(roleAssignmentRepository).insert(homeFacilityRoles, user.getId()); verify(roleAssignmentRepository).insert(allocationRoles, user.getId()); verify(roleAssignmentRepository).insert(supervisorRoles, user.getId()); verify(roleAssignmentRepository).insert(asList(adminRole), user.getId()); verify(roleAssignmentRepository).insert(asList(reportingRole), user.getId()); }
public void saveRolesForUser(User user) { roleAssignmentRepository.deleteAllRoleAssignmentsForUser(user.getId()); roleAssignmentRepository.insert(user.getHomeFacilityRoles(), user.getId()); roleAssignmentRepository.insert(user.getSupervisorRoles(), user.getId()); roleAssignmentRepository.insert(user.getAllocationRoles(), user.getId()); roleAssignmentRepository.insert(asList(user.getReportRoles()), user.getId()); roleAssignmentRepository.insert(asList(user.getAdminRole()), user.getId()); roleAssignmentRepository.insert(asList(user.getReportingRole()), user.getId()); fulfillmentRoleService.saveFulfillmentRoles(user); }
RoleAssignmentService { public void saveRolesForUser(User user) { roleAssignmentRepository.deleteAllRoleAssignmentsForUser(user.getId()); roleAssignmentRepository.insert(user.getHomeFacilityRoles(), user.getId()); roleAssignmentRepository.insert(user.getSupervisorRoles(), user.getId()); roleAssignmentRepository.insert(user.getAllocationRoles(), user.getId()); roleAssignmentRepository.insert(asList(user.getReportRoles()), user.getId()); roleAssignmentRepository.insert(asList(user.getAdminRole()), user.getId()); roleAssignmentRepository.insert(asList(user.getReportingRole()), user.getId()); fulfillmentRoleService.saveFulfillmentRoles(user); } }
RoleAssignmentService { public void saveRolesForUser(User user) { roleAssignmentRepository.deleteAllRoleAssignmentsForUser(user.getId()); roleAssignmentRepository.insert(user.getHomeFacilityRoles(), user.getId()); roleAssignmentRepository.insert(user.getSupervisorRoles(), user.getId()); roleAssignmentRepository.insert(user.getAllocationRoles(), user.getId()); roleAssignmentRepository.insert(asList(user.getReportRoles()), user.getId()); roleAssignmentRepository.insert(asList(user.getAdminRole()), user.getId()); roleAssignmentRepository.insert(asList(user.getReportingRole()), user.getId()); fulfillmentRoleService.saveFulfillmentRoles(user); }  }
RoleAssignmentService { public void saveRolesForUser(User user) { roleAssignmentRepository.deleteAllRoleAssignmentsForUser(user.getId()); roleAssignmentRepository.insert(user.getHomeFacilityRoles(), user.getId()); roleAssignmentRepository.insert(user.getSupervisorRoles(), user.getId()); roleAssignmentRepository.insert(user.getAllocationRoles(), user.getId()); roleAssignmentRepository.insert(asList(user.getReportRoles()), user.getId()); roleAssignmentRepository.insert(asList(user.getAdminRole()), user.getId()); roleAssignmentRepository.insert(asList(user.getReportingRole()), user.getId()); fulfillmentRoleService.saveFulfillmentRoles(user); }  List<RoleAssignment> getHomeFacilityRoles(Long userId); RoleAssignment getAdminRole(Long userId); RoleAssignment getReportRole(Long userId); List<RoleAssignment> getSupervisorRoles(Long userId); List<RoleAssignment> getAllocationRoles(Long userId); List<RoleAssignment> getHomeFacilityRolesForUserOnGivenProgramWithRights(Long userId, Long programId, String... rightNames); List<RoleAssignment> getRoleAssignments(String rightName, Long userId); void saveRolesForUser(User user); List<FulfillmentRoleAssignment> getFulfilmentRoles(Long userId); List<FulfillmentRoleAssignment> getFulfilmentRolesWithRight(Long userId, String rightName); RoleAssignment getReportingRole(Long userId); }
RoleAssignmentService { public void saveRolesForUser(User user) { roleAssignmentRepository.deleteAllRoleAssignmentsForUser(user.getId()); roleAssignmentRepository.insert(user.getHomeFacilityRoles(), user.getId()); roleAssignmentRepository.insert(user.getSupervisorRoles(), user.getId()); roleAssignmentRepository.insert(user.getAllocationRoles(), user.getId()); roleAssignmentRepository.insert(asList(user.getReportRoles()), user.getId()); roleAssignmentRepository.insert(asList(user.getAdminRole()), user.getId()); roleAssignmentRepository.insert(asList(user.getReportingRole()), user.getId()); fulfillmentRoleService.saveFulfillmentRoles(user); }  List<RoleAssignment> getHomeFacilityRoles(Long userId); RoleAssignment getAdminRole(Long userId); RoleAssignment getReportRole(Long userId); List<RoleAssignment> getSupervisorRoles(Long userId); List<RoleAssignment> getAllocationRoles(Long userId); List<RoleAssignment> getHomeFacilityRolesForUserOnGivenProgramWithRights(Long userId, Long programId, String... rightNames); List<RoleAssignment> getRoleAssignments(String rightName, Long userId); void saveRolesForUser(User user); List<FulfillmentRoleAssignment> getFulfilmentRoles(Long userId); List<FulfillmentRoleAssignment> getFulfilmentRolesWithRight(Long userId, String rightName); RoleAssignment getReportingRole(Long userId);  }