-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix typos * add db table * add togglz * add email domain logic * improve new domain logic * add another toggle * improve readability, add transactions, cleanup * remove todo * add indexes to profile email domain table * fix new domain visibility bug
- Loading branch information
Showing
26 changed files
with
925 additions
and
375 deletions.
There are no files selected for viewing
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
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
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
16 changes: 16 additions & 0 deletions
16
orcid-core/src/main/java/org/orcid/core/manager/v3/ProfileEmailDomainManager.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,16 @@ | ||
package org.orcid.core.manager.v3; | ||
|
||
import org.orcid.core.manager.v3.read_only.ProfileEmailDomainManagerReadOnly; | ||
import org.orcid.persistence.jpa.entities.EmailEntity; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author Andrej Romanov | ||
* | ||
*/ | ||
public interface ProfileEmailDomainManager extends ProfileEmailDomainManagerReadOnly { | ||
void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails emails); | ||
void processDomain(String orcid, String email); | ||
} |
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
78 changes: 78 additions & 0 deletions
78
orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileEmailDomainManagerImpl.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.core.manager.v3.impl; | ||
|
||
|
||
import org.orcid.core.manager.v3.ProfileEmailDomainManager; | ||
import org.orcid.core.manager.v3.read_only.impl.ProfileEmailDomainManagerReadOnlyImpl; | ||
import org.orcid.jaxb.model.v3.release.common.Visibility; | ||
import org.orcid.persistence.dao.EmailDao; | ||
import org.orcid.persistence.dao.EmailDomainDao; | ||
import org.orcid.persistence.dao.ProfileEmailDomainDao; | ||
import org.orcid.persistence.jpa.entities.EmailDomainEntity; | ||
import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.*; | ||
|
||
/** | ||
* | ||
* @author Andrej Romanov | ||
* | ||
*/ | ||
public class ProfileEmailDomainManagerImpl extends ProfileEmailDomainManagerReadOnlyImpl implements ProfileEmailDomainManager { | ||
@Resource | ||
protected ProfileEmailDomainDao profileEmailDomainDao; | ||
|
||
@Resource | ||
protected EmailDomainDao emailDomainDao; | ||
|
||
@Resource | ||
protected EmailDao emailDao; | ||
|
||
private static final String DEFAULT_DOMAIN_VISIBILITY = Visibility.PRIVATE.toString().toUpperCase(); | ||
|
||
@Transactional | ||
public void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails newEmails) { | ||
List<ProfileEmailDomainEntity> existingEmailDomains = profileEmailDomainDao.findByOrcid(orcid); | ||
|
||
if (existingEmailDomains != null) { | ||
// VISIBILITY UPDATE FOR EXISTING DOMAINS | ||
for (org.orcid.pojo.ajaxForm.ProfileEmailDomain emailDomain : newEmails.getEmailDomains()) { | ||
for (ProfileEmailDomainEntity existingEmailDomain : existingEmailDomains) { | ||
if (existingEmailDomain.getEmailDomain().equals(emailDomain.getValue())) { | ||
if (!existingEmailDomain.getVisibility().equals(emailDomain.getVisibility())) { | ||
profileEmailDomainDao.updateVisibility(orcid, emailDomain.getValue(), emailDomain.getVisibility()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// REMOVE DOMAINS | ||
for (ProfileEmailDomainEntity existingEmailDomain : existingEmailDomains) { | ||
boolean deleteEmail = true; | ||
for (org.orcid.pojo.ajaxForm.ProfileEmailDomain emailDomain : newEmails.getEmailDomains()) { | ||
if (existingEmailDomain.getEmailDomain().equals(emailDomain.getValue())) { | ||
deleteEmail = false; | ||
break; | ||
} | ||
} | ||
if (deleteEmail) { | ||
profileEmailDomainDao.removeEmailDomain(orcid, existingEmailDomain.getEmailDomain()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void processDomain(String orcid, String email) { | ||
String domain = email.split("@")[1]; | ||
EmailDomainEntity domainInfo = emailDomainDao.findByEmailDomain(domain); | ||
// Check if email is professional | ||
if (domainInfo != null && domainInfo.getCategory().equals(EmailDomainEntity.DomainCategory.PROFESSIONAL)) { | ||
ProfileEmailDomainEntity existingDomain = profileEmailDomainDao.findByEmailDomain(orcid, domain); | ||
// ADD NEW DOMAIN IF ONE DOESN'T EXIST | ||
if (existingDomain == null) { | ||
profileEmailDomainDao.addEmailDomain(orcid, domain, DEFAULT_DOMAIN_VISIBILITY); | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../src/main/java/org/orcid/core/manager/v3/read_only/ProfileEmailDomainManagerReadOnly.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,16 @@ | ||
package org.orcid.core.manager.v3.read_only; | ||
|
||
|
||
import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author Andrej Romanov | ||
* | ||
*/ | ||
public interface ProfileEmailDomainManagerReadOnly { | ||
List<ProfileEmailDomainEntity> getEmailDomains(String orcid); | ||
List<ProfileEmailDomainEntity> getPublicEmailDomains(String orcid); | ||
} |
32 changes: 32 additions & 0 deletions
32
.../java/org/orcid/core/manager/v3/read_only/impl/ProfileEmailDomainManagerReadOnlyImpl.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,32 @@ | ||
package org.orcid.core.manager.v3.read_only.impl; | ||
|
||
|
||
import org.orcid.core.manager.read_only.impl.ManagerReadOnlyBaseImpl; | ||
import org.orcid.core.manager.v3.read_only.ProfileEmailDomainManagerReadOnly; | ||
import org.orcid.persistence.dao.ProfileEmailDomainDao; | ||
import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author Andrej Romanov | ||
* | ||
*/ | ||
public class ProfileEmailDomainManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl implements ProfileEmailDomainManagerReadOnly { | ||
@Resource | ||
protected ProfileEmailDomainDao profileEmailDomainDao; | ||
|
||
public void setProfileEmailDomainDao(ProfileEmailDomainDao profileEmailDomainDao) { | ||
this.profileEmailDomainDao = profileEmailDomainDao; | ||
} | ||
|
||
public List<ProfileEmailDomainEntity> getEmailDomains(String orcid) { | ||
return profileEmailDomainDao.findByOrcid(orcid); | ||
}; | ||
|
||
public List<ProfileEmailDomainEntity> getPublicEmailDomains(String orcid) { | ||
return profileEmailDomainDao.findPublicEmailDomains(orcid); | ||
}; | ||
} |
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
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
79 changes: 79 additions & 0 deletions
79
orcid-core/src/main/java/org/orcid/pojo/ajaxForm/ProfileEmailDomain.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,79 @@ | ||
package org.orcid.pojo.ajaxForm; | ||
|
||
import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity; | ||
|
||
import java.time.LocalDate; | ||
import java.time.ZoneId; | ||
|
||
public class ProfileEmailDomain { | ||
|
||
protected String value; | ||
|
||
protected String visibility; | ||
|
||
private Date createdDate; | ||
|
||
private Date lastModified; | ||
|
||
public static ProfileEmailDomain valueOf(ProfileEmailDomainEntity ed) { | ||
ProfileEmailDomain emailDomain = new ProfileEmailDomain(); | ||
|
||
if (ed != null) { | ||
emailDomain.setValue(ed.getEmailDomain()); | ||
emailDomain.setVisibility(ed.getVisibility()); | ||
|
||
if (ed.getDateCreated() != null) { | ||
Date createdDate = new Date(); | ||
LocalDate date = ed.getDateCreated().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); | ||
createdDate.setYear(String.valueOf(date.getYear())); | ||
createdDate.setMonth(String.valueOf(date.getMonth())); | ||
createdDate.setDay(String.valueOf(date.getDayOfMonth())); | ||
createdDate.setTimestamp(ed.getDateCreated().toInstant().toEpochMilli()); | ||
emailDomain.setCreatedDate(createdDate); | ||
} | ||
|
||
if (ed.getLastModified() != null) { | ||
Date lastModifiedDate = new Date(); | ||
LocalDate date = ed.getLastModified().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); | ||
lastModifiedDate.setYear(String.valueOf(date.getYear())); | ||
lastModifiedDate.setMonth(String.valueOf(date.getMonth())); | ||
lastModifiedDate.setDay(String.valueOf(date.getDayOfMonth())); | ||
emailDomain.setLastModified(lastModifiedDate); | ||
} | ||
} | ||
return emailDomain; | ||
} | ||
|
||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getVisibility() { | ||
return visibility; | ||
} | ||
|
||
public void setVisibility(String visibility) { | ||
this.visibility = visibility; | ||
} | ||
|
||
public Date getCreatedDate() { | ||
return createdDate; | ||
} | ||
|
||
public void setCreatedDate(Date createdDate) { | ||
this.createdDate = createdDate; | ||
} | ||
|
||
public Date getLastModified() { | ||
return lastModified; | ||
} | ||
|
||
public void setLastModified(Date lastModified) { | ||
this.lastModified = lastModified; | ||
} | ||
} |
Oops, something went wrong.