Skip to content

Commit 79fef44

Browse files
authored
Add verification date to summary.json and mapi summary endpoint (#7124)
* add summary pojo assertions * set verification date * add more tests * add test * add exception throws * fix naming
1 parent 886fa94 commit 79fef44

9 files changed

Lines changed: 274 additions & 25 deletions

File tree

orcid-core/src/main/java/org/orcid/core/common/manager/impl/SummaryManagerImpl.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@
4343
import org.orcid.core.utils.JsonUtils;
4444
import org.orcid.core.utils.cache.redis.RedisClient;
4545
import org.orcid.core.utils.v3.SourceUtils;
46-
import org.orcid.jaxb.model.v3.release.common.CreatedDate;
47-
import org.orcid.jaxb.model.v3.release.common.FuzzyDate;
48-
import org.orcid.jaxb.model.v3.release.common.LastModifiedDate;
49-
import org.orcid.jaxb.model.v3.release.common.Source;
50-
import org.orcid.jaxb.model.v3.release.common.Visibility;
46+
import org.orcid.jaxb.model.v3.release.common.*;
5147
import org.orcid.jaxb.model.v3.release.record.AffiliationType;
5248
import org.orcid.jaxb.model.v3.release.record.Group;
5349
import org.orcid.jaxb.model.v3.release.record.GroupableActivity;
@@ -286,6 +282,7 @@ public RecordSummaryPojo getRecordSummaryPojo(String orcid) {
286282
for (EmailDomain ed : recordSummary.getEmailDomains().getEmailDomains()) {
287283
EmailDomainSummary eds = new EmailDomainSummary();
288284
eds.setValue(ed.getValue());
285+
eds.setVerificationDate(ed.getVerificationDate().toString());
289286
emailDomains.add(eds);
290287
}
291288
}
@@ -524,21 +521,22 @@ public void generateEmailDomainsSummary(RecordSummary recordSummary, String orci
524521
for (ProfileEmailDomainEntity ped : emailDomains) {
525522
ed = new EmailDomain();
526523
ed.setValue(ped.getEmailDomain());
524+
ed.setVerificationDate( new VerificationDate(DateUtils.convertToXMLGregorianCalendar(ped.getDateCreated())));
527525
edList.add(ed);
528526
}
529527
}
530528
List<EmailDomain> emailDomainsTop3 = new ArrayList<EmailDomain>();
531529
edList.stream().limit(3).forEach(t -> {
532530
EmailDomain ed = new EmailDomain();
533531
ed.setValue(t.getValue());
532+
ed.setVerificationDate(t.getVerificationDate());
534533
emailDomainsTop3.add(ed);
535534
});
536535

537536
EmailDomains eds = new EmailDomains();
538537
eds.setCount(edList.size());
539538
if (!emailDomainsTop3.isEmpty()) {
540539
eds.setEmailDomains(emailDomainsTop3);
541-
542540
}
543541

544542
recordSummary.setEmailDomains(eds);

orcid-core/src/main/java/org/orcid/core/manager/v3/impl/ProfileEmailDomainManagerImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class ProfileEmailDomainManagerImpl extends ProfileEmailDomainManagerRead
4242

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

4750
if (existingEmailDomains != null) {
@@ -55,7 +58,6 @@ public void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails newE
5558
}
5659
}
5760
}
58-
5961
// REMOVE DOMAINS
6062
for (ProfileEmailDomainEntity existingEmailDomain : existingEmailDomains) {
6163
boolean deleteEmail = true;
@@ -73,6 +75,13 @@ public void updateEmailDomains(String orcid, org.orcid.pojo.ajaxForm.Emails newE
7375
}
7476

7577
public void processDomain(String orcid, String email) {
78+
if (email == null || email.isBlank()) {
79+
throw new IllegalArgumentException("Email must not be empty");
80+
}
81+
if (orcid == null || orcid.isBlank()) {
82+
throw new IllegalArgumentException("ORCID must not be empty");
83+
}
84+
7685
String domain = email.split("@")[1];
7786
EmailDomainEntity domainInfo = emailDomainDao.findByEmailDomain(domain);
7887
// Check if email is professional

orcid-core/src/main/java/org/orcid/core/manager/v3/read_only/impl/ProfileEmailDomainManagerReadOnlyImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
*/
1717
public class ProfileEmailDomainManagerReadOnlyImpl extends ManagerReadOnlyBaseImpl implements ProfileEmailDomainManagerReadOnly {
1818
@Resource
19-
protected ProfileEmailDomainDao profileEmailDomainDao;
19+
protected ProfileEmailDomainDao profileEmailDomainDaoReadOnly;
2020

2121
public void setProfileEmailDomainDao(ProfileEmailDomainDao profileEmailDomainDao) {
22-
this.profileEmailDomainDao = profileEmailDomainDao;
22+
this.profileEmailDomainDaoReadOnly = profileEmailDomainDao;
2323
}
2424

2525
public List<ProfileEmailDomainEntity> getEmailDomains(String orcid) {
26-
return profileEmailDomainDao.findByOrcid(orcid);
26+
return profileEmailDomainDaoReadOnly.findByOrcid(orcid);
2727
};
2828

2929
public List<ProfileEmailDomainEntity> getPublicEmailDomains(String orcid) {
30-
return profileEmailDomainDao.findPublicEmailDomains(orcid);
30+
return profileEmailDomainDaoReadOnly.findPublicEmailDomains(orcid);
3131
};
3232
}

orcid-core/src/main/java/org/orcid/core/model/EmailDomain.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,37 @@
1010
import javax.xml.bind.annotation.XmlType;
1111

1212
import org.orcid.jaxb.model.v3.release.common.FuzzyDate;
13+
import org.orcid.jaxb.model.v3.release.common.VerificationDate;
1314
import org.orcid.pojo.ajaxForm.Date;
1415

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

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

26+
@XmlElement(name = "verification-date", namespace = "http://www.orcid.org/ns/summary")
27+
protected VerificationDate verificationDate;
28+
2529
public String getValue() {
2630
return value;
2731
}
2832

2933
public void setValue(String value) {
3034
this.value = value;
3135
}
32-
36+
37+
public VerificationDate getVerificationDate() {
38+
return verificationDate;
39+
}
40+
41+
public void setVerificationDate(VerificationDate verificationDate) {
42+
this.verificationDate = verificationDate;
43+
}
3344

3445
@Override
3546
public int hashCode() {
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package org.orcid.pojo.summary;
22

3+
import org.orcid.jaxb.model.v3.release.common.VerificationDate;
34
import org.orcid.persistence.jpa.entities.ProfileEmailDomainEntity;
5+
import org.orcid.pojo.ajaxForm.Date;
46
import org.orcid.pojo.ajaxForm.PojoUtil;
7+
import org.orcid.utils.DateUtils;
58

69
public class EmailDomainSummary {
710
private String value;
811

12+
public String verificationDate;
13+
914
public String getValue() {
1015
return value;
1116
}
@@ -14,17 +19,24 @@ public void setValue(String value) {
1419
this.value = value;
1520
}
1621

17-
22+
public String getVerificationDate() {
23+
return verificationDate;
24+
}
25+
26+
public void setVerificationDate(String verificationDate) {
27+
this.verificationDate = verificationDate;
28+
}
29+
30+
1831
public static EmailDomainSummary valueOf(ProfileEmailDomainEntity pem) {
1932
EmailDomainSummary form = new EmailDomainSummary();
2033

2134
if (pem != null) {
2235
if(!PojoUtil.isEmpty(pem.getEmailDomain())) {
2336
form.setValue(pem.getEmailDomain());
2437
}
38+
form.setVerificationDate(DateUtils.convertToXMLGregorianCalendar(pem.getDateCreated()).toString());
2539
}
2640
return form;
2741
}
28-
29-
3042
}

orcid-core/src/test/java/org/orcid/core/common/manager/SummaryManagerTest.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import javax.annotation.Resource;
1616
import javax.xml.datatype.XMLGregorianCalendar;
1717

18+
import com.oracle.truffle.api.profiles.Profile;
1819
import org.junit.Before;
1920
import org.junit.Test;
2021
import org.mockito.Mock;
@@ -81,6 +82,7 @@
8182
public class SummaryManagerTest {
8283
private final String ORCID = "0000-0000-0000-0000";
8384
private final String CLIENT1 = "APP-0000";
85+
private final String EMAIL_DOMAIN = "orcid.org";
8486

8587
public SummaryManagerImpl manager = new SummaryManagerImpl();
8688

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

167169
// Set EmailDomains
168-
EmailDomains emailDomains = getEmailDomains();
169-
Mockito.when(profileEmailDomainManagerReadOnlyMock.getPublicEmailDomains(Mockito.eq(ORCID))).thenReturn(new ArrayList<ProfileEmailDomainEntity>());
170+
List<ProfileEmailDomainEntity> emailDomains = getEmailDomains();
171+
Mockito.when(profileEmailDomainManagerReadOnlyMock.getPublicEmailDomains(Mockito.eq(ORCID))).thenReturn(emailDomains);
170172
ReflectionTestUtils.setField(manager, "profileEmailDomainManagerReadOnly", profileEmailDomainManagerReadOnlyMock);
171-
172173

173174
// Set metadata
174175
OrcidIdentifier oi = new OrcidIdentifier();
@@ -557,7 +558,11 @@ public void getSummaryTest() {
557558
// Peer review
558559
assertEquals(Integer.valueOf(2), rs.getPeerReviews().getSelfAssertedCount());
559560
assertEquals(Integer.valueOf(4), rs.getPeerReviews().getPeerReviewPublicationGrants());
560-
assertEquals(Integer.valueOf(16), rs.getPeerReviews().getTotal());
561+
assertEquals(Integer.valueOf(16), rs.getPeerReviews().getTotal());
562+
563+
// Email domains
564+
assertEquals("2024-12-20", rs.getEmailDomains().getEmailDomains().get(0).getVerificationDate().toString());
565+
assertEquals(1, rs.getEmailDomains().getEmailDomains().size());
561566
}
562567

563568
/**
@@ -588,7 +593,11 @@ public void getSummaryPojoTest() {
588593
// Peer review
589594
assertEquals(2, rs.getSelfAssertedPeerReviews());
590595
assertEquals(4, rs.getPeerReviewPublicationGrants());
591-
assertEquals(16, rs.getPeerReviewsTotal());
596+
assertEquals(16, rs.getPeerReviewsTotal());
597+
// Email domain
598+
assertEquals(1, rs.getEmailDomains().size());
599+
assertEquals("2024-12-20", rs.getEmailDomains().get(0).getVerificationDate());
600+
592601
}
593602

594603
private PersonExternalIdentifiers getPersonExternalIdentifiers() {
@@ -607,9 +616,13 @@ private ResearchResources getResearchResources() {
607616
return researchResources;
608617
}
609618

610-
private EmailDomains getEmailDomains() {
611-
EmailDomains emailDomains = new EmailDomains();
612-
619+
private List<ProfileEmailDomainEntity> getEmailDomains() {
620+
List<ProfileEmailDomainEntity> emailDomains = new ArrayList<ProfileEmailDomainEntity>();
621+
ProfileEmailDomainEntity emailDomain = new ProfileEmailDomainEntity();
622+
emailDomain.setEmailDomain(EMAIL_DOMAIN);
623+
emailDomain.setOrcid(ORCID);
624+
emailDomain.setDateCreated(new Date(124, 11, 20));
625+
emailDomains.add(emailDomain);
613626
return emailDomains;
614627
}
615628

0 commit comments

Comments
 (0)