private GroupRepresentation transformKeycloakGroupToGroup()

in services/src/main/java/org/apache/custos/service/iam/IamAdminService.java [1913:1964]


    private GroupRepresentation transformKeycloakGroupToGroup(String clientId, org.keycloak.representations.idm.GroupRepresentation group,
                                                              GroupRepresentation parent) {
        String name = group.getName();
        String id = group.getId();
        List<String> realmRoles = group.getRealmRoles();
        Map<String, List<String>> clientRoles = group.getClientRoles();
        Map<String, List<String>> atrs = group.getAttributes();

        GroupRepresentation representation = GroupRepresentation.newBuilder()
                .setName(name)
                .setId(id)
                .build();

        if (realmRoles != null && !realmRoles.isEmpty()) {
            representation = representation.toBuilder().addAllRealmRoles(realmRoles).build();
        }

        if (clientRoles != null && !clientRoles.isEmpty() && !clientRoles.get(clientId).isEmpty()) {
            representation = representation.toBuilder().addAllClientRoles(clientRoles.get(clientId)).build();
        }

        if (atrs != null && !atrs.isEmpty()) {
            List<UserAttribute> attributeList = new ArrayList<>();
            for (String key : atrs.keySet()) {
                if (key.equals(Constants.OWNER_ID)) {
                    representation = representation.toBuilder().setOwnerId(atrs.get(key).get(0)).build();
                } else if (key.equals(Constants.DESCRIPTION)) {
                    representation = representation.toBuilder().setDescription(atrs.get(key).get(0)).build();
                } else {
                    UserAttribute attribute = UserAttribute.newBuilder().setKey(key).addAllValues(atrs.get(key)).build();
                    attributeList.add(attribute);
                }
            }
            representation = representation.toBuilder().addAllAttributes(attributeList).build();
        }

        if (group.getSubGroups() != null && !group.getSubGroups().isEmpty()) {
            for (org.keycloak.representations.idm.GroupRepresentation subGroup : group.getSubGroups()) {
                representation = transformKeycloakGroupToGroup(clientId, subGroup, representation);
            }
        }

        if (parent != null) {
            parent = parent.toBuilder().addSubGroups(representation).build();
        }

        if (parent != null) {
            return parent;
        } else {
            return representation;
        }
    }