in services/src/main/java/org/apache/custos/service/management/GroupManagementService.java [125:177]
public Group patchGroup(AuthClaim authClaim, String groupId, org.apache.custos.core.user.profile.api.Group groupChangeProperties) {
String REMOVE_ALL_TAG = "custos-remove-all"; // TODO: update ProtobufPropertiesModule.java for a cleaner solution
GroupRequest exGroupReq = GroupRequest.newBuilder()
.setTenantId(authClaim.getTenantId())
.setClientId(authClaim.getIamAuthId())
.setClientSec(authClaim.getIamAuthSecret())
.setPerformedBy(authClaim.getPerformedBy() != null ? authClaim.getPerformedBy() : Constants.SYSTEM)
.setGroup(groupChangeProperties.toBuilder().setId(groupId).build())
.build();
Group exGroup = findGroup(exGroupReq);
Group.Builder mergedGroupBuilder = exGroup.toBuilder()
.setName(!groupChangeProperties.getName().isEmpty() ? groupChangeProperties.getName() : exGroup.getName())
.setDescription(!groupChangeProperties.getDescription().isEmpty() ? groupChangeProperties.getDescription() : exGroup.getDescription());
List<String> clientRolesLst = groupChangeProperties.getClientRolesList();
if (!clientRolesLst.isEmpty()) {
mergedGroupBuilder.clearClientRoles();
if (!clientRolesLst.get(0).equals(REMOVE_ALL_TAG)) {
mergedGroupBuilder.addAllClientRoles(groupChangeProperties.getClientRolesList());
}
}
List<String> realmRolesLst = groupChangeProperties.getRealmRolesList();
if (!realmRolesLst.isEmpty()) {
mergedGroupBuilder.clearRealmRoles();
if (!realmRolesLst.get(0).equals(REMOVE_ALL_TAG)) {
mergedGroupBuilder.addAllRealmRoles(groupChangeProperties.getRealmRolesList());
}
}
List<GroupAttribute> groupAttributeList = groupChangeProperties.getAttributesList();
if (!groupAttributeList.isEmpty()) {
mergedGroupBuilder.clearAttributes();
if (!groupAttributeList.get(0).getKey().equals(REMOVE_ALL_TAG)) {
mergedGroupBuilder.addAllAttributes(groupChangeProperties.getAttributesList());
}
}
Group mergedGroup = mergedGroupBuilder.build();
GroupRequest updateGroupRequest = GroupRequest.newBuilder()
.setTenantId(authClaim.getTenantId())
.setClientId(authClaim.getIamAuthId())
.setClientSec(authClaim.getIamAuthSecret())
.setPerformedBy(authClaim.getPerformedBy() != null ? authClaim.getPerformedBy() : Constants.SYSTEM)
.setGroup(mergedGroup.toBuilder().setId(groupId).build())
.build();
return updateGroup(updateGroupRequest);
}