Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sadilchamishka committed Sep 1, 2024
1 parent e66cf2c commit 3e16952
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
18 changes: 8 additions & 10 deletions src/main/java/org/wso2/scim2/client/ProvisioningClient.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
/*
* Copyright (c) 2018-2024, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wso2.scim2.client;
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/org/wso2/scim2/operation/GroupOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ public void updateGroup() throws IdentitySCIMException {
return;
}

// get corresponding userIds
Group updatedGroup = setUserIdForMembers();
String encodedGroup;
if (updatedGroup != null) {
encodedGroup = scimClient.encodeSCIMObject(updatedGroup, SCIMConstants.JSON);
} else {
List<String> users = ((Group) scimObject).getMembersWithDisplayName();
if (CollectionUtils.isEmpty(users)) {
encodedGroup = scimClient.encodeSCIMObject((AbstractSCIMObject) scimObject, SCIMConstants.JSON);
} else {
// Find corresponding userIds of group members and enrich the scimObject.
Group updatedGroup = addUserIDForMembersOfGroup();
encodedGroup = scimClient.encodeSCIMObject(updatedGroup, SCIMConstants.JSON);
}
client.setURL(groupEPURL + "/" + groupId);
Scimv2GroupsApi api = new Scimv2GroupsApi(client);
Expand Down Expand Up @@ -188,12 +189,10 @@ public void updateGroup() throws IdentitySCIMException {
}
}

private Group setUserIdForMembers() throws AbstractCharonException, ScimApiException, IOException {
private Group addUserIDForMembersOfGroup() throws AbstractCharonException, ScimApiException, IOException {

List<String> users = ((Group) scimObject).getMembersWithDisplayName();
if (CollectionUtils.isEmpty(users)) {
return null;
}

//create a deep copy of the group since we are going to update the member ids
Group copiedGroup = (Group) CopyUtil.deepCopy(scimObject);
//delete existing members in the group since we are going to update it with
Expand Down

0 comments on commit 3e16952

Please sign in to comment.