Skip to content

Commit

Permalink
Merge pull request #6872 from ORCID/8792-qa-affiliations-and-professi…
Browse files Browse the repository at this point in the history
…onal-activities-in-the-summary-page-should-be-sorted-like-in-the-public-page

fix: Sort professional activities by end date in summary endpoint
  • Loading branch information
leomendoza123 authored Aug 18, 2023
2 parents 90071ed + 4775ba7 commit c0081ae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
12 changes: 3 additions & 9 deletions orcid-test/src/main/resources/data/OrgAffiliationEntityData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -510,7 +511,29 @@ private Long getLastModifiedTime(String orcid) {
}

private void sortAffiliationsByCreatedDate(List<AffiliationGroupForm> affiliationGroupForms) {
affiliationGroupForms.sort(Comparator.comparing(a -> a.getDefaultAffiliation().getCreatedDate().toJavaDate()));
List<Long> 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<Long> i = activePutCodesWithOutDate.iterator();
while (i.hasNext()) {
Long activePutCode = i.next();
affiliationGroupForms.forEach(affiliationGroupForm -> {
if (activePutCode.equals(affiliationGroupForm.getActivePutCode())) {
affiliationGroupForm.getDefaultAffiliation().setEndDate(null);
i.remove();
}
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit c0081ae

Please sign in to comment.