diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/GmlReferenceData.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/GmlReferenceData.java index f929d75ed2..c34828982d 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/GmlReferenceData.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/GmlReferenceData.java @@ -7,6 +7,7 @@ import org.deegree.cs.exceptions.UnknownCRSException; import org.deegree.feature.Feature; import org.deegree.feature.FeatureCollection; +import org.deegree.feature.GenericFeature; import org.deegree.gml.GMLInputFactory; import org.deegree.gml.GMLStreamReader; import org.deegree.gml.GMLVersion; @@ -16,10 +17,10 @@ import java.io.IOException; import java.net.URL; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import static org.deegree.commons.xml.CommonNamespaces.XSINS; import static org.deegree.commons.xml.CommonNamespaces.XSI_PREFIX; @@ -29,12 +30,36 @@ */ public class GmlReferenceData implements ReferenceData { - private Map> features; + private Map> features = new HashMap<>(); public GmlReferenceData(URL referenceData) throws IOException, XMLStreamException, UnknownCRSException { GMLStreamReader gmlStreamReader = GMLInputFactory.createGMLStreamReader(GMLVersion.GML_32, referenceData); FeatureCollection featureCollection = gmlStreamReader.readFeatureCollection(); - this.features = featureCollection.stream().collect(Collectors.groupingBy(Feature::getName)); + addFeatures(featureCollection); + } + + private void addFeatures(FeatureCollection featureCollection) { + Iterator iterator = featureCollection.iterator(); + while (iterator.hasNext()) { + Feature feature = iterator.next(); + addFeature(feature); + List properties = feature.getProperties(); + for (Property prop : properties) { + // add inline features + if (prop.getValue() instanceof GenericFeature) { + Feature inlineFeature = (Feature) prop.getValue(); + addFeature(inlineFeature); + } + } + } + } + + private void addFeature(Feature feature) { + QName name = feature.getName(); + if (!features.containsKey(name)) { + features.put(name, new ArrayList<>()); + } + features.get(name).add(feature); } @Override diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/mapper/GmlReferenceDataTest.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/mapper/GmlReferenceDataTest.java index 75036c73c0..cdee20e238 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/mapper/GmlReferenceDataTest.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/mapper/GmlReferenceDataTest.java @@ -138,7 +138,7 @@ public void test_Reference_1() throws Exception { boolean hasMaxOneA3 = gmlReferenceData.hasZeroOrOneProperty(FEATURETYPE_A_NAME, Collections.singletonList(PROP_A3_NAME)); - assertThat(hasMaxOneA3, is(false)); + assertThat(hasMaxOneA3, is(true)); } @Test @@ -235,4 +235,21 @@ public void test_Inspire_isPropertyNilled() throws Exception { assertThat(propertyIsNilledStatus, is(true)); } + @Test + public void test_Inspire_shouldFeatureTypeMapped_withInlinedFeture() throws Exception { + URL resource = getClass().getResource("data/Inspire-Adress_withInlineFeature.xml"); + GmlReferenceData gmlReferenceData = new GmlReferenceData(resource); + + QName AdressFeatureTypeName = new QName("http://inspire.ec.europa.eu/schemas/ad/4.0", "Address", "ad"); + QName AdminUnitNameFeatureTypeName = new QName("http://inspire.ec.europa.eu/schemas/ad/4.0", "AdminUnitName", + "ad"); + + boolean explicitFeatureTypeShouldBeMapped = gmlReferenceData.shouldFeatureTypeMapped(AdressFeatureTypeName); + assertThat(explicitFeatureTypeShouldBeMapped, is(true)); + + boolean referencedFeatureTypeShouldBeMapped = gmlReferenceData + .shouldFeatureTypeMapped(AdminUnitNameFeatureTypeName); + assertThat(referencedFeatureTypeShouldBeMapped, is(true)); + } + } \ No newline at end of file diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/resources/org/deegree/feature/persistence/sql/mapper/data/Inspire-Adress_withInlineFeature.xml b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/resources/org/deegree/feature/persistence/sql/mapper/data/Inspire-Adress_withInlineFeature.xml new file mode 100644 index 0000000000..f45d6d78a7 --- /dev/null +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/resources/org/deegree/feature/persistence/sql/mapper/data/Inspire-Adress_withInlineFeature.xml @@ -0,0 +1,70 @@ + + + + + + + Address_1 + https://registry.gdi-de.org/id + + + + + + + + 49.119752 7.046397 + + + + + true + + + + + + + + 1 + + + + + + + + + + + + + + + deu + + + + + + + Test + + + + + + + + + + + + + \ No newline at end of file