private static void ensureGroupPermissionConsistency(DbSession dbSession, GroupPermissionDto dto) { if (dto.getGroupId() == null) { return; } GroupMapper groupMapper = dbSession.getMapper(GroupMapper.class); checkArgument( groupMapper.countGroupByOrganizationAndId(dto.getOrganizationUuid(), dto.getGroupId()) == 1, "Can't insert permission '%s' for group with id '%s' in organization with uuid '%s' because this group does not belong to organization with uuid '%s'", dto.getRole(), dto.getGroupId(), dto.getOrganizationUuid(), dto.getOrganizationUuid()); }
private static WsGroupsResponse buildResponse(List<GroupDto> groups, List<GroupPermissionDto> groupPermissions, Paging paging) { Multimap<Integer, String> permissionsByGroupId = TreeMultimap.create(); groupPermissions.forEach(groupPermission -> permissionsByGroupId.put(groupPermission.getGroupId(), groupPermission.getRole())); WsGroupsResponse.Builder response = WsGroupsResponse.newBuilder(); groups.forEach(group -> { Group.Builder wsGroup = response.addGroupsBuilder() .setName(group.getName()); if (group.getId() != 0) { wsGroup.setId(String.valueOf(group.getId())); } ofNullable(group.getDescription()).ifPresent(wsGroup::setDescription); wsGroup.addAllPermissions(permissionsByGroupId.get(group.getId())); }); response.getPagingBuilder() .setPageIndex(paging.pageIndex()) .setPageSize(paging.pageSize()) .setTotal(paging.total()); return response.build(); }
private static void ensureGroupPermissionConsistency(DbSession dbSession, GroupPermissionDto dto) { if (dto.getGroupId() == null) { return; } GroupMapper groupMapper = dbSession.getMapper(GroupMapper.class); checkArgument( groupMapper.countGroupByOrganizationAndId(dto.getOrganizationUuid(), dto.getGroupId()) == 1, "Can't insert permission '%s' for group with id '%s' in organization with uuid '%s' because this group does not belong to organization with uuid '%s'", dto.getRole(), dto.getGroupId(), dto.getOrganizationUuid(), dto.getOrganizationUuid()); }
private static WsGroupsResponse buildResponse(List<GroupDto> groups, List<GroupPermissionDto> groupPermissions, Paging paging) { Multimap<Integer, String> permissionsByGroupId = TreeMultimap.create(); groupPermissions.forEach(groupPermission -> permissionsByGroupId.put(groupPermission.getGroupId(), groupPermission.getRole())); WsGroupsResponse.Builder response = WsGroupsResponse.newBuilder(); groups.forEach(group -> { Group.Builder wsGroup = response.addGroupsBuilder() .setName(group.getName()); if (group.getId() != 0) { wsGroup.setId(String.valueOf(group.getId())); } setNullable(group.getDescription(), wsGroup::setDescription); wsGroup.addAllPermissions(permissionsByGroupId.get(group.getId())); }); response.getPagingBuilder() .setPageIndex(paging.pageIndex()) .setPageSize(paging.pageSize()) .setTotal(paging.total()); return response.build(); }