From 10ff5787f0655280ac2471b5f40858eeb4328a53 Mon Sep 17 00:00:00 2001 From: Brendan Le Ny Date: Mon, 17 Jun 2024 10:11:16 +0200 Subject: [PATCH] Check emptyness not size --- src/main/java/sh/libre/scim/core/GroupAdapter.java | 5 +++-- src/main/java/sh/libre/scim/core/ScimClient.java | 2 +- src/main/java/sh/libre/scim/core/UserAdapter.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/sh/libre/scim/core/GroupAdapter.java b/src/main/java/sh/libre/scim/core/GroupAdapter.java index ef6609e663..375b6434ef 100644 --- a/src/main/java/sh/libre/scim/core/GroupAdapter.java +++ b/src/main/java/sh/libre/scim/core/GroupAdapter.java @@ -4,6 +4,7 @@ import de.captaingoldfish.scim.sdk.common.resources.Group; import de.captaingoldfish.scim.sdk.common.resources.complex.Meta; import de.captaingoldfish.scim.sdk.common.resources.multicomplex.Member; import jakarta.persistence.NoResultException; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.jboss.logging.Logger; import org.keycloak.models.GroupModel; @@ -60,7 +61,7 @@ public class GroupAdapter extends Adapter { setExternalId(group.getId().get()); setDisplayName(group.getDisplayName().get()); List groupMembers = group.getMembers(); - if (groupMembers != null && groupMembers.size() > 0) { + if (CollectionUtils.isNotEmpty(groupMembers)) { this.members = new HashSet<>(); for (Member groupMember : groupMembers) { try { @@ -80,7 +81,7 @@ public class GroupAdapter extends Adapter { group.setId(externalId); group.setExternalId(id); group.setDisplayName(displayName); - if (members.size() > 0) { + if (!members.isEmpty()) { for (String member : members) { Member groupMember = new Member(); try { diff --git a/src/main/java/sh/libre/scim/core/ScimClient.java b/src/main/java/sh/libre/scim/core/ScimClient.java index 84afe5de73..4782b1e079 100644 --- a/src/main/java/sh/libre/scim/core/ScimClient.java +++ b/src/main/java/sh/libre/scim/core/ScimClient.java @@ -116,7 +116,7 @@ public class ScimClient { if (adapter.skip) return; // If mapping exist then it was created by import so skip. - if (adapter.query("findById", adapter.getId()).getResultList().size() != 0) { + if (!adapter.query("findById", adapter.getId()).getResultList().isEmpty()) { return; } Retry retry = registry.retry("create-" + adapter.getId()); diff --git a/src/main/java/sh/libre/scim/core/UserAdapter.java b/src/main/java/sh/libre/scim/core/UserAdapter.java index d4bd9ac6c9..1de86b3b72 100644 --- a/src/main/java/sh/libre/scim/core/UserAdapter.java +++ b/src/main/java/sh/libre/scim/core/UserAdapter.java @@ -139,7 +139,7 @@ public class UserAdapter extends Adapter { setUsername(user.getUserName().get()); setDisplayName(user.getDisplayName().get()); setActive(user.isActive().get()); - if (user.getEmails().size() > 0) { + if (!user.getEmails().isEmpty()) { setEmail(user.getEmails().get(0).getValue().get()); } }