@Test public void shouldSaveRoleAssignment() throws Exception { final List<Long> roles = new ArrayList<Long>() {{ add(1l); add(2l); add(3l); }}; final List<Long> roles2 = new ArrayList<Long>() {{ add(5l); add(6l); add(7l); }}; SupervisoryNode node = make(a(defaultSupervisoryNode, with(id, 1l))); RoleAssignment roleAssignment = make(a(defaultRoleAssignment, with(RoleAssignmentBuilder.roleIds, roles), with(supervisoryNode, node))); RoleAssignment roleAssignment2 = make(a(defaultRoleAssignment, with(RoleAssignmentBuilder.roleIds, roles2), with(supervisoryNode, node))); List<RoleAssignment> roleAssignments = new ArrayList<>(); roleAssignments.add(roleAssignment); roleAssignments.add(roleAssignment2); repository.insert(roleAssignments, 1L); verify(mapper).insert(1L, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), 1l); verify(mapper).insert(1L, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), 2l); verify(mapper).insert(1L, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), 3l); verify(mapper).insert(1L, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), 5l); verify(mapper).insert(1L, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), 6l); verify(mapper).insert(1L, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), 7l); }
public void insert(List<RoleAssignment> roleAssignments, final Long userId) { if (roleAssignments == null) return; for (final RoleAssignment roleAssignment : roleAssignments) { if (roleAssignment == null) continue; forAllDo(roleAssignment.getRoleIds(), new Closure() { @Override public void execute(Object o) { final Long roleId = (Long) o; mapper.insert(userId, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), roleId); } }); } }
RoleAssignmentRepository { public void insert(List<RoleAssignment> roleAssignments, final Long userId) { if (roleAssignments == null) return; for (final RoleAssignment roleAssignment : roleAssignments) { if (roleAssignment == null) continue; forAllDo(roleAssignment.getRoleIds(), new Closure() { @Override public void execute(Object o) { final Long roleId = (Long) o; mapper.insert(userId, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), roleId); } }); } } }
RoleAssignmentRepository { public void insert(List<RoleAssignment> roleAssignments, final Long userId) { if (roleAssignments == null) return; for (final RoleAssignment roleAssignment : roleAssignments) { if (roleAssignment == null) continue; forAllDo(roleAssignment.getRoleIds(), new Closure() { @Override public void execute(Object o) { final Long roleId = (Long) o; mapper.insert(userId, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), roleId); } }); } } @Autowired  RoleAssignmentRepository(RoleAssignmentMapper roleAssignmentMapper); }
RoleAssignmentRepository { public void insert(List<RoleAssignment> roleAssignments, final Long userId) { if (roleAssignments == null) return; for (final RoleAssignment roleAssignment : roleAssignments) { if (roleAssignment == null) continue; forAllDo(roleAssignment.getRoleIds(), new Closure() { @Override public void execute(Object o) { final Long roleId = (Long) o; mapper.insert(userId, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), roleId); } }); } } @Autowired  RoleAssignmentRepository(RoleAssignmentMapper roleAssignmentMapper); List<RoleAssignment> getRoleAssignmentsForUserWithRight(String rightName, Long userId); void deleteAllRoleAssignmentsForUser(Long id); List<RoleAssignment> getSupervisorRoles(Long userId); List<RoleAssignment> getHomeFacilityRoles(Long userId); List<RoleAssignment> getHomeFacilityRolesForUserOnGivenProgramWithRights(Long userId, Long programId, String... rightNames); RoleAssignment getAdminRole(Long userId); RoleAssignment getReportRole(Long userId); void insert(List<RoleAssignment> roleAssignments, final Long userId); List<RoleAssignment> getAllocationRoles(Long userId); RoleAssignment getReportingRole(Long userId); }
RoleAssignmentRepository { public void insert(List<RoleAssignment> roleAssignments, final Long userId) { if (roleAssignments == null) return; for (final RoleAssignment roleAssignment : roleAssignments) { if (roleAssignment == null) continue; forAllDo(roleAssignment.getRoleIds(), new Closure() { @Override public void execute(Object o) { final Long roleId = (Long) o; mapper.insert(userId, roleAssignment.getProgramId(), roleAssignment.getSupervisoryNode(), roleAssignment.getDeliveryZone(), roleId); } }); } } @Autowired  RoleAssignmentRepository(RoleAssignmentMapper roleAssignmentMapper); List<RoleAssignment> getRoleAssignmentsForUserWithRight(String rightName, Long userId); void deleteAllRoleAssignmentsForUser(Long id); List<RoleAssignment> getSupervisorRoles(Long userId); List<RoleAssignment> getHomeFacilityRoles(Long userId); List<RoleAssignment> getHomeFacilityRolesForUserOnGivenProgramWithRights(Long userId, Long programId, String... rightNames); RoleAssignment getAdminRole(Long userId); RoleAssignment getReportRole(Long userId); void insert(List<RoleAssignment> roleAssignments, final Long userId); List<RoleAssignment> getAllocationRoles(Long userId); RoleAssignment getReportingRole(Long userId);  }