From 58c35cfd8a109fa584eea4588d09cba69b04e32a Mon Sep 17 00:00:00 2001 From: razvantufisi Date: Fri, 3 Jan 2025 17:32:35 +0200 Subject: [PATCH] #287 Add attributes to an OrganizationMembers --- .../service/model/jpa/OrganizationAdapter.java | 3 +-- ...shipAdapter.java => OrganizationMemberAdapter.java} | 10 +++++----- .../model/jpa/entity/OrganizationEntityProvider.java | 2 +- ...ity.java => OrganizationMemberAttributeEntity.java} | 4 ++-- .../model/jpa/entity/OrganizationMemberEntity.java | 6 +++--- 5 files changed, 12 insertions(+), 13 deletions(-) rename src/main/java/io/phasetwo/service/model/jpa/{OrganizationMembershipAdapter.java => OrganizationMemberAdapter.java} (84%) rename src/main/java/io/phasetwo/service/model/jpa/entity/{OrganizationMembershipAttributeEntity.java => OrganizationMemberAttributeEntity.java} (93%) diff --git a/src/main/java/io/phasetwo/service/model/jpa/OrganizationAdapter.java b/src/main/java/io/phasetwo/service/model/jpa/OrganizationAdapter.java index d2c93ee..d84bcf2 100644 --- a/src/main/java/io/phasetwo/service/model/jpa/OrganizationAdapter.java +++ b/src/main/java/io/phasetwo/service/model/jpa/OrganizationAdapter.java @@ -13,7 +13,6 @@ import io.phasetwo.service.model.jpa.entity.InvitationEntity; import io.phasetwo.service.model.jpa.entity.OrganizationAttributeEntity; import io.phasetwo.service.model.jpa.entity.OrganizationMemberEntity; -import io.phasetwo.service.model.jpa.entity.OrganizationMembershipAttributeEntity; import io.phasetwo.service.model.jpa.entity.OrganizationRoleEntity; import io.phasetwo.service.model.jpa.entity.UserOrganizationRoleMappingEntity; import io.phasetwo.service.util.IdentityProviders; @@ -196,7 +195,7 @@ public Stream getOrganizationMembersStream() { query.setParameter("organization", org); return query.getResultStream() - .map(organizationMemberEntity -> new OrganizationMembershipAdapter(session, realm, em, organizationMemberEntity)); + .map(organizationMemberEntity -> new OrganizationMemberAdapter(session, realm, em, organizationMemberEntity)); } @Override diff --git a/src/main/java/io/phasetwo/service/model/jpa/OrganizationMembershipAdapter.java b/src/main/java/io/phasetwo/service/model/jpa/OrganizationMemberAdapter.java similarity index 84% rename from src/main/java/io/phasetwo/service/model/jpa/OrganizationMembershipAdapter.java rename to src/main/java/io/phasetwo/service/model/jpa/OrganizationMemberAdapter.java index 29f97e4..5ba2b27 100644 --- a/src/main/java/io/phasetwo/service/model/jpa/OrganizationMembershipAdapter.java +++ b/src/main/java/io/phasetwo/service/model/jpa/OrganizationMemberAdapter.java @@ -4,7 +4,7 @@ import io.phasetwo.service.model.OrganizationModel; import io.phasetwo.service.model.OrganizationProvider; import io.phasetwo.service.model.jpa.entity.OrganizationMemberEntity; -import io.phasetwo.service.model.jpa.entity.OrganizationMembershipAttributeEntity; +import io.phasetwo.service.model.jpa.entity.OrganizationMemberAttributeEntity; import jakarta.persistence.EntityManager; import org.keycloak.common.util.MultivaluedHashMap; import org.keycloak.models.KeycloakSession; @@ -15,14 +15,14 @@ import java.util.List; import java.util.Map; -public class OrganizationMembershipAdapter implements OrganizationMembershipModel, JpaModel { +public class OrganizationMemberAdapter implements OrganizationMembershipModel, JpaModel { protected final KeycloakSession session; protected final OrganizationMemberEntity organizationMemberEntity; protected final EntityManager em; protected final RealmModel realm; - public OrganizationMembershipAdapter( + public OrganizationMemberAdapter( KeycloakSession session, RealmModel realm, EntityManager em, OrganizationMemberEntity organizationMemberEntity) { this.session = session; this.em = em; @@ -55,7 +55,7 @@ public OrganizationModel getOrganization() { @Override public Map> getAttributes() { MultivaluedHashMap result = new MultivaluedHashMap<>(); - for (OrganizationMembershipAttributeEntity attr : organizationMemberEntity.getAttributes()) { + for (OrganizationMemberAttributeEntity attr : organizationMemberEntity.getAttributes()) { result.add(attr.getName(), attr.getValue()); } return result; @@ -75,7 +75,7 @@ public void removeAttributes() { public void setAttribute(String name, List values) { removeAttribute(name); for (String value : values) { - OrganizationMembershipAttributeEntity a = new OrganizationMembershipAttributeEntity(); + OrganizationMemberAttributeEntity a = new OrganizationMemberAttributeEntity(); a.setId(KeycloakModelUtils.generateId()); a.setName(name); a.setValue(value); diff --git a/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationEntityProvider.java b/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationEntityProvider.java index 85e2307..b112eb8 100644 --- a/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationEntityProvider.java +++ b/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationEntityProvider.java @@ -12,7 +12,7 @@ public class OrganizationEntityProvider implements JpaEntityProvider { ExtOrganizationEntity.class, OrganizationAttributeEntity.class, OrganizationMemberEntity.class, - OrganizationMembershipAttributeEntity.class, + OrganizationMemberAttributeEntity.class, OrganizationRoleEntity.class, UserOrganizationRoleMappingEntity.class, InvitationEntity.class, diff --git a/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationMembershipAttributeEntity.java b/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationMemberAttributeEntity.java similarity index 93% rename from src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationMembershipAttributeEntity.java rename to src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationMemberAttributeEntity.java index 401ff26..9f653a1 100644 --- a/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationMembershipAttributeEntity.java +++ b/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationMemberAttributeEntity.java @@ -18,7 +18,7 @@ name = "ORGANIZATION_MEMBER_ATTRIBUTE", uniqueConstraints = {@UniqueConstraint(columnNames = {"ORGANIZATION_MEMBER_ID", "NAME"})}) @Entity -public class OrganizationMembershipAttributeEntity { +public class OrganizationMemberAttributeEntity { @Id @Column(name = "ID", length = 36) @@ -73,7 +73,7 @@ public void setValue(String value) { @Override public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; - OrganizationMembershipAttributeEntity that = (OrganizationMembershipAttributeEntity) o; + OrganizationMemberAttributeEntity that = (OrganizationMemberAttributeEntity) o; return Objects.equals(id, that.id) && Objects.equals(organizationMember, that.organizationMember); } diff --git a/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationMemberEntity.java b/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationMemberEntity.java index 0950ba2..827cdfc 100644 --- a/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationMemberEntity.java +++ b/src/main/java/io/phasetwo/service/model/jpa/entity/OrganizationMemberEntity.java @@ -66,7 +66,7 @@ public class OrganizationMemberEntity { protected Date createdAt; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "organizationMember") - protected Collection attributes = new ArrayList<>(); + protected Collection attributes = new ArrayList<>(); @PrePersist protected void onCreate() { @@ -105,11 +105,11 @@ public void setCreatedAt(Date at) { createdAt = at; } - public Collection getAttributes() { + public Collection getAttributes() { return attributes; } - public void setAttributes(Collection attributes) { + public void setAttributes(Collection attributes) { this.attributes = attributes; }