Skip to content

Commit

Permalink
fix for ordering of relations list in shopping cart (MID-6677)
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Nov 9, 2020
1 parent fef8dad commit 66442f0
Showing 1 changed file with 33 additions and 0 deletions.
Expand Up @@ -2847,6 +2847,29 @@ public static void refreshResourceSchema(@NotNull PrismObject<ResourceType> reso
public static List<QName> getCategoryRelationChoices(AreaCategoryType category, ModelServiceLocator pageBase){
List<QName> relationsList = new ArrayList<>();
List<RelationDefinitionType> defList = getRelationDefinitions(pageBase);
defList.sort(new Comparator<RelationDefinitionType>() {
@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());
Expand All @@ -2855,6 +2878,16 @@ public static List<QName> getCategoryRelationChoices(AreaCategoryType category,
return relationsList;
}

private static RelationKindType getHighestRelationKind(List<RelationKindType> kinds) {
RelationKindType ret = null;
for (RelationKindType kind : kinds){
if (ret == null || ret.ordinal() < kind.ordinal()) {
ret = kind;
}
}
return ret;
}

public static List<QName> getAllRelations(ModelServiceLocator pageBase) {
List<RelationDefinitionType> allRelationDefinitions = getRelationDefinitions(pageBase);
List<QName> allRelationsQName = new ArrayList<>(allRelationDefinitions.size());
Expand Down

0 comments on commit 66442f0

Please sign in to comment.