Skip to content

Commit

Permalink
fix: Invert selfAsserted and validated in sort by source
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielPalafox committed Oct 25, 2023
1 parent b05f46c commit 5bed255
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,8 @@ public class FundingComparators {

private final String TYPE_SORT_KEY = "type";

private final String SOURCE_SORT_KEY = "source";

private String orcid = null;

public FundingComparators() {}

public FundingComparators(String orcid) {
this.orcid = orcid;
}

public Comparator<FundingGroup> getInstance(String key, boolean sortAsc, String orcid) {
Comparator<FundingGroup> comparator = null;
if (DATE_SORT_KEY.equals(key)) {
Expand Down Expand Up @@ -120,7 +112,7 @@ public List<FundingGroup> sortBySource(List<FundingGroup> fundingGroups, boolean
selfAsserted.sort(new FundingComparators().TITLE_COMPARATOR);
validated.sort(new FundingComparators().TITLE_COMPARATOR);

return (sortAsc ? Stream.concat(selfAsserted.stream(), validated.stream()) : Stream.concat(validated.stream(), selfAsserted.stream()))
return (sortAsc ? Stream.concat(validated.stream(), selfAsserted.stream()) : Stream.concat(selfAsserted.stream(), validated.stream()))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ public List<org.orcid.jaxb.model.v3.release.record.summary.WorkGroup> sortBySour
selfAsserted.sort(new TitleComparator());
validated.sort(new TitleComparator());

return sortAsc ? Stream.concat(selfAsserted.stream(), validated.stream())
.collect(Collectors.toList()) : Stream.concat(validated.stream(), selfAsserted.stream())
return (sortAsc ? Stream.concat(validated.stream(), selfAsserted.stream()) : Stream.concat(selfAsserted.stream(), validated.stream()))
.collect(Collectors.toList());
}

Expand All @@ -492,7 +491,7 @@ public List<WorkGroupExtended> sortBySourceExtended(List<WorkGroupExtended> work
selfAsserted.sort(new TitleComparatorWorkGroupExtended());
validated.sort(new TitleComparatorWorkGroupExtended());

return (sortAsc ? Stream.concat(selfAsserted.stream(), validated.stream()) : Stream.concat(validated.stream(), selfAsserted.stream()))
return (sortAsc ? Stream.concat(validated.stream(), selfAsserted.stream()) : Stream.concat(selfAsserted.stream(), validated.stream()))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ public void testGetFundingsJsonSortedBySource() {
List<FundingGroup> fundings = fundingController.getFundingsJson("source", true);
assertNotNull(fundings);
assertEquals(3, fundings.size());
assertEquals("4444-4444-4444-4443", fundings.get(0).getFundings().get(0).getSource());
assertEquals("4444-4444-4444-4441", fundings.get(2).getFundings().get(0).getSource());
assertEquals("4444-4444-4444-4441", fundings.get(0).getFundings().get(0).getSource());
assertEquals("4444-4444-4444-4443", fundings.get(2).getFundings().get(0).getSource());
}

private FundingForm getFundingForm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public void testSourceSort() {
Mockito.when(worksCacheManager.getGroupedWorks(Mockito.anyString())).thenReturn(works);
Page<org.orcid.pojo.grouping.WorkGroup> page = worksPaginator.getWorksPage("orcid", 0, pageSize, false, WorksPaginator.SOURCE_SORT_KEY, false);

assertEquals("APP-5555-5555-5555-5555", page.getGroups().get(0).getWorks().get(0).getSource());
assertEquals("orcid", page.getGroups().get(49).getWorks().get(0).getSource());
assertEquals("orcid", page.getGroups().get(0).getWorks().get(0).getSource());
assertEquals("APP-5555-5555-5555-5555", page.getGroups().get(49).getWorks().get(0).getSource());
}

@Test
Expand Down Expand Up @@ -218,8 +218,8 @@ public void testTitleSortCase() {
Mockito.when(worksCacheManager.getGroupedWorks(Mockito.anyString())).thenReturn(works);
Page<org.orcid.pojo.grouping.WorkGroup> page = worksPaginator.getWorksPage("orcid", 0, pageSize, false, WorksPaginator.SOURCE_SORT_KEY, false);

assertEquals("APP-5555-5555-5555-5555", page.getGroups().get(0).getWorks().get(0).getSource());
assertEquals("orcid", page.getGroups().get(49).getWorks().get(0).getSource());
assertEquals("orcid", page.getGroups().get(0).getWorks().get(0).getSource());
assertEquals("APP-5555-5555-5555-5555", page.getGroups().get(49).getWorks().get(0).getSource());
}

@Test
Expand Down

0 comments on commit 5bed255

Please sign in to comment.