diff --git a/orcid-test/src/main/resources/data/OrgAffiliationEntityData.xml b/orcid-test/src/main/resources/data/OrgAffiliationEntityData.xml index 47226910685..caa8ad76cb1 100644 --- a/orcid-test/src/main/resources/data/OrgAffiliationEntityData.xml +++ b/orcid-test/src/main/resources/data/OrgAffiliationEntityData.xml @@ -1177,7 +1177,7 @@ start_day="04" end_year="2030" end_month="01" - end_day="01" + end_day="03" visibility="PUBLIC" client_source_id="APP-5555555555555555" display_index="1" @@ -1195,8 +1195,8 @@ start_year="2023" start_month="01" start_day="03" - end_year="2030" - end_month="01" + end_year="2023" + end_month="05" end_day="01" visibility="PUBLIC" client_source_id="APP-5555555555555555" @@ -1214,9 +1214,6 @@ last_modified="2023-01-02 15:31:00.00" start_year="2023" start_month="01" - start_day="02" - end_year="2030" - end_month="01" end_day="01" visibility="PUBLIC" client_source_id="APP-5555555555555555" @@ -1234,9 +1231,6 @@ start_year="2023" start_month="01" start_day="01" - end_year="2030" - end_month="01" - end_day="01" visibility="PUBLIC" source_id="0000-0000-0000-0003" /> 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 d089fd37d32..9d43e0e7516 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 @@ -55,6 +55,7 @@ import org.orcid.pojo.ajaxForm.AffiliationGroupContainer; import org.orcid.pojo.ajaxForm.AffiliationGroupForm; import org.orcid.pojo.ajaxForm.BiographyForm; +import org.orcid.pojo.ajaxForm.Date; import org.orcid.pojo.ajaxForm.ExternalIdentifiersForm; import org.orcid.pojo.ajaxForm.KeywordsForm; import org.orcid.pojo.ajaxForm.NamesForm; @@ -510,7 +511,29 @@ private Long getLastModifiedTime(String orcid) { } private void sortAffiliationsByCreatedDate(List affiliationGroupForms) { - affiliationGroupForms.sort(Comparator.comparing(a -> a.getDefaultAffiliation().getCreatedDate().toJavaDate())); + List activePutCodesWithOutDate = new ArrayList<>(); + + affiliationGroupForms.forEach(affiliationGroupForm -> { + if (affiliationGroupForm.getDefaultAffiliation().getEndDate().getYear() == null || "".equals(affiliationGroupForm.getDefaultAffiliation().getEndDate().getYear())) { + activePutCodesWithOutDate.add(affiliationGroupForm.getActivePutCode()); + affiliationGroupForm.getDefaultAffiliation().setEndDate(Date.valueOf(new java.util.Date())); + } + }); + + affiliationGroupForms.sort(Comparator.comparing(a -> a.getDefaultAffiliation().getEndDate().toJavaDate())); Collections.reverse(affiliationGroupForms); + + if (activePutCodesWithOutDate.size() > 0) { + Iterator i = activePutCodesWithOutDate.iterator(); + while (i.hasNext()) { + Long activePutCode = i.next(); + affiliationGroupForms.forEach(affiliationGroupForm -> { + if (activePutCode.equals(affiliationGroupForm.getActivePutCode())) { + affiliationGroupForm.getDefaultAffiliation().setEndDate(null); + i.remove(); + } + }); + } + } } } 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 131a2c66ef1..0d6f385a8cd 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 @@ -224,12 +224,12 @@ public void testGetRecordSummaryPrivateName() { } @Test - public void testGetRecordSummaryProfessionalActivitiesSortedByCreationDate() { + public void testGetRecordSummaryProfessionalActivitiesSortedByEndDate() { 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()); + assertEquals("2030-01-03", record.getProfessionalActivities().get(0).getEndDate()); + assertEquals("2030-01-01", record.getProfessionalActivities().get(1).getEndDate()); + assertNull(record.getProfessionalActivities().get(2).getEndDate()); } }