Skip to content

Commit

Permalink
fix: Update comparator class to not be static so we can assign an orc…
Browse files Browse the repository at this point in the history
…id id every time the comparator class its generated
  • Loading branch information
DanielPalafox committed Oct 2, 2023
1 parent 57afecf commit d99b236
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,8 @@ public static boolean isSelfAsserted(Source source, String orcid) {
public static boolean isSelfAsserted(AffiliationForm af, String orcid) {
return (orcid.equals(af.getSource()) || orcid.equals(af.getAssertionOriginOrcid()));
}

public static boolean isSelfAsserted(String source, String orcid) {
return !orcid.equals(source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@

public class FundingComparators {

private static final String TITLE_SORT_KEY = "title";
private final String TITLE_SORT_KEY = "title";

private static final String DATE_SORT_KEY = "date";
private final String DATE_SORT_KEY = "date";

private static final String TYPE_SORT_KEY = "type";
private final String TYPE_SORT_KEY = "type";

private static final String SOURCE_SORT_KEY = "source";
private final String SOURCE_SORT_KEY = "source";

private static String orcid = null;
private String orcid = null;

public static Comparator<FundingGroup> getInstance(String key, boolean sortAsc, String orcid) {
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)) {
comparator = FundingComparators.DATE_COMPARATOR;
comparator = new FundingComparators().DATE_COMPARATOR;
} else if (TITLE_SORT_KEY.equals(key)) {
comparator = FundingComparators.TITLE_COMPARATOR;
comparator = new FundingComparators().TITLE_COMPARATOR;
} else if (TYPE_SORT_KEY.equals(key)) {
comparator = FundingComparators.TYPE_COMPARATOR;
comparator = new FundingComparators().TYPE_COMPARATOR;
} else if (SOURCE_SORT_KEY.equals(key)) {
FundingComparators.orcid = orcid;
comparator = FundingComparators.SOURCE_COMPARATOR;
comparator = new FundingComparators(orcid).SOURCE_COMPARATOR;
}

if (sortAsc) {
Expand All @@ -39,7 +44,7 @@ public static Comparator<FundingGroup> getInstance(String key, boolean sortAsc,
}
}

public static Comparator<FundingGroup> TITLE_COMPARATOR = (g1, g2) -> {
public Comparator<FundingGroup> TITLE_COMPARATOR = (g1, g2) -> {
if (g1.getTitle() == null && g2.getTitle() == null) {
return 0;
}
Expand All @@ -53,7 +58,7 @@ public static Comparator<FundingGroup> getInstance(String key, boolean sortAsc,
return g1.getTitle().toLowerCase().compareTo(g2.getTitle().toLowerCase());
};

public static Comparator<FundingGroup> TYPE_COMPARATOR = (g1, g2) -> {
public Comparator<FundingGroup> TYPE_COMPARATOR = (g1, g2) -> {
FundingForm f1 = g1.getFundings().get(0);
FundingForm f2 = g2.getFundings().get(0);

Expand All @@ -71,7 +76,7 @@ public static Comparator<FundingGroup> getInstance(String key, boolean sortAsc,
return f1.getFundingType().getValue().compareTo(f2.getFundingType().getValue());
};

public static Comparator<FundingGroup> END_DATE_COMPARATOR = (g1, g2) -> {
public Comparator<FundingGroup> END_DATE_COMPARATOR = (g1, g2) -> {
if (g1.getEndDate() == null && g2.getEndDate() == null)
return TITLE_COMPARATOR.compare(g1, g2) * -1; // reverse secondary order;;
//Null = to present and should sort first
Expand All @@ -85,7 +90,7 @@ public static Comparator<FundingGroup> getInstance(String key, boolean sortAsc,
return g1.getEndDate().compareTo(g2.getEndDate());
};

public static Comparator<FundingGroup> DATE_COMPARATOR = (g1, g2) -> {
public Comparator<FundingGroup> DATE_COMPARATOR = (g1, g2) -> {
if (g1.getStartDate() == null && g2.getStartDate() == null) {
return TITLE_COMPARATOR.compare(g1, g2) * -1; // reverse secondary order;;
}
Expand All @@ -102,9 +107,9 @@ public static Comparator<FundingGroup> getInstance(String key, boolean sortAsc,
return g1.getStartDate().compareTo(g2.getStartDate());
};

public static Comparator<FundingGroup> SOURCE_COMPARATOR = (g1, g2) -> Boolean.compare(isSelfAsserted(g1), isSelfAsserted(g2));
public Comparator<FundingGroup> SOURCE_COMPARATOR = (g1, g2) -> Boolean.compare(isSelfAsserted(g1), isSelfAsserted(g2));

private static boolean isSelfAsserted(FundingGroup fundingGroup) {
return SourceUtils.isSelfAsserted(fundingGroup.getSource(), FundingComparators.orcid);
private boolean isSelfAsserted(FundingGroup fundingGroup) {
return SourceUtils.isSelfAsserted(fundingGroup.getSource(), orcid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ FundingForm getFunding() {
fundingGroups.add(fundingGroup);
}

fundingGroups.sort(FundingComparators.getInstance(sort, sortAsc, getEffectiveUserOrcid()));
fundingGroups.sort(new FundingComparators().getInstance(sort, sortAsc, getEffectiveUserOrcid()));
return fundingGroups;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private boolean isRecordReadyForIndexing(ProfileEntity profile) {
fundingGroups.add(fundingGroup);
}

fundingGroups.sort(FundingComparators.getInstance(sort, sortAsc, orcid));
fundingGroups.sort(new FundingComparators().getInstance(sort, sortAsc, orcid));
return fundingGroups;
}

Expand Down

0 comments on commit d99b236

Please sign in to comment.