Skip to content

Commit

Permalink
Add verification date to summary.json and mapi summary endpoint (#7124)
Browse files Browse the repository at this point in the history
* add summary pojo assertions

* set verification date

* add more tests

* add test

* add exception throws

* fix naming
  • Loading branch information
auumgn authored Nov 13, 2024
1 parent 886fa94 commit 79fef44
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@
import org.orcid.core.utils.JsonUtils;
import org.orcid.core.utils.cache.redis.RedisClient;
import org.orcid.core.utils.v3.SourceUtils;
import org.orcid.jaxb.model.v3.release.common.CreatedDate;
import org.orcid.jaxb.model.v3.release.common.FuzzyDate;
import org.orcid.jaxb.model.v3.release.common.LastModifiedDate;
import org.orcid.jaxb.model.v3.release.common.Source;
import org.orcid.jaxb.model.v3.release.common.Visibility;
import org.orcid.jaxb.model.v3.release.common.*;
import org.orcid.jaxb.model.v3.release.record.AffiliationType;
import org.orcid.jaxb.model.v3.release.record.Group;
import org.orcid.jaxb.model.v3.release.record.GroupableActivity;
Expand Down Expand Up @@ -286,6 +282,7 @@ public RecordSummaryPojo getRecordSummaryPojo(String orcid) {
for (EmailDomain ed : recordSummary.getEmailDomains().getEmailDomains()) {
EmailDomainSummary eds = new EmailDomainSummary();
eds.setValue(ed.getValue());
eds.setVerificationDate(ed.getVerificationDate().toString());
emailDomains.add(eds);
}
}
Expand Down Expand Up @@ -524,21 +521,22 @@ public void generateEmailDomainsSummary(RecordSummary recordSummary, String orci
for (ProfileEmailDomainEntity ped : emailDomains) {
ed = new EmailDomain();
ed.setValue(ped.getEmailDomain());
ed.setVerificationDate( new VerificationDate(DateUtils.convertToXMLGregorianCalendar(ped.getDateCreated())));
edList.add(ed);
}
}
List<EmailDomain> emailDomainsTop3 = new ArrayList<EmailDomain>();
edList.stream().limit(3).forEach(t -> {
EmailDomain ed = new EmailDomain();
ed.setValue(t.getValue());
ed.setVerificationDate(t.getVerificationDate());
emailDomainsTop3.add(ed);
});

EmailDomains eds = new EmailDomains();
eds.setCount(edList.size());
if (!emailDomainsTop3.isEmpty()) {
eds.setEmailDomains(emailDomainsTop3);

}

recordSummary.setEmailDomains(eds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class ProfileEmailDomainManagerImpl extends ProfileEmailDomainManagerRead

@Transactional
public void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails newEmails) {
if (orcid == null || orcid.isBlank()) {
throw new IllegalArgumentException("ORCID must not be empty");
}
List<ProfileEmailDomainEntity> existingEmailDomains = profileEmailDomainDao.findByOrcid(orcid);

if (existingEmailDomains != null) {
Expand All @@ -55,7 +58,6 @@ public void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails newE
}
}
}

// REMOVE DOMAINS
for (ProfileEmailDomainEntity existingEmailDomain : existingEmailDomains) {
boolean deleteEmail = true;
Expand All @@ -73,6 +75,13 @@ public void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails newE
}

public void processDomain(String orcid, String email) {
if (email == null || email.isBlank()) {
throw new IllegalArgumentException("Email must not be empty");
}
if (orcid == null || orcid.isBlank()) {
throw new IllegalArgumentException("ORCID must not be empty");
}

String domain = email.split("@")[1];
EmailDomainEntity domainInfo = emailDomainDao.findByEmailDomain(domain);
// Check if email is professional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
*/
public class ProfileEmailDomainManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl implements ProfileEmailDomainManagerReadOnly {
@Resource
protected ProfileEmailDomainDao profileEmailDomainDao;
protected ProfileEmailDomainDao profileEmailDomainDaoReadOnly;

public void setProfileEmailDomainDao(ProfileEmailDomainDao profileEmailDomainDao) {
this.profileEmailDomainDao = profileEmailDomainDao;
this.profileEmailDomainDaoReadOnly = profileEmailDomainDao;
}

public List<ProfileEmailDomainEntity> getEmailDomains(String orcid) {
return profileEmailDomainDao.findByOrcid(orcid);
return profileEmailDomainDaoReadOnly.findByOrcid(orcid);
};

public List<ProfileEmailDomainEntity> getPublicEmailDomains(String orcid) {
return profileEmailDomainDao.findPublicEmailDomains(orcid);
return profileEmailDomainDaoReadOnly.findPublicEmailDomains(orcid);
};
}
15 changes: 13 additions & 2 deletions orcid-core/src/main/java/org/orcid/core/model/EmailDomain.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,37 @@
import javax.xml.bind.annotation.XmlType;

import org.orcid.jaxb.model.v3.release.common.FuzzyDate;
import org.orcid.jaxb.model.v3.release.common.VerificationDate;
import org.orcid.pojo.ajaxForm.Date;

import io.swagger.v3.oas.annotations.media.Schema;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "value"})
@XmlType(propOrder = { "value", "verificationDate"})
@XmlRootElement(name = "email-domain", namespace = "http://www.orcid.org/ns/summary")
@Schema(description = "Email Domain")
public class EmailDomain {
@XmlElement(name = "value", namespace = "http://www.orcid.org/ns/summary")
protected String value;

@XmlElement(name = "verification-date", namespace = "http://www.orcid.org/ns/summary")
protected VerificationDate verificationDate;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}


public VerificationDate getVerificationDate() {
return verificationDate;
}

public void setVerificationDate(VerificationDate verificationDate) {
this.verificationDate = verificationDate;
}

@Override
public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package org.orcid.pojo.summary;

import org.orcid.jaxb.model.v3.release.common.VerificationDate;
import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity;
import org.orcid.pojo.ajaxForm.Date;
import org.orcid.pojo.ajaxForm.PojoUtil;
import org.orcid.utils.DateUtils;

public class EmailDomainSummary {
private String value;

public String verificationDate;

public String getValue() {
return value;
}
Expand All @@ -14,17 +19,24 @@ public void setValue(String value) {
this.value = value;
}


public String getVerificationDate() {
return verificationDate;
}

public void setVerificationDate(String verificationDate) {
this.verificationDate = verificationDate;
}


public static EmailDomainSummary valueOf(ProfileEmailDomainEntity pem) {
EmailDomainSummary form = new EmailDomainSummary();

if (pem != null) {
if(!PojoUtil.isEmpty(pem.getEmailDomain())) {
form.setValue(pem.getEmailDomain());
}
form.setVerificationDate(DateUtils.convertToXMLGregorianCalendar(pem.getDateCreated()).toString());
}
return form;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.annotation.Resource;
import javax.xml.datatype.XMLGregorianCalendar;

import com.oracle.truffle.api.profiles.Profile;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
Expand Down Expand Up @@ -81,6 +82,7 @@
public class SummaryManagerTest {
private final String ORCID = "0000-0000-0000-0000";
private final String CLIENT1 = "APP-0000";
private final String EMAIL_DOMAIN = "orcid.org";

public SummaryManagerImpl manager = new SummaryManagerImpl();

Expand Down Expand Up @@ -165,10 +167,9 @@ public void setUp() {
ReflectionTestUtils.setField(manager, "researchResourceManagerReadOnly", researchResourceManagerReadOnlyMock);

// Set EmailDomains
EmailDomains emailDomains = getEmailDomains();
Mockito.when(profileEmailDomainManagerReadOnlyMock.getPublicEmailDomains(Mockito.eq(ORCID))).thenReturn(new ArrayList<ProfileEmailDomainEntity>());
List<ProfileEmailDomainEntity> emailDomains = getEmailDomains();
Mockito.when(profileEmailDomainManagerReadOnlyMock.getPublicEmailDomains(Mockito.eq(ORCID))).thenReturn(emailDomains);
ReflectionTestUtils.setField(manager, "profileEmailDomainManagerReadOnly", profileEmailDomainManagerReadOnlyMock);


// Set metadata
OrcidIdentifier oi = new OrcidIdentifier();
Expand Down Expand Up @@ -557,7 +558,11 @@ public void getSummaryTest() {
// Peer review
assertEquals(Integer.valueOf(2), rs.getPeerReviews().getSelfAssertedCount());
assertEquals(Integer.valueOf(4), rs.getPeerReviews().getPeerReviewPublicationGrants());
assertEquals(Integer.valueOf(16), rs.getPeerReviews().getTotal());
assertEquals(Integer.valueOf(16), rs.getPeerReviews().getTotal());

// Email domains
assertEquals("2024-12-20", rs.getEmailDomains().getEmailDomains().get(0).getVerificationDate().toString());
assertEquals(1, rs.getEmailDomains().getEmailDomains().size());
}

/**
Expand Down Expand Up @@ -588,7 +593,11 @@ public void getSummaryPojoTest() {
// Peer review
assertEquals(2, rs.getSelfAssertedPeerReviews());
assertEquals(4, rs.getPeerReviewPublicationGrants());
assertEquals(16, rs.getPeerReviewsTotal());
assertEquals(16, rs.getPeerReviewsTotal());
// Email domain
assertEquals(1, rs.getEmailDomains().size());
assertEquals("2024-12-20", rs.getEmailDomains().get(0).getVerificationDate());

}

private PersonExternalIdentifiers getPersonExternalIdentifiers() {
Expand All @@ -607,9 +616,13 @@ private ResearchResources getResearchResources() {
return researchResources;
}

private EmailDomains getEmailDomains() {
EmailDomains emailDomains = new EmailDomains();

private List<ProfileEmailDomainEntity> getEmailDomains() {
List<ProfileEmailDomainEntity> emailDomains = new ArrayList<ProfileEmailDomainEntity>();
ProfileEmailDomainEntity emailDomain = new ProfileEmailDomainEntity();
emailDomain.setEmailDomain(EMAIL_DOMAIN);
emailDomain.setOrcid(ORCID);
emailDomain.setDateCreated(new Date(124, 11, 20));
emailDomains.add(emailDomain);
return emailDomains;
}

Expand Down
Loading

0 comments on commit 79fef44

Please sign in to comment.