From a5f4f86ce0368f5d7a1b1927f3d3e13ebbc6db6f Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Tue, 3 Dec 2024 14:30:32 +0100 Subject: [PATCH] XWIKI-22702: Provide parentType information in EntityReference * Minor improvment --- .../main/java/org/xwiki/model/reference/EntityReference.java | 3 ++- .../java/org/xwiki/model/reference/EntityReferenceTest.java | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/reference/EntityReference.java b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/reference/EntityReference.java index c5927e8692e..edd265e4964 100644 --- a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/reference/EntityReference.java +++ b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/reference/EntityReference.java @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.TreeMap; @@ -325,7 +326,7 @@ private void setParentTypeParameter(Serializable value) if (value instanceof EntityType entityType) { parentType = entityType; } else { - parentType = EntityType.valueOf(value.toString()); + parentType = EntityType.valueOf(value.toString().toUpperCase(Locale.ROOT)); } if (getType().getAllowedParents().contains(parentType)) { this.parameters.put(PARENT_TYPE_PARAMETER, parentType); diff --git a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/reference/EntityReferenceTest.java b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/reference/EntityReferenceTest.java index 9d04c85afc0..5d3d1dccd6c 100644 --- a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/reference/EntityReferenceTest.java +++ b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/reference/EntityReferenceTest.java @@ -673,5 +673,10 @@ void getParentType() exception = assertThrows(IllegalArgumentException.class, () -> new EntityReference(SPACE_NAME, EntityType.SPACE, parametersMap2)); assertEquals("No enum constant org.xwiki.model.EntityType.42", exception.getMessage()); + + // custom type lowercase + spaceReference = new EntityReference(SPACE_NAME, EntityType.SPACE, + Map.of(EntityReference.PARENT_TYPE_PARAMETER, "space")); + assertEquals(EntityType.SPACE, spaceReference.getParentType()); } }