From 66442f0c0de6b2b08aae1ef2935c8ca860547655 Mon Sep 17 00:00:00 2001 From: lskublik Date: Mon, 9 Nov 2020 10:22:06 +0100 Subject: [PATCH] fix for ordering of relations list in shopping cart (MID-6677) --- .../gui/api/util/WebComponentUtil.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebComponentUtil.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebComponentUtil.java index 243f0092c67..098c15d07c0 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebComponentUtil.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebComponentUtil.java @@ -2847,6 +2847,29 @@ public static void refreshResourceSchema(@NotNull PrismObject reso public static List getCategoryRelationChoices(AreaCategoryType category, ModelServiceLocator pageBase){ List relationsList = new ArrayList<>(); List defList = getRelationDefinitions(pageBase); + defList.sort(new Comparator() { + @Override + public int compare(RelationDefinitionType rD1, RelationDefinitionType rD2) { + if (rD1 == null || rD2 == null) { + return 0; + } + RelationKindType rK1 = rD1.getDefaultFor() != null ? rD1.getDefaultFor() : getHighestRelationKind(rD1.getKind()); + RelationKindType rK2 = rD2.getDefaultFor() != null ? rD2.getDefaultFor() : getHighestRelationKind(rD2.getKind()); + int int1 = rK1 != null ? rK1.ordinal() : 100; + int int2 = rK2 != null ? rK2.ordinal() : 100; + int compare = Integer.compare(int1, int2); + if (compare == 0){ + if(rD1.getDisplay() == null || rD1.getDisplay().getLabel() == null + || rD2.getDisplay() == null || rD2.getDisplay().getLabel() == null) { + return compare; + } + String display1 = getTranslatedPolyString(rD1.getDisplay().getLabel()); + String display2 = getTranslatedPolyString(rD2.getDisplay().getLabel()); + return String.CASE_INSENSITIVE_ORDER.compare(display1, display2); + } + return compare; + } + }); defList.forEach(def -> { if (def.getCategory() != null && def.getCategory().contains(category)) { relationsList.add(def.getRef()); @@ -2855,6 +2878,16 @@ public static List getCategoryRelationChoices(AreaCategoryType category, return relationsList; } + private static RelationKindType getHighestRelationKind(List kinds) { + RelationKindType ret = null; + for (RelationKindType kind : kinds){ + if (ret == null || ret.ordinal() < kind.ordinal()) { + ret = kind; + } + } + return ret; + } + public static List getAllRelations(ModelServiceLocator pageBase) { List allRelationDefinitions = getRelationDefinitions(pageBase); List allRelationsQName = new ArrayList<>(allRelationDefinitions.size());