From a65a1fc4995c6c826e93571135fefda55dd383ac Mon Sep 17 00:00:00 2001 From: Daniel Palafox Date: Mon, 2 Oct 2023 18:10:57 -0500 Subject: [PATCH] fix: Update comparator class to not be static so we can assign an orcid id every time the comparator class its generated --- .../org/orcid/core/utils/v3/SourceUtils.java | 4 ++ .../v3/activities/FundingComparators.java | 41 +++++++++++-------- .../web/controllers/FundingsController.java | 2 +- .../controllers/PublicProfileController.java | 2 +- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java b/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java index d93db88fcb3..99f95e4bd85 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/v3/SourceUtils.java @@ -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); + } } diff --git a/orcid-core/src/main/java/org/orcid/core/utils/v3/activities/FundingComparators.java b/orcid-core/src/main/java/org/orcid/core/utils/v3/activities/FundingComparators.java index 7a99d715356..89a4a2217e6 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/v3/activities/FundingComparators.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/v3/activities/FundingComparators.java @@ -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 getInstance(String key, boolean sortAsc, String orcid) { + public FundingComparators() {} + + public FundingComparators(String orcid) { + this.orcid = orcid; + } + + public Comparator getInstance(String key, boolean sortAsc, String orcid) { Comparator 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) { @@ -39,7 +44,7 @@ public static Comparator getInstance(String key, boolean sortAsc, } } - public static Comparator TITLE_COMPARATOR = (g1, g2) -> { + public Comparator TITLE_COMPARATOR = (g1, g2) -> { if (g1.getTitle() == null && g2.getTitle() == null) { return 0; } @@ -53,7 +58,7 @@ public static Comparator getInstance(String key, boolean sortAsc, return g1.getTitle().toLowerCase().compareTo(g2.getTitle().toLowerCase()); }; - public static Comparator TYPE_COMPARATOR = (g1, g2) -> { + public Comparator TYPE_COMPARATOR = (g1, g2) -> { FundingForm f1 = g1.getFundings().get(0); FundingForm f2 = g2.getFundings().get(0); @@ -71,7 +76,7 @@ public static Comparator getInstance(String key, boolean sortAsc, return f1.getFundingType().getValue().compareTo(f2.getFundingType().getValue()); }; - public static Comparator END_DATE_COMPARATOR = (g1, g2) -> { + public Comparator 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 @@ -85,7 +90,7 @@ public static Comparator getInstance(String key, boolean sortAsc, return g1.getEndDate().compareTo(g2.getEndDate()); }; - public static Comparator DATE_COMPARATOR = (g1, g2) -> { + public Comparator DATE_COMPARATOR = (g1, g2) -> { if (g1.getStartDate() == null && g2.getStartDate() == null) { return TITLE_COMPARATOR.compare(g1, g2) * -1; // reverse secondary order;; } @@ -102,9 +107,9 @@ public static Comparator getInstance(String key, boolean sortAsc, return g1.getStartDate().compareTo(g2.getStartDate()); }; - public static Comparator SOURCE_COMPARATOR = (g1, g2) -> Boolean.compare(isSelfAsserted(g1), isSelfAsserted(g2)); + public Comparator 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); } } diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/FundingsController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/FundingsController.java index 63b9dd6b6dc..711f65e75eb 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/FundingsController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/FundingsController.java @@ -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; } diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicProfileController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicProfileController.java index 0af6121d717..53144913727 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicProfileController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicProfileController.java @@ -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; }