Skip to content

Commit

Permalink
fix: Update dates format
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielPalafox committed Jul 14, 2023
1 parent a53cce0 commit 39cc863
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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())) {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package org.orcid.pojo.summary;


import java.util.Date;
import java.util.List;

public class RecordSummary {
private String name;
private String orcid;
private List<AffiliationSummary> 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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -375,12 +378,14 @@ RecordSummary getSummary(String orcid) {

List<AffiliationSummary> employmentAffiliations = new ArrayList<>();

Stream<AffiliationGroup<EmploymentSummary>> 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<AffiliationGroup<EmploymentSummary>> 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);
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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;
}
Expand Down Expand Up @@ -489,6 +506,12 @@ private List<AffiliationSummary> 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);
}
Expand Down

0 comments on commit 39cc863

Please sign in to comment.