Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Sort affiliations by created date #6870

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testFindDisambuguatedOrgsWithIncorrectPopularity() {
assertEquals(1, results.size());
Pair<Long, Integer> pair = results.get(0);
assertEquals(1, pair.getLeft().longValue());
assertEquals(48, pair.getRight().intValue());
assertEquals(50, pair.getRight().intValue());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public void testfindById() {
public void testFindAll() {
List<ProfileEntity> all = profileDao.getAll();
assertNotNull(all);
assertEquals(22, all.size());
assertEquals(23, all.size());
Long count = profileDao.countAll();
assertEquals(Long.valueOf(22), count);
assertEquals(Long.valueOf(23), count);
}

@Test
Expand All @@ -127,7 +127,7 @@ public void testInsert() throws DataSetException {
assertEquals(profile.getDateCreated(), profile.getLastModified());

Long count = profileDao.countAll();
assertEquals(Long.valueOf(23), count);
assertEquals(Long.valueOf(24), count);
profile = profileDao.find(newOrcid);

assertNotNull(profile);
Expand All @@ -151,7 +151,7 @@ public void testInsertWithPrimaryInstitutions() throws DataSetException {
assertNotNull(profile.getLastModified());

Long count = profileDao.countAll();
assertEquals(Long.valueOf(23), count);
assertEquals(Long.valueOf(24), count);
profile = profileDao.find(newOrcid);

assertNotNull(profile);
Expand All @@ -177,7 +177,7 @@ public void testInsertWithInstitutionDepartments() throws DataSetException {
assertNotNull(retrievedProfile.getLastModified());

Long count = profileDao.countAll();
assertEquals(Long.valueOf(23), count);
assertEquals(Long.valueOf(24), count);
}

@Test
Expand Down Expand Up @@ -278,12 +278,12 @@ public void testUpdateIndexingStatus() {
public void testGetConfirmedProfileCount() {
String orcid = "4444-4444-4444-4446";
Long confirmedProfileCount = profileDao.getConfirmedProfileCount();
assertEquals(Long.valueOf(22), confirmedProfileCount);
assertEquals(Long.valueOf(23), confirmedProfileCount);
ProfileEntity profileEntity = profileDao.find(orcid);
profileEntity.setCompletedDate(null);
profileDao.persist(profileEntity);
confirmedProfileCount = profileDao.getConfirmedProfileCount();
assertEquals(Long.valueOf(21), confirmedProfileCount);
assertEquals(Long.valueOf(22), confirmedProfileCount);
}

@Test
Expand Down
100 changes: 99 additions & 1 deletion orcid-test/src/main/resources/data/OrgAffiliationEntityData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1142,4 +1142,102 @@
visibility="PRIVATE"
client_source_id="APP-5555555555555555"
/>
</dataset>

<org_affiliation_relation
id="1007"
org_id="2"
orcid="0000-0000-0000-0008"
org_affiliation_relation_role="SERVICE"
org_affiliation_relation_title="PUBLIC"
department="PUBLIC Department"
date_created="2023-01-05 15:31:00.00"
last_modified="2023-01-05 15:31:00.00"
start_year="2023"
start_month="01"
start_day="05"
end_year="2030"
end_month="01"
end_day="01"
visibility="PUBLIC"
client_source_id="APP-5555555555555555"
display_index="1"
/>

<org_affiliation_relation
id="1008"
org_id="2"
orcid="0000-0000-0000-0008"
org_affiliation_relation_role="MEMBERSHIP"
org_affiliation_relation_title="PUBLIC"
department="PUBLIC Department"
date_created="2023-01-04 15:31:00.00"
last_modified="2023-01-04 15:31:00.00"
start_year="2023"
start_month="01"
start_day="04"
end_year="2030"
end_month="01"
end_day="01"
visibility="PUBLIC"
client_source_id="APP-5555555555555555"
display_index="1"
/>

<org_affiliation_relation
id="1009"
org_id="2"
orcid="0000-0000-0000-0008"
org_affiliation_relation_role="INVITED_POSITION"
org_affiliation_relation_title="PUBLIC"
department="PUBLIC Department"
date_created="2023-01-03 15:31:00.00"
last_modified="2023-01-03 15:31:00.00"
start_year="2023"
start_month="01"
start_day="03"
end_year="2030"
end_month="01"
end_day="01"
visibility="PUBLIC"
client_source_id="APP-5555555555555555"
display_index="1"
/>

<org_affiliation_relation
id="1010"
org_id="1"
orcid="0000-0000-0000-0008"
org_affiliation_relation_role="MEMBERSHIP"
org_affiliation_relation_title="PUBLIC"
department="PUBLIC Department"
date_created="2023-01-02 15:31:00.00"
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"
/>

<org_affiliation_relation
id="1011"
org_id="1"
orcid="0000-0000-0000-0008"
org_affiliation_relation_role="INVITED_POSITION"
org_affiliation_relation_title="PUBLIC"
department="SELF PUBLIC Department"
date_created="2023-01-01 15:31:00.00"
last_modified="2023-01-01 15:31:00.00"
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"
/>
</dataset>
27 changes: 26 additions & 1 deletion orcid-test/src/main/resources/data/ProfileEntityData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,26 @@
using_2fa="true"
/>

<profile
orcid="0000-0000-0000-0008"
creation_method="API"
completed_date="2023-03-29 15:31:00.00"
date_created="2023-03-29 15:31:00.00"
submission_date="2023-03-29 15:31:00.00"
last_indexed_date="2023-03-29 15:31:00.00"
last_modified="2023-03-29 15:31:00.00"
is_selectable_sponsor="false"
encrypted_password="e9adO9I4UpBwqI5tGR+qDodvAZ7mlcISn+T+kyqXPf2Z6PPevg7JijqYr6KGO8VOskOYqVOEK2FEDwebxWKGDrV/TQ9gRfKWZlzxssxsOnA="
activities_visibility_default="PUBLIC"
indexing_status="DONE"
orcid_type="USER"
claimed="true"
reviewed="true"
record_locked="false"
using_2fa="false"
secret_for_2fa="secret"
/>

<granted_authority
authority="USER_ROLE"
orcid="4444-4444-4444-4441"
Expand Down Expand Up @@ -496,6 +516,11 @@
orcid="0000-0000-0000-0007"
/>

<granted_authority
authority="USER_ROLE"
orcid="0000-0000-0000-0008"
/>

<external_identifier
id="1"
external_id_reference="d3clan"
Expand Down Expand Up @@ -2247,4 +2272,4 @@
last_modified="2020-01-01 15:00:00.00"
date_created="2020-01-01 15:00:00.00"
/>
</dataset>
</dataset>
15 changes: 13 additions & 2 deletions orcid-test/src/main/resources/data/RecordNameEntityData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,16 @@
given_names="Given names"
family_name="Family name"
visibility="PRIVATE"
/>
</dataset>
/>

<record_name
id="19"
date_created="2023-01-01 00:00:00.00"
last_modified="2023-01-01 00:00:00.00"
orcid="0000-0000-0000-0008"
credit_name="Credit Name"
given_names="Given Names"
family_name="Family Name"
visibility="PUBLIC"
/>
</dataset>
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -355,7 +353,7 @@ PublicRecord getRecord(String orcid) {
return recordSummary;
} else {
recordSummary = getSummary(orcid);
recordSummary.setStatus("active");
recordSummary.setStatus("active");
return recordSummary;
}
}
Expand Down Expand Up @@ -393,8 +391,9 @@ RecordSummary getSummary(String orcid) {

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

if (groupedEmployments.size() > 0) {
sortAffiliationsByCreatedDate(groupedEmployments);

if (groupedEmployments.size() > 0) {
Stream<AffiliationGroupForm> employmentsList = groupedEmployments.stream().limit(3);
employmentsList.forEach(e -> employmentAffiliations.add(AffiliationSummary.valueOf(e.getDefaultAffiliation(), orcid, "employment")));
}
Expand Down Expand Up @@ -486,15 +485,16 @@ RecordSummary getSummary(String orcid) {
private List<AffiliationSummary> retrieveProfessionalActivities(AffiliationGroupContainer groupedAffiliations, String orcid) {
List<AffiliationSummary> professionalActivities = new ArrayList<>();

List<AffiliationGroupForm> membershipGroupedAffiliations = groupedAffiliations.getAffiliationGroups().get(AffiliationType.MEMBERSHIP);
List<AffiliationGroupForm> serviceGroupedAffiliations = groupedAffiliations.getAffiliationGroups().get(AffiliationType.SERVICE);
List<AffiliationGroupForm> invitedPositionGroupedAffiliations = groupedAffiliations.getAffiliationGroups().get(AffiliationType.INVITED_POSITION);
List<AffiliationGroupForm> distinctionGroupedAffiliations = groupedAffiliations.getAffiliationGroups().get(AffiliationType.DISTINCTION);
List<AffiliationGroupForm> 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;
}
Expand All @@ -508,4 +508,9 @@ private String formatDate(XMLGregorianCalendar xmlGregorianCalendar) {
private Long getLastModifiedTime(String orcid) {
return profileEntityManager.getLastModified(orcid);
}

private void sortAffiliationsByCreatedDate(List<AffiliationGroupForm> affiliationGroupForms) {
affiliationGroupForms.sort(Comparator.comparing(a -> a.getDefaultAffiliation().getCreatedDate().toJavaDate()));
Collections.reverse(affiliationGroupForms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,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());
}
}