diff --git a/orcid-core/src/main/java/org/orcid/pojo/summary/AffiliationSummary.java b/orcid-core/src/main/java/org/orcid/pojo/summary/AffiliationSummary.java index fd4f04fdfd2..98ff367b11c 100644 --- a/orcid-core/src/main/java/org/orcid/pojo/summary/AffiliationSummary.java +++ b/orcid-core/src/main/java/org/orcid/pojo/summary/AffiliationSummary.java @@ -4,14 +4,13 @@ import org.orcid.pojo.ajaxForm.PojoUtil; import java.util.ArrayList; -import java.util.Date; import java.util.List; public class AffiliationSummary { public String organizationName; public String url; - public Date startDate; - public Date endDate; + public String startDate; + public String endDate; public String role; public String title; public String type; @@ -33,19 +32,19 @@ public void setUrl(String url) { this.url = url; } - public Date getStartDate() { + public String getStartDate() { return startDate; } - public void setStartDate(Date startDate) { + public void setStartDate(String startDate) { this.startDate = startDate; } - public Date getEndDate() { + public String getEndDate() { return endDate; } - public void setEndDate(Date endDate) { + public void setEndDate(String endDate) { this.endDate = endDate; } @@ -104,12 +103,11 @@ public static AffiliationSummary valueOf(org.orcid.jaxb.model.v3.release.record. } if (!PojoUtil.isEmpty(as.getStartDate())) { - FuzzyDate date = as.getStartDate(); -// form.setStartDate(new Date(date.getYear().getValue(), date.getMonth(), date.getDay())); + form.setStartDate(getDate(as.getStartDate())); } if (!PojoUtil.isEmpty(as.getEndDate())) { -// form.setStartDate(affiliationForm.getEndDate().toJavaDate()); + form.setEndDate(getDate(as.getEndDate())); } if (!PojoUtil.isEmpty(as.getRoleTitle())) { @@ -132,4 +130,8 @@ public static AffiliationSummary valueOf(org.orcid.jaxb.model.v3.release.record. } return form; } + + private static String getDate(FuzzyDate date) { + return date != null ? date.toString() : null; + } } diff --git a/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java b/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java index 8c731291ec8..363ed25d0da 100644 --- a/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java +++ b/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummary.java @@ -1,7 +1,6 @@ package org.orcid.pojo.summary; -import java.util.Date; import java.util.List; public class RecordSummary { @@ -9,8 +8,8 @@ public class RecordSummary { private String orcid; private List employmentAffiliations; private int employmentAffiliationsCount; - private Date creation; - private Date lastModified; + private String creation; + private String lastModified; private int validatedWorks; private int selfAssertedWorks; private int reviews; @@ -53,19 +52,19 @@ public void setEmploymentAffiliationsCount(int employmentAffiliationsCount) { this.employmentAffiliationsCount = employmentAffiliationsCount; } - public Date getCreation() { + public String getCreation() { return creation; } - public void setCreation(Date creation) { + public void setCreation(String creation) { this.creation = creation; } - public Date getLastModified() { + public String getLastModified() { return lastModified; } - public void setLastModified(Date lastModified) { + public void setLastModified(String lastModified) { this.lastModified = lastModified; } 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 b0d1c376f94..c2d4de2ef0b 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 @@ -77,9 +77,12 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import javax.xml.datatype.XMLGregorianCalendar; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.GregorianCalendar; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -375,12 +378,14 @@ RecordSummary getSummary(String orcid) { List employmentAffiliations = new ArrayList<>(); - Stream> employmentsList = employmentsSummary.stream().limit(3); - employmentsList.forEach(e -> { - for (EmploymentSummary s : e.getActivities()) { - employmentAffiliations.add(AffiliationSummary.valueOf(s, orcid, "employment")); - } - }); + if (employmentsSummary.size() > 0) { + Stream> employmentsList = employmentsSummary.stream().limit(3); + employmentsList.forEach(e -> { + for (EmploymentSummary s : e.getActivities()) { + employmentAffiliations.add(AffiliationSummary.valueOf(s, orcid, "employment")); + } + }); + } recordSummary.setEmploymentAffiliationsCount(employmentsSummary.size()); recordSummary.setEmploymentAffiliations(employmentAffiliations); @@ -408,15 +413,17 @@ RecordSummary getSummary(String orcid) { AtomicInteger validatedWorks = new AtomicInteger(); AtomicInteger selfAssertedWorks = new AtomicInteger(); - workGroups.forEach(work -> { - work.getWorkSummary().forEach(w -> { - if (w.getSource().getSourceName().getContent().equals(orcid)) { - selfAssertedWorks.getAndIncrement(); - } else { - validatedWorks.getAndIncrement(); - } + if (workGroups != null) { + workGroups.forEach(work -> { + work.getWorkSummary().forEach(w -> { + if (w.getSource().getSourceName().getContent().equals(orcid)) { + selfAssertedWorks.getAndIncrement(); + } else { + validatedWorks.getAndIncrement(); + } + }); }); - }); + } recordSummary.setSelfAssertedWorks(selfAssertedWorks.get()); recordSummary.setValidatedWorks(validatedWorks.get()); @@ -428,15 +435,17 @@ RecordSummary getSummary(String orcid) { AtomicInteger validatedFunds = new AtomicInteger(); AtomicInteger selfAssertedFunds = new AtomicInteger(); - fundingGroups.forEach(fundingGroup -> { - fundingGroup.getFundingSummary().forEach(funding -> { - if (funding.getSource().getSourceName().getContent().equals(orcid)){ - selfAssertedFunds.getAndIncrement(); - } else{ - validatedFunds.getAndIncrement(); - } + if (fundingGroups != null) { + fundingGroups.forEach(fundingGroup -> { + fundingGroup.getFundingSummary().forEach(funding -> { + if (funding.getSource().getSourceName().getContent().equals(orcid)) { + selfAssertedFunds.getAndIncrement(); + } else { + validatedFunds.getAndIncrement(); + } + }); }); - }); + } recordSummary.setSelfAssertedFunds(selfAssertedFunds.get()); recordSummary.setValidatedFunds(validatedFunds.get()); @@ -445,15 +454,23 @@ RecordSummary getSummary(String orcid) { AtomicInteger publicationGrants = new AtomicInteger(); - peerReviewMinimizedSummaryList.forEach(peerReviewMinimizedSummary -> { - publicationGrants.set(publicationGrants.intValue() + peerReviewMinimizedSummary.getPutCodes().size()); - }); + if (peerReviewMinimizedSummaryList != null) { + peerReviewMinimizedSummaryList.forEach(peerReviewMinimizedSummary -> { + publicationGrants.set(publicationGrants.intValue() + peerReviewMinimizedSummary.getPutCodes().size()); + }); + recordSummary.setReviews(peerReviewMinimizedSummaryList.size()); + recordSummary.setPeerReviewPublicationGrants(publicationGrants.intValue()); + } else { + recordSummary.setReviews(0); + recordSummary.setPeerReviewPublicationGrants(0); + } + + ProfileEntity profileEntity = profileEntityManager.findByOrcid(orcid); - recordSummary.setReviews(peerReviewMinimizedSummaryList.size()); - recordSummary.setPeerReviewPublicationGrants(publicationGrants.intValue()); + recordSummary.setLastModified(formatDate(record.getHistory().getLastModifiedDate().getValue())); + recordSummary.setCreation(formatDate(DateUtils.convertToXMLGregorianCalendar(profileEntity.getDateCreated()))); - recordSummary.setCreation(DateUtils.convertToDate(record.getHistory().getCompletionDate().getValue())); - recordSummary.setLastModified(DateUtils.convertToDate(record.getHistory().getLastModifiedDate().getValue())); + recordSummary.setOrcid(recordManagerReadOnly.getOrcidIdentifier(orcid).getUri()); return recordSummary; } @@ -489,6 +506,12 @@ private List retrieveProfessionalActivities(ActivitiesSummar return professionalActivities; } + private String formatDate(XMLGregorianCalendar xmlGregorianCalendar) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + GregorianCalendar gc = xmlGregorianCalendar.toGregorianCalendar(); + return sdf.format(gc.getTime()); + } + private Long getLastModifiedTime(String orcid) { return profileEntityManager.getLastModified(orcid); }