diff --git a/orcid-test/src/main/resources/data/OrgAffiliationEntityData.xml b/orcid-test/src/main/resources/data/OrgAffiliationEntityData.xml
index 684a6f9f29e..47226910685 100644
--- a/orcid-test/src/main/resources/data/OrgAffiliationEntityData.xml
+++ b/orcid-test/src/main/resources/data/OrgAffiliationEntityData.xml
@@ -1142,4 +1142,102 @@
visibility="PRIVATE"
client_source_id="APP-5555555555555555"
/>
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
diff --git a/orcid-test/src/main/resources/data/ProfileEntityData.xml b/orcid-test/src/main/resources/data/ProfileEntityData.xml
index 3f516a1d61a..c2efa79aed1 100644
--- a/orcid-test/src/main/resources/data/ProfileEntityData.xml
+++ b/orcid-test/src/main/resources/data/ProfileEntityData.xml
@@ -435,6 +435,26 @@
using_2fa="true"
/>
+
+
+
+
-
\ No newline at end of file
+
diff --git a/orcid-test/src/main/resources/data/RecordNameEntityData.xml b/orcid-test/src/main/resources/data/RecordNameEntityData.xml
index 751f059399d..ce8c718ec28 100644
--- a/orcid-test/src/main/resources/data/RecordNameEntityData.xml
+++ b/orcid-test/src/main/resources/data/RecordNameEntityData.xml
@@ -207,5 +207,16 @@
given_names="Given names"
family_name="Family name"
visibility="PRIVATE"
- />
-
\ No newline at end of file
+ />
+
+
+
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 b77278a2cfd..d089fd37d32 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
@@ -1,8 +1,5 @@
package org.orcid.frontend.web.controllers;
-import com.fasterxml.jackson.databind.ser.FilterProvider;
-import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
-import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import org.orcid.core.exception.DeactivatedException;
import org.orcid.core.exception.LockedException;
import org.orcid.core.exception.OrcidDeprecatedException;
@@ -69,7 +66,6 @@
import org.orcid.pojo.summary.ExternalIdentifiersSummary;
import org.orcid.pojo.summary.RecordSummary;
import org.orcid.utils.DateUtils;
-import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -81,6 +77,8 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
@@ -189,7 +187,7 @@ PublicRecord getPublicRecord(@PathVariable("orcid") String orcid) {
} catch (OrcidDeprecatedException e) {
isDeprecated = true;
} catch (OrcidNoResultException e) {
- return publicRecord;
+ return publicRecord;
}
publicRecord = getRecord(orcid);
@@ -355,7 +353,7 @@ PublicRecord getRecord(String orcid) {
return recordSummary;
} else {
recordSummary = getSummary(orcid);
- recordSummary.setStatus("active");
+ recordSummary.setStatus("active");
return recordSummary;
}
}
@@ -393,8 +391,9 @@ RecordSummary getSummary(String orcid) {
List employmentAffiliations = new ArrayList<>();
- if (groupedEmployments.size() > 0) {
+ sortAffiliationsByCreatedDate(groupedEmployments);
+ if (groupedEmployments.size() > 0) {
Stream employmentsList = groupedEmployments.stream().limit(3);
employmentsList.forEach(e -> employmentAffiliations.add(AffiliationSummary.valueOf(e.getDefaultAffiliation(), orcid, "employment")));
}
@@ -486,15 +485,16 @@ RecordSummary getSummary(String orcid) {
private List retrieveProfessionalActivities(AffiliationGroupContainer groupedAffiliations, String orcid) {
List professionalActivities = new ArrayList<>();
- List membershipGroupedAffiliations = groupedAffiliations.getAffiliationGroups().get(AffiliationType.MEMBERSHIP);
- List serviceGroupedAffiliations = groupedAffiliations.getAffiliationGroups().get(AffiliationType.SERVICE);
- List invitedPositionGroupedAffiliations = groupedAffiliations.getAffiliationGroups().get(AffiliationType.INVITED_POSITION);
- List distinctionGroupedAffiliations = groupedAffiliations.getAffiliationGroups().get(AffiliationType.DISTINCTION);
+ List affiliationGroupForms = new ArrayList<>();
+
+ affiliationGroupForms.addAll(groupedAffiliations.getAffiliationGroups().get(AffiliationType.MEMBERSHIP));
+ affiliationGroupForms.addAll(groupedAffiliations.getAffiliationGroups().get(AffiliationType.SERVICE));
+ affiliationGroupForms.addAll(groupedAffiliations.getAffiliationGroups().get(AffiliationType.INVITED_POSITION));
+ affiliationGroupForms.addAll(groupedAffiliations.getAffiliationGroups().get(AffiliationType.DISTINCTION));
- membershipGroupedAffiliations.forEach(e -> professionalActivities.add(AffiliationSummary.valueOf(e.getDefaultAffiliation(), orcid, "membership")));
- serviceGroupedAffiliations.forEach(e -> professionalActivities.add(AffiliationSummary.valueOf(e.getDefaultAffiliation(), orcid, "service")));
- invitedPositionGroupedAffiliations.forEach(e -> professionalActivities.add(AffiliationSummary.valueOf(e.getDefaultAffiliation(), orcid, "invited-position")));
- distinctionGroupedAffiliations.forEach(e -> professionalActivities.add(AffiliationSummary.valueOf(e.getDefaultAffiliation(), orcid, "distinction")));
+ sortAffiliationsByCreatedDate(affiliationGroupForms);
+
+ affiliationGroupForms.forEach(e -> professionalActivities.add(AffiliationSummary.valueOf(e.getDefaultAffiliation(), orcid, e.getAffiliationType().value())));
return professionalActivities;
}
@@ -508,4 +508,9 @@ private String formatDate(XMLGregorianCalendar xmlGregorianCalendar) {
private Long getLastModifiedTime(String orcid) {
return profileEntityManager.getLastModified(orcid);
}
+
+ private void sortAffiliationsByCreatedDate(List affiliationGroupForms) {
+ affiliationGroupForms.sort(Comparator.comparing(a -> a.getDefaultAffiliation().getCreatedDate().toJavaDate()));
+ Collections.reverse(affiliationGroupForms);
+ }
}
diff --git a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerTest.java b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerTest.java
index 5cb8fa3ef78..9354e6b7d29 100644
--- a/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerTest.java
+++ b/orcid-web/src/test/java/org/orcid/frontend/web/controllers/PublicRecordControllerTest.java
@@ -216,4 +216,14 @@ public void testGetRecordSummaryPrivateName() {
assertNull(record.getName());
}
+
+ @Test
+ public void testGetRecordSummaryProfessionalActivitiesSortedByCreationDate() {
+ RecordSummary record = publicRecordController.getSummaryRecord("0000-0000-0000-0008");
+
+ assertEquals(5, record.getProfessionalActivitiesCount());
+ assertEquals("2023-01-05", record.getProfessionalActivities().get(0).getStartDate());
+ assertEquals("2023-01-04", record.getProfessionalActivities().get(1).getStartDate());
+ assertEquals("2023-01-03", record.getProfessionalActivities().get(2).getStartDate());
+ }
}