Skip to content

Commit 6e950fb

Browse files
committed
XWIKI-22702: Provide parentType information in EntityReference
* Minor improvment (cherry picked from commit a5f4f86)
1 parent b6efa94 commit 6e950fb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/reference/EntityReference.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Iterator;
2626
import java.util.LinkedList;
2727
import java.util.List;
28+
import java.util.Locale;
2829
import java.util.Map;
2930
import java.util.TreeMap;
3031

@@ -325,7 +326,7 @@ private void setParentTypeParameter(Serializable value)
325326
if (value instanceof EntityType entityType) {
326327
parentType = entityType;
327328
} else {
328-
parentType = EntityType.valueOf(value.toString());
329+
parentType = EntityType.valueOf(value.toString().toUpperCase(Locale.ROOT));
329330
}
330331
if (getType().getAllowedParents().contains(parentType)) {
331332
this.parameters.put(PARENT_TYPE_PARAMETER, parentType);

xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/reference/EntityReferenceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,5 +673,10 @@ void getParentType()
673673
exception = assertThrows(IllegalArgumentException.class, () ->
674674
new EntityReference(SPACE_NAME, EntityType.SPACE, parametersMap2));
675675
assertEquals("No enum constant org.xwiki.model.EntityType.42", exception.getMessage());
676+
677+
// custom type lowercase
678+
spaceReference = new EntityReference(SPACE_NAME, EntityType.SPACE,
679+
Map.of(EntityReference.PARENT_TYPE_PARAMETER, "space"));
680+
assertEquals(EntityType.SPACE, spaceReference.getParentType());
676681
}
677682
}

0 commit comments

Comments
 (0)