Skip to content

Commit

Permalink
p2-inc#287 Add attributes to an OrganizationMembers
Browse files Browse the repository at this point in the history
  • Loading branch information
rtufisi committed Jan 3, 2025
1 parent 05c159e commit 58c35cf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -196,7 +195,7 @@ public Stream<OrganizationMembershipModel> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,14 +15,14 @@
import java.util.List;
import java.util.Map;

public class OrganizationMembershipAdapter implements OrganizationMembershipModel, JpaModel<OrganizationMemberEntity> {
public class OrganizationMemberAdapter implements OrganizationMembershipModel, JpaModel<OrganizationMemberEntity> {

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;
Expand Down Expand Up @@ -55,7 +55,7 @@ public OrganizationModel getOrganization() {
@Override
public Map<String, List<String>> getAttributes() {
MultivaluedHashMap<String, String> result = new MultivaluedHashMap<>();
for (OrganizationMembershipAttributeEntity attr : organizationMemberEntity.getAttributes()) {
for (OrganizationMemberAttributeEntity attr : organizationMemberEntity.getAttributes()) {
result.add(attr.getName(), attr.getValue());
}
return result;
Expand All @@ -75,7 +75,7 @@ public void removeAttributes() {
public void setAttribute(String name, List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class OrganizationMemberEntity {
protected Date createdAt;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "organizationMember")
protected Collection<OrganizationMembershipAttributeEntity> attributes = new ArrayList<>();
protected Collection<OrganizationMemberAttributeEntity> attributes = new ArrayList<>();

@PrePersist
protected void onCreate() {
Expand Down Expand Up @@ -105,11 +105,11 @@ public void setCreatedAt(Date at) {
createdAt = at;
}

public Collection<OrganizationMembershipAttributeEntity> getAttributes() {
public Collection<OrganizationMemberAttributeEntity> getAttributes() {
return attributes;
}

public void setAttributes(Collection<OrganizationMembershipAttributeEntity> attributes) {
public void setAttributes(Collection<OrganizationMemberAttributeEntity> attributes) {
this.attributes = attributes;
}

Expand Down

0 comments on commit 58c35cf

Please sign in to comment.