From df77595980aa03e5aaf1276a492c519f55da5930 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Wed, 24 Apr 2024 15:08:25 -0600 Subject: [PATCH] Working on model object --- .../impl/MemberV3ApiServiceDelegatorImpl.java | 3 +- .../core/common/manager/SummaryManager.java | 5 +- .../manager/impl/SummaryManagerImpl.java | 278 ++++++++++++------ .../org/orcid/core}/model/Employment.java | 2 +- .../org/orcid/core}/model/Employments.java | 2 +- .../orcid/core}/model/ExternalIdentifier.java | 2 +- .../core}/model/ExternalIdentifiers.java | 2 +- .../java/org/orcid/core}/model/Fundings.java | 2 +- .../org/orcid/core}/model/ItemsCount.java | 2 +- .../org/orcid/core}/model/PeerReviews.java | 2 +- .../core}/model/ProfessionalActivities.java | 2 +- .../core}/model/ProfessionalActivity.java | 2 +- .../org/orcid/core}/model/RecordSummary.java | 37 ++- .../java/org/orcid/core}/model/Works.java | 2 +- ...ordSummary.java => RecordSummaryPojo.java} | 2 +- .../common/manager/SummaryManagerTest.java | 2 +- .../controllers/PublicRecordController.java | 6 +- .../PublicRecordControllerLegacyTest.java | 14 +- 18 files changed, 250 insertions(+), 117 deletions(-) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/Employment.java (98%) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/Employments.java (97%) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/ExternalIdentifier.java (98%) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/ExternalIdentifiers.java (97%) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/Fundings.java (88%) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/ItemsCount.java (97%) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/PeerReviews.java (98%) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/ProfessionalActivities.java (98%) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/ProfessionalActivity.java (98%) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/RecordSummary.java (78%) rename {orcid-api-web/src/main/java/org/orcid/api/member => orcid-core/src/main/java/org/orcid/core}/model/Works.java (87%) rename orcid-core/src/main/java/org/orcid/pojo/summary/{RecordSummary.java => RecordSummaryPojo.java} (99%) diff --git a/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java b/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java index 3c6551e86c4..cb55957434a 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java +++ b/orcid-api-web/src/main/java/org/orcid/api/memberV3/server/delegator/impl/MemberV3ApiServiceDelegatorImpl.java @@ -63,6 +63,7 @@ import org.orcid.core.manager.v3.read_only.ResearchResourceManagerReadOnly; import org.orcid.core.manager.v3.read_only.ResearcherUrlManagerReadOnly; import org.orcid.core.manager.v3.read_only.WorkManagerReadOnly; +import org.orcid.core.model.RecordSummary; import org.orcid.core.utils.SourceEntityUtils; import org.orcid.core.utils.v3.ContributorUtils; import org.orcid.core.utils.v3.SourceUtils; @@ -127,7 +128,7 @@ import org.orcid.jaxb.model.v3.release.record.summary.Works; import org.orcid.jaxb.model.v3.release.search.Search; import org.orcid.jaxb.model.v3.release.search.expanded.ExpandedSearch; -import org.orcid.pojo.summary.RecordSummary; +import org.orcid.pojo.summary.RecordSummaryPojo; import org.springframework.context.MessageSource; import org.springframework.stereotype.Component; diff --git a/orcid-core/src/main/java/org/orcid/core/common/manager/SummaryManager.java b/orcid-core/src/main/java/org/orcid/core/common/manager/SummaryManager.java index cca83995609..baf501f1cce 100644 --- a/orcid-core/src/main/java/org/orcid/core/common/manager/SummaryManager.java +++ b/orcid-core/src/main/java/org/orcid/core/common/manager/SummaryManager.java @@ -1,7 +1,10 @@ package org.orcid.core.common.manager; -import org.orcid.pojo.summary.RecordSummary; +import org.orcid.core.model.RecordSummary; +import org.orcid.pojo.summary.RecordSummaryPojo; public interface SummaryManager { RecordSummary getRecordSummary(String orcid); + + RecordSummaryPojo getRecordSummaryPojo(String orcid); } diff --git a/orcid-core/src/main/java/org/orcid/core/common/manager/impl/SummaryManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/common/manager/impl/SummaryManagerImpl.java index 0bc95590116..9792cc5adfe 100644 --- a/orcid-core/src/main/java/org/orcid/core/common/manager/impl/SummaryManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/common/manager/impl/SummaryManagerImpl.java @@ -9,6 +9,7 @@ import java.util.Map; import javax.annotation.Resource; +import javax.xml.datatype.XMLGregorianCalendar; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; @@ -22,28 +23,43 @@ import org.orcid.core.manager.v3.read_only.RecordManagerReadOnly; import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly; import org.orcid.core.manager.v3.read_only.WorkManagerReadOnly; +import org.orcid.core.model.Employment; +import org.orcid.core.model.Employments; +import org.orcid.core.model.ExternalIdentifier; +import org.orcid.core.model.ExternalIdentifiers; +import org.orcid.core.model.Fundings; +import org.orcid.core.model.PeerReviews; +import org.orcid.core.model.ProfessionalActivities; +import org.orcid.core.model.ProfessionalActivity; +import org.orcid.core.model.RecordSummary; +import org.orcid.core.model.Works; 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.record.AffiliationType; import org.orcid.jaxb.model.v3.release.record.Group; import org.orcid.jaxb.model.v3.release.record.GroupableActivity; import org.orcid.jaxb.model.v3.release.record.GroupsContainer; +import org.orcid.jaxb.model.v3.release.record.PersonExternalIdentifier; import org.orcid.jaxb.model.v3.release.record.PersonExternalIdentifiers; import org.orcid.jaxb.model.v3.release.record.SourceAware; import org.orcid.jaxb.model.v3.release.record.summary.AffiliationGroup; -import org.orcid.jaxb.model.v3.release.record.summary.AffiliationSummary; import org.orcid.jaxb.model.v3.release.record.summary.DistinctionSummary; -import org.orcid.jaxb.model.v3.release.record.summary.Fundings; +import org.orcid.jaxb.model.v3.release.record.summary.InvitedPositionSummary; +import org.orcid.jaxb.model.v3.release.record.summary.MembershipSummary; +import org.orcid.jaxb.model.v3.release.record.summary.ServiceSummary; import org.orcid.jaxb.model.v3.release.record.summary.WorkGroup; import org.orcid.jaxb.model.v3.release.record.summary.WorkSummary; -import org.orcid.jaxb.model.v3.release.record.summary.Works; import org.orcid.persistence.jpa.entities.ProfileEntity; import org.orcid.pojo.PeerReviewMinimizedSummary; +import org.orcid.pojo.summary.AffiliationSummary; import org.orcid.pojo.summary.ExternalIdentifiersSummary; -import org.orcid.pojo.summary.RecordSummary; +import org.orcid.pojo.summary.RecordSummaryPojo; import org.orcid.utils.DateUtils; import org.springframework.beans.factory.annotation.Value; @@ -99,15 +115,15 @@ public RecordSummary getRecordSummary(String orcid) { RecordSummary recordSummary = new RecordSummary(); - // Set ORCID uri - recordSummary.setOrcid(recordManagerReadOnly.getOrcidIdentifier(orcid).getUri()); + // Set ORCID identifier + recordSummary.setOrcidIdentifier(recordManagerReadOnly.getOrcidIdentifier(orcid)); // Set dates ProfileEntity profileEntity = profileEntityCacheManager.retrieve(orcid); - recordSummary.setLastModified(DateUtils.formatDateISO8601(profileEntity.getLastModified())); - recordSummary.setCreation(DateUtils.formatDateISO8601(profileEntity.getDateCreated())); + recordSummary.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(profileEntity.getLastModified()))); + recordSummary.setCreatedDate(new CreatedDate(DateUtils.convertToXMLGregorianCalendar(profileEntity.getDateCreated()))); - recordSummary.setName(recordNameManagerReadOnly.fetchDisplayablePublicName(orcid)); + recordSummary.setCreditName(recordNameManagerReadOnly.fetchDisplayablePublicName(orcid)); // Generate the affiliations summary generateAffiliationsSummary(recordSummary, orcid); @@ -122,8 +138,7 @@ public RecordSummary getRecordSummary(String orcid) { generateFundingSummary(recordSummary, orcid); // Generate the peer review summary - generatePeerReviewSummary(recordSummary, orcid); - recordSummary.setStatus("active"); + generatePeerReviewSummary(recordSummary, orcid); // Set the summary in the cache if(isSummaryCacheEnabled) { @@ -132,8 +147,160 @@ public RecordSummary getRecordSummary(String orcid) { return recordSummary; } + @Override + public RecordSummaryPojo getRecordSummaryPojo(String orcid) { + RecordSummary recordSummary = getRecordSummary(orcid); + RecordSummaryPojo pojo = new RecordSummaryPojo(); + pojo.setStatus("active"); + + pojo.setOrcid(recordSummary.getOrcidIdentifier().getUri()); + pojo.setName(recordSummary.getCreditName()); + + if(recordSummary.getCreatedDate() != null && recordSummary.getCreatedDate().getValue() != null) { + pojo.setCreation(DateUtils.formatDateISO8601(recordSummary.getCreatedDate().getValue().toGregorianCalendar().getTime())); + } + + if(recordSummary.getLastModifiedDate() != null && recordSummary.getLastModifiedDate().getValue() != null) { + pojo.setLastModified(DateUtils.formatDateISO8601(recordSummary.getLastModifiedDate().getValue().toGregorianCalendar().getTime())); + } + + if(recordSummary.getExternalIdentifiers() != null && recordSummary.getExternalIdentifiers().getExternalIdentifiers() != null) { + List externalIdentifiers = new ArrayList<>(); + for(ExternalIdentifier ei : recordSummary.getExternalIdentifiers().getExternalIdentifiers()) { + ExternalIdentifiersSummary eis = new ExternalIdentifiersSummary(); + eis.setCommonName(ei.getExternalIdType()); + eis.setId(String.valueOf(ei.getPutCode())); + eis.setReference(ei.getExternalIdValue()); + eis.setUrl(ei.getExternalIdUrl()); + eis.setValidated(ei.isValidated()); + externalIdentifiers.add(eis); + } + pojo.setExternalIdentifiers(externalIdentifiers); + } + + if(recordSummary.getEmployments() != null && recordSummary.getEmployments().getEmployments() != null) { + List affiliations = new ArrayList<>(); + for(Employment e : recordSummary.getEmployments().getEmployments()) { + AffiliationSummary as = new AffiliationSummary(); + as.setEndDate(e.getEndDate() == null ? null : e.getEndDate().toString()); + as.setOrganizationName(e.getOrganizationName()); + as.setPutCode(e.getPutCode()); + as.setValidated(e.isValidated()); + affiliations.add(as); + } + pojo.setEmploymentAffiliations(affiliations); + pojo.setEmploymentAffiliationsCount(recordSummary.getEmployments().getCount()); + } + + + + pojo.setProfessionalActivities(); + pojo.setProfessionalActivitiesCount(); + + pojo.setSelfAssertedFunds(); + pojo.setValidatedFunds(); + + pojo.setPeerReviewsTotal(); + pojo.setPeerReviewPublicationGrants(); + pojo.setSelfAssertedPeerReviews(); + + pojo.setSelfAssertedWorks(); + pojo.setValidatedWorks(); + } + + public void generateAffiliationsSummary(RecordSummary recordSummary, String orcid) { + Map>> affiliationsMap = affiliationsManagerReadOnly.getGroupedAffiliations(orcid, + true); + + // EMPLOYMENT + List> employmentGroups = affiliationsMap.get(AffiliationType.EMPLOYMENT); + List preferredEmployments = new ArrayList<>(); + if (employmentGroups != null) { + for (AffiliationGroup group : employmentGroups) { + preferredEmployments.add(getDefaultAffiliationFromGroup(group)); + } + } + // Sort them by end date by default + sortAffiliationsByEndDate(preferredEmployments); + + List employmentsTop3 = new ArrayList<>(); + preferredEmployments.stream().limit(3).forEach(t -> { + Employment e = new Employment(); + e.setEndDate(t.getEndDate()); + e.setOrganizationName((t.getOrganization() == null || StringUtils.isBlank(t.getOrganization().getName())) ? null : t.getOrganization().getName()); + e.setPutCode(t.getPutCode()); + e.setValidated(!SourceUtils.isSelfAsserted(t.getSource(), orcid)); + employmentsTop3.add(e); + }); + Employments e = new Employments(); + e.setCount(preferredEmployments.size()); + e.setEmployments(employmentsTop3); + recordSummary.setEmployments(e); + + // PROFESIONAL ACTIVITIES + List> profesionalActivitesGroups = new ArrayList<>(); + if (affiliationsMap.containsKey(AffiliationType.DISTINCTION)) { + profesionalActivitesGroups.addAll(affiliationsMap.get(AffiliationType.DISTINCTION)); + } + if (affiliationsMap.containsKey(AffiliationType.INVITED_POSITION)) { + profesionalActivitesGroups.addAll(affiliationsMap.get(AffiliationType.INVITED_POSITION)); + } + if (affiliationsMap.containsKey(AffiliationType.MEMBERSHIP)) { + profesionalActivitesGroups.addAll(affiliationsMap.get(AffiliationType.MEMBERSHIP)); + } + if (affiliationsMap.containsKey(AffiliationType.SERVICE)) { + profesionalActivitesGroups.addAll(affiliationsMap.get(AffiliationType.SERVICE)); + } + List preferredProfesionalActivities = new ArrayList<>(); + for (AffiliationGroup group : profesionalActivitesGroups) { + preferredProfesionalActivities.add(getDefaultAffiliationFromGroup(group)); + } + // Sort them by end date by default + sortAffiliationsByEndDate(preferredProfesionalActivities); + + List professionalActivitiesTop3 = new ArrayList<>(); + preferredProfesionalActivities.stream().limit(3).forEach(t -> { + ProfessionalActivity p = new ProfessionalActivity(); + p.setOrganizationName((t.getOrganization() == null || StringUtils.isBlank(t.getOrganization().getName())) ? null : t.getOrganization().getName()); + p.setPutCode(t.getPutCode()); + p.setRole(p.getRole()); + if(t instanceof DistinctionSummary) { + p.setType(AffiliationType.DISTINCTION.name()); + } else if (t instanceof InvitedPositionSummary) { + p.setType(AffiliationType.INVITED_POSITION.name()); + } else if (t instanceof MembershipSummary) { + p.setType(AffiliationType.MEMBERSHIP.name()); + } else if (t instanceof ServiceSummary) { + p.setType(AffiliationType.SERVICE.name()); + } + p.setUrl((t.getUrl() == null || StringUtils.isBlank(t.getUrl().getValue())) ? null : t.getUrl().getValue()); + p.setValidated(!SourceUtils.isSelfAsserted(t.getSource(), orcid)); + professionalActivitiesTop3.add(p); + }); + ProfessionalActivities pa = new ProfessionalActivities(); + pa.setCount(preferredProfesionalActivities.size()); + pa.setProfessionalActivities(professionalActivitiesTop3); + } + + public void generateExternalIdentifiersSummary(RecordSummary recordSummary, String orcid) { + PersonExternalIdentifiers personExternalIdentifiers = externalIdentifierManagerReadOnly.getPublicExternalIdentifiers(orcid); + if(personExternalIdentifiers == null || personExternalIdentifiers.getExternalIdentifiers().isEmpty()) { + return; + } + ExternalIdentifiers eis = new ExternalIdentifiers(); + for(PersonExternalIdentifier pei : personExternalIdentifiers.getExternalIdentifiers()) { + ExternalIdentifier ei = new ExternalIdentifier(); + ei.setExternalIdType(pei.getType()); + ei.setExternalIdUrl((pei.getUrl() == null || StringUtils.isEmpty(pei.getUrl().getValue())) ? null : pei.getUrl().getValue()); + ei.setExternalIdValue(pei.getValue()); + ei.setPutCode(pei.getPutCode()); + ei.setValidated(!SourceUtils.isSelfAsserted(pei.getSource(), orcid)); + } + recordSummary.setExternalIdentifiers(eis); + } + public void generateWorksSummary(RecordSummary recordSummary, String orcid) { - Works works = worksCacheManager.getGroupedWorks(orcid); + org.orcid.jaxb.model.v3.release.record.summary.Works works = worksCacheManager.getGroupedWorks(orcid); Iterator workGroupIt = works.getWorkGroup().iterator(); while (workGroupIt.hasNext()) { WorkGroup workGroup = workGroupIt.next(); @@ -150,16 +317,18 @@ public void generateWorksSummary(RecordSummary recordSummary, String orcid) { } Pair validAndSelfAssertedStats = calculateSelfAssertedAndValidated(works, orcid); - recordSummary.setValidatedWorks(validAndSelfAssertedStats.getLeft()); - recordSummary.setSelfAssertedWorks(validAndSelfAssertedStats.getRight()); + Works worksModel = new Works(); + worksModel.setSelfAssertedCount(validAndSelfAssertedStats.getRight()); + worksModel.setValidatedCount(validAndSelfAssertedStats.getLeft()); } - + public void generateFundingSummary(RecordSummary recordSummary, String orcid) { - Fundings fundingGroups = profileFundingManagerReadOnly.groupFundings(profileFundingManagerReadOnly.getFundingSummaryList(orcid), true); + org.orcid.jaxb.model.v3.release.record.summary.Fundings fundingGroups = profileFundingManagerReadOnly.groupFundings(profileFundingManagerReadOnly.getFundingSummaryList(orcid), true); Pair validAndSelfAssertedStats = calculateSelfAssertedAndValidated(fundingGroups, orcid); - recordSummary.setValidatedFunds(validAndSelfAssertedStats.getLeft()); - recordSummary.setSelfAssertedFunds(validAndSelfAssertedStats.getRight()); + Fundings fundingsModel = new Fundings(); + fundingsModel.setSelfAssertedCount(validAndSelfAssertedStats.getRight()); + fundingsModel.setValidatedCount(validAndSelfAssertedStats.getLeft()); } public void generatePeerReviewSummary(RecordSummary recordSummary, String orcid) { @@ -177,9 +346,10 @@ public void generatePeerReviewSummary(RecordSummary recordSummary, String orcid) } } - recordSummary.setSelfAssertedPeerReviews(selfAssertedPeerReviews); - recordSummary.setPeerReviewsTotal(totalReviewsCount); - recordSummary.setPeerReviewPublicationGrants(peerReviewMinimizedSummaryList.size()); + PeerReviews pr = new PeerReviews(); + pr.setPeerReviewPublicationGrants(peerReviewMinimizedSummaryList.size()); + pr.setSelfAssertedCount(selfAssertedPeerReviews); + pr.setTotal(totalReviewsCount); } private Pair calculateSelfAssertedAndValidated(GroupsContainer c, String orcid) { @@ -206,66 +376,10 @@ private Pair calculateSelfAssertedAndValidated(GroupsContainer return Pair.of(validated, selfAsserted); } - public void generateExternalIdentifiersSummary(RecordSummary recordSummary, String orcid) { - PersonExternalIdentifiers personExternalIdentifiers = externalIdentifierManagerReadOnly.getPublicExternalIdentifiers(orcid); - recordSummary.setExternalIdentifiers(ExternalIdentifiersSummary.valueOf(personExternalIdentifiers, orcid)); - } - - public void generateAffiliationsSummary(RecordSummary recordSummary, String orcid) { - Map>> affiliationsMap = affiliationsManagerReadOnly.getGroupedAffiliations(orcid, - true); - - // EMPLOYMENT - List> employmentGroups = affiliationsMap.get(AffiliationType.EMPLOYMENT); - List preferredEmployments = new ArrayList<>(); - if (employmentGroups != null) { - for (AffiliationGroup group : employmentGroups) { - preferredEmployments.add(getDefaultAffiliationFromGroup(group)); - } - } - // Sort them by end date by default - sortAffiliationsByEndDate(preferredEmployments); - - List employmentsTop3 = new ArrayList<>(); - preferredEmployments.stream().limit(3).forEach(t -> { - employmentsTop3.add(org.orcid.pojo.summary.AffiliationSummary.valueof(t, orcid, AffiliationType.EMPLOYMENT.value())); - }); - recordSummary.setEmploymentAffiliations(employmentsTop3); - recordSummary.setEmploymentAffiliationsCount(preferredEmployments.size()); - - // PROFESIONAL ACTIVITIES - List> profesionalActivitesGroups = new ArrayList<>(); - if (affiliationsMap.containsKey(AffiliationType.DISTINCTION)) { - profesionalActivitesGroups.addAll(affiliationsMap.get(AffiliationType.DISTINCTION)); - } - if (affiliationsMap.containsKey(AffiliationType.INVITED_POSITION)) { - profesionalActivitesGroups.addAll(affiliationsMap.get(AffiliationType.INVITED_POSITION)); - } - if (affiliationsMap.containsKey(AffiliationType.MEMBERSHIP)) { - profesionalActivitesGroups.addAll(affiliationsMap.get(AffiliationType.MEMBERSHIP)); - } - if (affiliationsMap.containsKey(AffiliationType.SERVICE)) { - profesionalActivitesGroups.addAll(affiliationsMap.get(AffiliationType.SERVICE)); - } - List preferredProfesionalActivities = new ArrayList<>(); - for (AffiliationGroup group : profesionalActivitesGroups) { - preferredProfesionalActivities.add(getDefaultAffiliationFromGroup(group)); - } - // Sort them by end date by default - sortAffiliationsByEndDate(preferredProfesionalActivities); - - List professionalActivitiesTop3 = new ArrayList<>(); - preferredProfesionalActivities.stream().limit(3).forEach(t -> { - professionalActivitiesTop3.add(org.orcid.pojo.summary.AffiliationSummary.valueof(t, orcid, AffiliationType.EMPLOYMENT.value())); - }); - recordSummary.setProfessionalActivities(professionalActivitiesTop3); - recordSummary.setProfessionalActivitiesCount(preferredProfesionalActivities.size()); - } - - private AffiliationSummary getDefaultAffiliationFromGroup(AffiliationGroup group) { - AffiliationSummary defaultAffiliation = null; + private org.orcid.jaxb.model.v3.release.record.summary.AffiliationSummary getDefaultAffiliationFromGroup(AffiliationGroup group) { + org.orcid.jaxb.model.v3.release.record.summary.AffiliationSummary defaultAffiliation = null; Long maxDisplayIndex = null; - for (AffiliationSummary as : group.getActivities()) { + for (org.orcid.jaxb.model.v3.release.record.summary.AffiliationSummary as : group.getActivities()) { if (maxDisplayIndex == null || (as.getDisplayIndex() != null && Long.valueOf(as.getDisplayIndex()) > maxDisplayIndex)) { maxDisplayIndex = Long.valueOf(as.getDisplayIndex()); defaultAffiliation = as; @@ -274,8 +388,8 @@ private AffiliationSummary getDefaultAffiliationFromGroup(AffiliationGroup affiliations) { - List summariesWithOutEndDate = new ArrayList<>(); + private void sortAffiliationsByEndDate(List affiliations) { + List summariesWithOutEndDate = new ArrayList<>(); LocalDate today = LocalDate.now(); affiliations.forEach(aff -> { // TODO: Why do we need to overwrite the end date when it is a diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/Employment.java b/orcid-core/src/main/java/org/orcid/core/model/Employment.java similarity index 98% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/Employment.java rename to orcid-core/src/main/java/org/orcid/core/model/Employment.java index 654aeac12e8..1649789b259 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/Employment.java +++ b/orcid-core/src/main/java/org/orcid/core/model/Employment.java @@ -1,4 +1,4 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import java.util.Objects; diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/Employments.java b/orcid-core/src/main/java/org/orcid/core/model/Employments.java similarity index 97% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/Employments.java rename to orcid-core/src/main/java/org/orcid/core/model/Employments.java index f8a3b22d042..d1d8bac30db 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/Employments.java +++ b/orcid-core/src/main/java/org/orcid/core/model/Employments.java @@ -1,4 +1,4 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import java.util.List; import java.util.Objects; diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/ExternalIdentifier.java b/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifier.java similarity index 98% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/ExternalIdentifier.java rename to orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifier.java index 2da14ac74f8..f215b9d2ce5 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/ExternalIdentifier.java +++ b/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifier.java @@ -1,4 +1,4 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import java.util.Objects; diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/ExternalIdentifiers.java b/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifiers.java similarity index 97% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/ExternalIdentifiers.java rename to orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifiers.java index 61073ed15de..4c721c6b0f6 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/ExternalIdentifiers.java +++ b/orcid-core/src/main/java/org/orcid/core/model/ExternalIdentifiers.java @@ -1,4 +1,4 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import java.util.List; import java.util.Objects; diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/Fundings.java b/orcid-core/src/main/java/org/orcid/core/model/Fundings.java similarity index 88% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/Fundings.java rename to orcid-core/src/main/java/org/orcid/core/model/Fundings.java index 676ad93a461..5ca2b4d7185 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/Fundings.java +++ b/orcid-core/src/main/java/org/orcid/core/model/Fundings.java @@ -1,4 +1,4 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import javax.xml.bind.annotation.XmlRootElement; diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/ItemsCount.java b/orcid-core/src/main/java/org/orcid/core/model/ItemsCount.java similarity index 97% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/ItemsCount.java rename to orcid-core/src/main/java/org/orcid/core/model/ItemsCount.java index 7596b3d574e..b9c1d96982b 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/ItemsCount.java +++ b/orcid-core/src/main/java/org/orcid/core/model/ItemsCount.java @@ -1,4 +1,4 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import java.util.Objects; diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/PeerReviews.java b/orcid-core/src/main/java/org/orcid/core/model/PeerReviews.java similarity index 98% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/PeerReviews.java rename to orcid-core/src/main/java/org/orcid/core/model/PeerReviews.java index 77aefbdf744..07e49e15536 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/PeerReviews.java +++ b/orcid-core/src/main/java/org/orcid/core/model/PeerReviews.java @@ -1,4 +1,4 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import java.util.Objects; diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/ProfessionalActivities.java b/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivities.java similarity index 98% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/ProfessionalActivities.java rename to orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivities.java index 42c962e60d6..127f1a9a6be 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/ProfessionalActivities.java +++ b/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivities.java @@ -1,4 +1,4 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import java.util.List; import java.util.Objects; diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/ProfessionalActivity.java b/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivity.java similarity index 98% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/ProfessionalActivity.java rename to orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivity.java index 3c4c5461433..c831ceddd00 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/ProfessionalActivity.java +++ b/orcid-core/src/main/java/org/orcid/core/model/ProfessionalActivity.java @@ -1,4 +1,4 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import java.util.Objects; diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/RecordSummary.java b/orcid-core/src/main/java/org/orcid/core/model/RecordSummary.java similarity index 78% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/RecordSummary.java rename to orcid-core/src/main/java/org/orcid/core/model/RecordSummary.java index 377aa0eb2fa..59285b85d41 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/RecordSummary.java +++ b/orcid-core/src/main/java/org/orcid/core/model/RecordSummary.java @@ -1,31 +1,41 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import java.util.Objects; +import javax.annotation.Resource; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import javax.xml.datatype.XMLGregorianCalendar; +import org.orcid.core.manager.impl.OrcidUrlManager; +import org.orcid.jaxb.model.common_v2.SourceClientId; import org.orcid.jaxb.model.v3.release.common.CreatedDate; import org.orcid.jaxb.model.v3.release.common.LastModifiedDate; +import org.orcid.jaxb.model.v3.release.common.OrcidIdentifier; +import org.orcid.pojo.summary.AffiliationSummary; +import org.orcid.utils.DateUtils; import io.swagger.v3.oas.annotations.media.Schema; @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(propOrder = { "createdDate", "lastModifiedDate", "creditName", "orcidIdentifier", "externalIdentifiers", "employments", "profilessionalActivities", "fundings", +@XmlType(propOrder = { "createdDate", "lastModifiedDate", "creditName", "orcidIdentifier", "orcidIdentifier", "externalIdentifiers", "employments", "profilessionalActivities", "fundings", "works", "peerReviews" }) @XmlRootElement(name = "work-summary", namespace = "http://www.orcid.org/ns/work") @Schema(description = "Record summary") public class RecordSummary { - + @Resource + private OrcidUrlManager orcidUrlManager; @XmlElement(name = "last-modified-date", namespace = "http://www.orcid.org/ns/common") private LastModifiedDate lastModifiedDate; @XmlElement(name = "created-date", namespace = "http://www.orcid.org/ns/common") private CreatedDate createdDate; @XmlElement(name = "credit-name", namespace = "http://www.orcid.org/ns/summary") private String creditName; + @XmlElement(name = "orcid-identifier", namespace = "http://www.orcid.org/ns/common") + protected OrcidIdentifier orcidIdentifier; @XmlElement(name = "external-identifiers", namespace = "http://www.orcid.org/ns/summary") private ExternalIdentifiers externalIdentifiers; @XmlElement(name = "employments", namespace = "http://www.orcid.org/ns/summary") @@ -39,6 +49,14 @@ public class RecordSummary { @XmlElement(name = "peer-reviews", namespace = "http://www.orcid.org/ns/summary") private PeerReviews peerReviews; + public OrcidIdentifier getOrcidIdentifier() { + return orcidIdentifier; + } + + public void setOrcidIdentifier(OrcidIdentifier orcidIdentifier) { + this.orcidIdentifier = orcidIdentifier; + } + public LastModifiedDate getLastModifiedDate() { return lastModifiedDate; } @@ -113,7 +131,8 @@ public void setPeerReviews(PeerReviews peerReviews) { @Override public int hashCode() { - return Objects.hash(createdDate, creditName, employments, externalIdentifiers, fundings, lastModifiedDate, peerReviews, professionalActivities, works); + return Objects.hash(createdDate, creditName, employments, externalIdentifiers, fundings, lastModifiedDate, orcidIdentifier, orcidUrlManager, peerReviews, + professionalActivities, works); } @Override @@ -127,12 +146,8 @@ public boolean equals(Object obj) { RecordSummary other = (RecordSummary) obj; return Objects.equals(createdDate, other.createdDate) && Objects.equals(creditName, other.creditName) && Objects.equals(employments, other.employments) && Objects.equals(externalIdentifiers, other.externalIdentifiers) && Objects.equals(fundings, other.fundings) - && Objects.equals(lastModifiedDate, other.lastModifiedDate) && Objects.equals(peerReviews, other.peerReviews) + && Objects.equals(lastModifiedDate, other.lastModifiedDate) && Objects.equals(orcidIdentifier, other.orcidIdentifier) + && Objects.equals(orcidUrlManager, other.orcidUrlManager) && Objects.equals(peerReviews, other.peerReviews) && Objects.equals(professionalActivities, other.professionalActivities) && Objects.equals(works, other.works); - } - - public RecordSummary valueOf(org.orcid.pojo.summary.RecordSummary coreSummaryObject) { - RecordSummary summary = new RecordSummary(); - return summary; - } + } } diff --git a/orcid-api-web/src/main/java/org/orcid/api/member/model/Works.java b/orcid-core/src/main/java/org/orcid/core/model/Works.java similarity index 87% rename from orcid-api-web/src/main/java/org/orcid/api/member/model/Works.java rename to orcid-core/src/main/java/org/orcid/core/model/Works.java index f7d41ea9f8e..3fea14cdc29 100644 --- a/orcid-api-web/src/main/java/org/orcid/api/member/model/Works.java +++ b/orcid-core/src/main/java/org/orcid/core/model/Works.java @@ -1,4 +1,4 @@ -package org.orcid.api.member.model; +package org.orcid.core.model; import javax.xml.bind.annotation.XmlRootElement; diff --git a/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java b/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummaryPojo.java similarity index 99% rename from orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java rename to orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummaryPojo.java index 1c3cfed92fd..51f83708564 100644 --- a/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java +++ b/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummaryPojo.java @@ -9,7 +9,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @XmlRootElement -public class RecordSummary { +public class RecordSummaryPojo { @JsonInclude(Include.NON_NULL) private String name; private String orcid; diff --git a/orcid-core/src/test/java/org/orcid/core/common/manager/SummaryManagerTest.java b/orcid-core/src/test/java/org/orcid/core/common/manager/SummaryManagerTest.java index 70088c6ac9b..16ed6964cbf 100644 --- a/orcid-core/src/test/java/org/orcid/core/common/manager/SummaryManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/common/manager/SummaryManagerTest.java @@ -25,6 +25,7 @@ import org.orcid.core.manager.v3.read_only.ProfileFundingManagerReadOnly; import org.orcid.core.manager.v3.read_only.RecordManagerReadOnly; import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly; +import org.orcid.core.model.RecordSummary; import org.orcid.jaxb.model.v3.release.common.CreatedDate; import org.orcid.jaxb.model.v3.release.common.CreditName; import org.orcid.jaxb.model.v3.release.common.FuzzyDate; @@ -62,7 +63,6 @@ import org.orcid.jaxb.model.v3.release.record.summary.Works; import org.orcid.persistence.jpa.entities.ProfileEntity; import org.orcid.pojo.PeerReviewMinimizedSummary; -import org.orcid.pojo.summary.RecordSummary; import org.orcid.utils.DateUtils; import org.springframework.test.util.ReflectionTestUtils; diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java index 77ef57fbb9c..4eefa72601b 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java @@ -43,7 +43,7 @@ import org.orcid.pojo.ajaxForm.OtherNamesForm; import org.orcid.pojo.ajaxForm.PojoUtil; import org.orcid.pojo.ajaxForm.WebsitesForm; -import org.orcid.pojo.summary.RecordSummary; +import org.orcid.pojo.summary.RecordSummaryPojo; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; @@ -212,8 +212,8 @@ PublicRecord getRecord(String orcid) { } @RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/summary.json", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody RecordSummary getSummaryRecord(@PathVariable("orcid") String orcid) { - RecordSummary recordSummary = new RecordSummary(); + public @ResponseBody RecordSummaryPojo getSummaryRecord(@PathVariable("orcid") String orcid) { + RecordSummaryPojo recordSummary = new RecordSummaryPojo(); try { // Check if the profile is deprecated or locked orcidSecurityManager.checkProfile(orcid); diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java index bb1eeb66089..7da841d7dab 100644 --- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java +++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerLegacyTest.java @@ -12,7 +12,7 @@ import org.orcid.jaxb.model.common.Iso3166Country; import org.orcid.jaxb.model.v3.release.common.Visibility; import org.orcid.pojo.PublicRecord; -import org.orcid.pojo.summary.RecordSummary; +import org.orcid.pojo.summary.RecordSummaryPojo; import org.orcid.test.DBUnitTest; import org.orcid.test.OrcidJUnit4ClassRunner; import org.springframework.test.context.ContextConfiguration; @@ -141,7 +141,7 @@ public void testGetPublicRecord() { @Test public void testGetRecordSummary() { - RecordSummary record = publicRecordController.getSummaryRecord(userOrcid); + RecordSummaryPojo record = publicRecordController.getSummaryRecord(userOrcid); assertEquals("active", record.getStatus()); assertNotNull(record.getName()); @@ -191,7 +191,7 @@ public void testGetRecordSummary() { @Test public void testGetRecordSummaryDeactivated() { - RecordSummary record = publicRecordController.getSummaryRecord(deactivatedUserOrcid); + RecordSummaryPojo record = publicRecordController.getSummaryRecord(deactivatedUserOrcid); assertEquals("Given Names Deactivated Family Name Deactivated", record.getName()); @@ -200,7 +200,7 @@ public void testGetRecordSummaryDeactivated() { @Test public void testGetRecordSummaryLocked() { - RecordSummary record = publicRecordController.getSummaryRecord(lockedUserOrcid); + RecordSummaryPojo record = publicRecordController.getSummaryRecord(lockedUserOrcid); assertNotNull(record.getName()); assertEquals("Given Names Deactivated Family Name Deactivated", record.getName()); @@ -210,7 +210,7 @@ public void testGetRecordSummaryLocked() { @Test public void testGetRecordSummaryDeprecated() { - RecordSummary record = publicRecordController.getSummaryRecord(deprecatedUserOrcid); + RecordSummaryPojo record = publicRecordController.getSummaryRecord(deprecatedUserOrcid); assertNull(record.getName()); @@ -219,14 +219,14 @@ public void testGetRecordSummaryDeprecated() { @Test public void testGetRecordSummaryPrivateName() { - RecordSummary record = publicRecordController.getSummaryRecord(unclaimedUserOrcid); + RecordSummaryPojo record = publicRecordController.getSummaryRecord(unclaimedUserOrcid); assertNull(record.getName()); } @Test public void testGetRecordSummaryProfessionalActivitiesSortedByEndDate() { - RecordSummary record = publicRecordController.getSummaryRecord("0000-0000-0000-0008"); + RecordSummaryPojo record = publicRecordController.getSummaryRecord("0000-0000-0000-0008"); assertEquals(5, record.getProfessionalActivitiesCount()); assertNull(record.getProfessionalActivities().get(0).getEndDate());