-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86f5ae9
commit 529c463
Showing
4 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/EmailDomainEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.orcid.persistence.jpa.entities; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.SequenceGenerator; | ||
import javax.persistence.Table; | ||
|
||
/** | ||
* | ||
* @author Will Simpson | ||
* | ||
*/ | ||
@Table(name = "email_domain") | ||
@Entity | ||
public class EmailDomainEntity extends BaseEntity<Long> { | ||
|
||
private static final long serialVersionUID = 7138838021634315502L; | ||
|
||
public enum DomainCategory {PERSONAL, PROFESSIONAL, UNDEFINED} | ||
|
||
private Long id; | ||
private String emailDomain; | ||
private DomainCategory category; | ||
|
||
|
||
@Override | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "email_domain_seq") | ||
@SequenceGenerator(name = "email_domain_seq", sequenceName = "email_domain_seq", allocationSize = 1) | ||
@Column(name = "id") | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
@Column(name = "email_domain") | ||
public String getEmailDomain() { | ||
return emailDomain; | ||
} | ||
|
||
public void setCategory(DomainCategory category) { | ||
this.category = category; | ||
} | ||
|
||
@Column(name = "category") | ||
public DomainCategory getCategory() { | ||
return category; | ||
} | ||
|
||
public void setEmailDomain(String emailDomain) { | ||
this.emailDomain = emailDomain; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(category, emailDomain, id); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
EmailDomainEntity other = (EmailDomainEntity) obj; | ||
return category == other.category && Objects.equals(emailDomain, other.emailDomain) && Objects.equals(id, other.id); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...ersistence/src/main/java/org/orcid/persistence/jpa/entities/EmailDomainToOrgIdEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.orcid.persistence.jpa.entities; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.SequenceGenerator; | ||
import javax.persistence.Table; | ||
|
||
/** | ||
* | ||
* @author Will Simpson | ||
* | ||
*/ | ||
@Table(name = "email_domain_to_org_id") | ||
@Entity | ||
public class EmailDomainToOrgIdEntity extends BaseEntity<Long> { | ||
|
||
private static final long serialVersionUID = 7138838021634315502L; | ||
|
||
public enum DomainCategory {PERSONAL, PROFESSIONAL, UNDEFINED} | ||
|
||
private Long id; | ||
private EmailDomainEntity emailDomian; | ||
private OrgDisambiguatedEntity orgDisambiguated; | ||
|
||
|
||
@Override | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "email_domain_to_org_id_seq") | ||
@SequenceGenerator(name = "email_domain_to_org_id_seq", sequenceName = "email_domain_to_org_id_seq", allocationSize = 1) | ||
@Column(name = "id") | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
@ManyToOne(fetch = FetchType.EAGER) | ||
@JoinColumn(name = "email_domian_id") | ||
public EmailDomainEntity getEmailDomian() { | ||
return emailDomian; | ||
} | ||
|
||
public void setEmailDomian(EmailDomainEntity emailDomian) { | ||
this.emailDomian = emailDomian; | ||
} | ||
|
||
@ManyToOne(fetch = FetchType.EAGER) | ||
@JoinColumn(name = "org_disambiguated_id") | ||
public OrgDisambiguatedEntity getOrgDisambiguated() { | ||
return orgDisambiguated; | ||
} | ||
|
||
public void setOrgDisambiguated(OrgDisambiguatedEntity orgDisambiguated) { | ||
this.orgDisambiguated = orgDisambiguated; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
orcid-persistence/src/main/resources/db/updates/create_email_domain_mapping_tables.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd"> | ||
|
||
<changeSet author="Angel Montenegro" id="CREATE-EMAIL-DOMAIN-TABLE"> | ||
<preConditions onFail="MARK_RAN"> | ||
<not> | ||
<tableExists tableName="email_domain" /> | ||
</not> | ||
</preConditions> | ||
|
||
<createTable tableName="email_domain"> | ||
<column name="id" type="bigint"> | ||
<constraints nullable="false" primaryKey="true" | ||
primaryKeyName="email_domain_pkey" /> | ||
</column> | ||
<column name="email_domain" type="VARCHAR(64)"> | ||
<constraints nullable="false" /> | ||
</column> | ||
<column name="category" type="VARCHAR(16)"> | ||
<constraints nullable="false" /> | ||
</column> | ||
<column name="date_created" type="TIMESTAMP WITH TIME ZONE" /> | ||
<column name="last_modified" type="TIMESTAMP WITH TIME ZONE" /> | ||
</createTable> | ||
</changeSet> | ||
|
||
<changeSet author="Angel Montenegro" id="CREATE-EMAIL-DOMAIN-TO-ORG-ID-TABLE"> | ||
<preConditions onFail="MARK_RAN"> | ||
<not> | ||
<tableExists tableName="email_domain_to_org_id" /> | ||
</not> | ||
</preConditions> | ||
|
||
<createTable tableName="email_domain_to_org_id"> | ||
<column name="id" type="bigint"> | ||
<constraints nullable="false" primaryKey="true" | ||
primaryKeyName="email_domain_to_org_id_pkey" /> | ||
</column> | ||
<column name="email_domian_id" type="bigint"> | ||
<constraints nullable="false" /> | ||
</column> | ||
<column name="org_disambiguated_id" type="bigint"> | ||
<constraints nullable="false" /> | ||
</column> | ||
<column name="date_created" type="TIMESTAMP WITH TIME ZONE" /> | ||
<column name="last_modified" type="TIMESTAMP WITH TIME ZONE" /> | ||
</createTable> | ||
|
||
<sql>ALTER TABLE email_domain_to_org_id ADD CONSTRAINT email_domain_fk FOREIGN KEY (email_domian_id) REFERENCES email_domain (id);</sql> | ||
<sql>ALTER TABLE email_domain_to_org_id ADD CONSTRAINT org_disambiguated_id_fk FOREIGN KEY (org_disambiguated_id) REFERENCES org_disambiguated (id);</sql> | ||
<sql>create index email_domain_to_org_id_domain_index on email_domain_to_org_id(email_domian_id);</sql> | ||
<sql>create index email_domain_to_org_id_org_index on email_domain_to_org_id(org_disambiguated_id);</sql> | ||
</changeSet> | ||
|
||
<changeSet id="CREATE-SEQUENCES" author="Angel Montenegro" dbms="postgresql"> | ||
<preConditions onFail="MARK_RAN"> | ||
<not> | ||
<sequenceExists sequenceName="email_domain_seq"/> | ||
<sequenceExists sequenceName="email_domain_to_org_id_seq"/> | ||
</not> | ||
</preConditions> | ||
<createSequence sequenceName="email_domain_seq" startValue="1000" /> | ||
<createSequence sequenceName="email_domain_to_org_id_seq" startValue="1000" /> | ||
</changeSet> | ||
|
||
<changeSet id="CREATE-AUTOCOLS" author="Angel Montenegro" dbms="hsqldb"> | ||
<addAutoIncrement tableName="email_domain" columnName="id" columnDataType="bigint"/> | ||
<addAutoIncrement tableName="email_domain_to_org_id" columnName="id" columnDataType="bigint"/> | ||
</changeSet> | ||
|
||
<changeSet id="EMAIL-DOMAIN-INDEX" author="Angel Montenegro" dbms="postgresql"> | ||
<preConditions onFail="MARK_RAN"> | ||
<not> | ||
<indexExists indexName="email_domain_domain_index" tableName="email_domain" /> | ||
</not> | ||
</preConditions> | ||
<sql>create index email_domain_domain_index on email_domain(email_domain);</sql> | ||
</changeSet> | ||
|
||
<changeSet id="GRANT-READ-PERMISSIONS-TO-ORCIDRO" author="Angel Montenegro" dbms="postgresql"> | ||
<sql>GRANT SELECT ON email_domain to orcidro;</sql> | ||
<sql>GRANT SELECT ON email_domain_to_org_id to orcidro;</sql> | ||
</changeSet> | ||
|
||
</databaseChangeLog> |