From 58696f74180bbe82e9eccc6b07ed44b55fd83576 Mon Sep 17 00:00:00 2001 From: Hylke van der Schaaf Date: Sat, 24 Feb 2024 20:42:55 +0100 Subject: [PATCH] Fixed deep select for complex properties in GeoJSON and CSV output --- CHANGELOG.md | 1 + .../frostserver/property/EntityPropertyCustomSelect.java | 7 +++++-- .../iosb/ilt/frostserver/property/ComplexValue.java | 0 .../iosb/ilt/frostserver/util/CollectionsHelper.java | 7 +++++++ 4 files changed, 13 insertions(+), 2 deletions(-) rename {FROST-Server.Core.Model => FROST-Server.Util}/src/main/java/de/fraunhofer/iosb/ilt/frostserver/property/ComplexValue.java (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e955299dc..c027e31df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ **Internal changes & Bugfixes** * Improved generated queries when fetching entities over a one-to-many relation. +* Fixed deep select for complex properties in GeoJSON and CSV output. ## Release version 2.3.0 diff --git a/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/property/EntityPropertyCustomSelect.java b/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/property/EntityPropertyCustomSelect.java index b90416a22..f01d2d59b 100644 --- a/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/property/EntityPropertyCustomSelect.java +++ b/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/property/EntityPropertyCustomSelect.java @@ -78,8 +78,11 @@ public Object getFrom(Entity entity) { entityProperty = entity.getEntityType().getEntityProperty(entityPropertyName); } Object baseProperty = entity.getProperty(entityProperty); - if (baseProperty instanceof Map) { - return CollectionsHelper.getFrom((Map) baseProperty, subPath); + if (baseProperty instanceof Map map) { + return CollectionsHelper.getFrom(map, subPath); + } + if (baseProperty instanceof ComplexValue cv) { + return CollectionsHelper.getFrom(cv, subPath); } return null; } diff --git a/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/property/ComplexValue.java b/FROST-Server.Util/src/main/java/de/fraunhofer/iosb/ilt/frostserver/property/ComplexValue.java similarity index 100% rename from FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/property/ComplexValue.java rename to FROST-Server.Util/src/main/java/de/fraunhofer/iosb/ilt/frostserver/property/ComplexValue.java diff --git a/FROST-Server.Util/src/main/java/de/fraunhofer/iosb/ilt/frostserver/util/CollectionsHelper.java b/FROST-Server.Util/src/main/java/de/fraunhofer/iosb/ilt/frostserver/util/CollectionsHelper.java index 2b1ad1c4c..f7f884742 100644 --- a/FROST-Server.Util/src/main/java/de/fraunhofer/iosb/ilt/frostserver/util/CollectionsHelper.java +++ b/FROST-Server.Util/src/main/java/de/fraunhofer/iosb/ilt/frostserver/util/CollectionsHelper.java @@ -17,6 +17,7 @@ */ package de.fraunhofer.iosb.ilt.frostserver.util; +import de.fraunhofer.iosb.ilt.frostserver.property.ComplexValue; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -72,6 +73,10 @@ public static Object getFrom(final Map map, final List p return getFrom((Object) map, path); } + public static Object getFrom(final ComplexValue cv, final List path) { + return getFrom((Object) cv, path); + } + private static Object getFrom(final Object mapOrList, final List path) { Object currentEntry = mapOrList; int last = path.size(); @@ -79,6 +84,8 @@ private static Object getFrom(final Object mapOrList, final List path) { String key = path.get(idx); if (currentEntry instanceof Map map) { currentEntry = map.get(key); + } else if (currentEntry instanceof ComplexValue cv) { + currentEntry = cv.get(key); } else if (currentEntry instanceof List list) { try { currentEntry = list.get(Integer.parseInt(key));