diff --git a/src/main/java/io/phasetwo/service/model/OrganizationMemberModel.java b/src/main/java/io/phasetwo/service/model/OrganizationMemberModel.java new file mode 100644 index 0000000..3906d1b --- /dev/null +++ b/src/main/java/io/phasetwo/service/model/OrganizationMemberModel.java @@ -0,0 +1,15 @@ +package io.phasetwo.service.model; + +import java.util.List; +import java.util.Map; + +public interface OrganizationMemberModel extends WithAttributes { + + String getId(); + + String getUserId(); + + OrganizationModel getOrganization(); + + List getRoles(); +} diff --git a/src/main/java/io/phasetwo/service/model/OrganizationMembershipModel.java b/src/main/java/io/phasetwo/service/model/OrganizationMembershipModel.java deleted file mode 100644 index d3fc393..0000000 --- a/src/main/java/io/phasetwo/service/model/OrganizationMembershipModel.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.phasetwo.service.model; - -public interface OrganizationMembershipModel extends WithAttributes { - - String getId(); - - String getUserId(); - - OrganizationModel getOrganization(); -} diff --git a/src/main/java/io/phasetwo/service/model/OrganizationModel.java b/src/main/java/io/phasetwo/service/model/OrganizationModel.java index 511cacc..3d67b70 100644 --- a/src/main/java/io/phasetwo/service/model/OrganizationModel.java +++ b/src/main/java/io/phasetwo/service/model/OrganizationModel.java @@ -41,9 +41,9 @@ public interface OrganizationModel extends WithAttributes { Stream searchForMembersStream(String search, Integer firstResult, Integer maxResults); - Stream getOrganizationMembersStream(); + Stream getOrganizationMembersStream(); - Stream searchForOrganizationMembersStream(String search, Integer firstResult, Integer maxResults); + Stream searchForOrganizationMembersStream(String search, Integer firstResult, Integer maxResults); boolean hasMembership(UserModel user); @@ -78,7 +78,7 @@ default OrganizationRoleModel getRoleByName(String name) { .orElse(null); } - OrganizationMembershipModel getMembershipDetails(UserModel user); + OrganizationMemberModel getMembershipDetails(UserModel user); void removeRole(String name); 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..1ca69b2 100644 --- a/src/main/java/io/phasetwo/service/model/jpa/OrganizationAdapter.java +++ b/src/main/java/io/phasetwo/service/model/jpa/OrganizationAdapter.java @@ -5,7 +5,7 @@ import com.google.common.base.Strings; import io.phasetwo.service.model.DomainModel; import io.phasetwo.service.model.InvitationModel; -import io.phasetwo.service.model.OrganizationMembershipModel; +import io.phasetwo.service.model.OrganizationMemberModel; import io.phasetwo.service.model.OrganizationModel; import io.phasetwo.service.model.OrganizationRoleModel; import io.phasetwo.service.model.jpa.entity.DomainEntity; @@ -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; @@ -191,16 +190,16 @@ public Stream searchForMembersStream( } @Override - public Stream getOrganizationMembersStream() { + public Stream getOrganizationMembersStream() { TypedQuery query = em.createNamedQuery("getOrganizationMembers", OrganizationMemberEntity.class); query.setParameter("organization", org); return query.getResultStream() - .map(organizationMemberEntity -> new OrganizationMembershipAdapter(session, realm, em, organizationMemberEntity)); + .map(organizationMemberEntity -> new OrganizationMemberAdapter(session, realm, em, organizationMemberEntity)); } @Override - public Stream searchForOrganizationMembersStream(String search, Integer firstResult, Integer maxResults) { + public Stream searchForOrganizationMembersStream(String search, Integer firstResult, Integer maxResults) { return Stream.empty(); } @@ -318,8 +317,8 @@ public Stream getRolesByUserStream(UserModel user) { } @Override - public OrganizationMembershipModel getMembershipDetails(UserModel user) { - TypedQuery query = em.createNamedQuery("getOrganizationMemberByUserId", OrganizationMembershipModel.class); + public OrganizationMemberModel getMembershipDetails(UserModel user) { + TypedQuery query = em.createNamedQuery("getOrganizationMemberByUserId", OrganizationMemberModel.class); query.setParameter("organization", org); query.setParameter("id", user.getId()); return query.getSingleResult(); 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 81% 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..6d4dc85 100644 --- a/src/main/java/io/phasetwo/service/model/jpa/OrganizationMembershipAdapter.java +++ b/src/main/java/io/phasetwo/service/model/jpa/OrganizationMemberAdapter.java @@ -1,10 +1,10 @@ package io.phasetwo.service.model.jpa; -import io.phasetwo.service.model.OrganizationMembershipModel; +import io.phasetwo.service.model.OrganizationMemberModel; 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 OrganizationMemberModel, 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; @@ -52,10 +52,15 @@ public OrganizationModel getOrganization() { .getOrganizationById(realm, organizationMemberEntity.getOrganization().getId()); } + @Override + public List getRoles() { + return List.of(); + } + @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 +80,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; }