All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.phasetwo.service.model.jpa.entity.InvitationEntity Maven / Gradle / Ivy

There is a newer version: 0.79
Show newest version
package io.phasetwo.service.model.jpa.entity;

import static io.phasetwo.service.model.jpa.entity.Entities.setCollection;

import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/** */
@NamedQueries({
  @NamedQuery(
      name = "getInvitationByOrganization",
      query =
          "SELECT t FROM InvitationEntity t WHERE t.organization = :organization AND t.id = :id"),
  @NamedQuery(
      name = "getInvitationsByOrganizationAndEmail",
      query =
          "SELECT t FROM InvitationEntity t WHERE t.organization = :organization AND lower(t.email) LIKE lower(:search) ORDER BY t.email"),
  @NamedQuery(
      name = "getInvitationsByRealmAndEmail",
      query =
          "SELECT i FROM InvitationEntity i WHERE i.organization in (SELECT o FROM ExtOrganizationEntity o WHERE o.realmId = :realmId) AND lower(i.email) = lower(:search) ORDER BY i.createdAt"),
  @NamedQuery(
      name = "getInvitationCount",
      query = "SELECT COUNT(t) FROM InvitationEntity t WHERE t.organization = :organization")
})
@Entity
@Table(
    name = "INVITATION",
    uniqueConstraints = {@UniqueConstraint(columnNames = {"ORGANIZATION_ID", "EMAIL"})})
public class InvitationEntity {
  @Id
  @Column(name = "ID", length = 36)
  @Access(
      AccessType.PROPERTY) // we do this because relationships often fetch id, but not entity.  This
  // avoids an extra SQL
  protected String id;

  @Email
  @Column(name = "EMAIL")
  protected String email;

  @Column(name = "URL")
  protected String url;

  @Column(name = "INVITER_ID")
  protected String inviterId;

  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "CREATED_AT")
  protected Date createdAt;

  @OneToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "ORGANIZATION_ID")
  private ExtOrganizationEntity organization;

  @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "invitation")
  protected Collection attributes =
      new ArrayList();

  @ElementCollection
  @Column(name = "ROLE")
  @CollectionTable(
      name = "INVITATION_ROLE",
      joinColumns = {@JoinColumn(name = "INVITATION_ID")})
  protected Set roles = new HashSet();

  @PrePersist
  protected void onCreate() {
    if (createdAt == null) createdAt = new Date();
  }

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public String getUrl() {
    return url;
  }

  public void setUrl(String url) {
    this.url = url;
  }

  public String getInviterId() {
    return inviterId;
  }

  public void setInviterId(String inviterId) {
    this.inviterId = inviterId;
  }

  public Date getCreatedAt() {
    return createdAt;
  }

  public void setCreatedAt(Date at) {
    createdAt = at;
  }

  public ExtOrganizationEntity getOrganization() {
    return organization;
  }

  public void setOrganization(ExtOrganizationEntity organization) {
    this.organization = organization;
  }

  public Set getRoles() {
    return roles;
  }

  public void setRoles(Set roles) {
    this.roles = roles;
  }

  public Collection getAttributes() {
    return attributes;
  }

  public void setAttributes(Collection attributes) {
    setCollection(attributes, this.attributes);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null) return false;
    if (!(o instanceof InvitationEntity)) return false;

    InvitationEntity that = (InvitationEntity) o;

    if (!id.equals(that.id)) return false;

    return true;
  }

  @Override
  public int hashCode() {
    return id.hashCode();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy