Skip to content

Commit

Permalink
#9914 (deegree#195) - apply useRefDataProps to XSElementDeclaration
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoltz committed Aug 6, 2024
1 parent 3cda708 commit 24c2d39
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -818,21 +818,24 @@ private List<Mapping> generateMapping(XSParticle particle, int maxOccurs, Mappin
// }
if (childElMappings.isEmpty()) {
if (particle.getMaxOccursUnbounded()) {
childElMappings.addAll(generateMapping(particle.getTerm(), -1, mc, cycleAnalyser));
childElMappings
.addAll(generateMapping(particle.getTerm(), particle.getMinOccurs(), -1, mc, cycleAnalyser));
}
else {
for (int i = 1; i <= particle.getMaxOccurs(); i++) {
childElMappings.addAll(generateMapping(particle.getTerm(), i, mc, cycleAnalyser));
childElMappings
.addAll(generateMapping(particle.getTerm(), particle.getMinOccurs(), i, mc, cycleAnalyser));
}
}
}
return childElMappings;
}

private List<Mapping> generateMapping(XSTerm term, int occurence, MappingContext mc, CycleAnalyser cycleAnalyser) {
private List<Mapping> generateMapping(XSTerm term, int minOccurs, int occurence, MappingContext mc,
CycleAnalyser cycleAnalyser) {
List<Mapping> mappings = new ArrayList<Mapping>();
if (term instanceof XSElementDeclaration) {
mappings.addAll(generateMapping((XSElementDeclaration) term, occurence, mc, cycleAnalyser));
mappings.addAll(generateMapping((XSElementDeclaration) term, minOccurs, occurence, mc, cycleAnalyser));
}
else if (term instanceof XSModelGroup) {
mappings.addAll(generateMapping((XSModelGroup) term, occurence, mc, cycleAnalyser));
Expand All @@ -843,9 +846,13 @@ else if (term instanceof XSModelGroup) {
return mappings;
}

private List<Mapping> generateMapping(XSElementDeclaration elDecl, int occurence, MappingContext mc,
private List<Mapping> generateMapping(XSElementDeclaration elDecl, int minOccurs, int occurence, MappingContext mc,
CycleAnalyser cycleAnalyser) {
cycleAnalyser.add(elDecl);
if (minOccurs < 1 && !referenceDataHasProperty(cycleAnalyser)) {
cycleAnalyser.remove(elDecl);
return Collections.emptyList();
}
if (referenceDataHasOnlyOne(cycleAnalyser))
occurence = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,49 @@ public void testWithReferenceDataAndConsiderProperties() throws Exception {
assertThat(getPrimitive(mappings, "prop_A3"), is(nullValue()));
}

@Test
public void testWithReferenceDataAndConsiderProperties_xomplexProperties() throws Exception {
GMLAppSchemaReader xsdDecoder = new GMLAppSchemaReader(null, null, schemaForSampleValues);
AppSchema appSchema = xsdDecoder.extractAppSchema();

QName featureTypeNameB = new QName("http://test.de/schema", "FeatureB", "te");
ReferenceData referenceData = mock(ReferenceData.class);
when(referenceData.shouldFeatureTypeMapped(featureTypeNameB)).thenReturn(true);
QName propB1 = new QName("http://test.de/schema", "prop_B1", "te");
when(referenceData.hasZeroOrOneProperty(featureTypeNameB, asPathStep(propB1))).thenReturn(false);
QName propFfeatureA = new QName("http://test.de/schema", "featureA", "te");
when(referenceData.hasZeroOrOneProperty(featureTypeNameB, asPathStep(propFfeatureA))).thenReturn(false);

QName featureTypeNameA = new QName("http://test.de/schema", "FeatureA", "te");
QName propA1 = new QName("http://test.de/schema", "prop_A1", "te");
when(referenceData.shouldFeatureTypeMapped(featureTypeNameA)).thenReturn(true);
when(referenceData.hasZeroOrOneProperty(featureTypeNameA, asPathStep(propA1))).thenReturn(false);

CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326");
GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2);
AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0,
referenceData, true, null);

MappedAppSchema mappedSchema = mapper.getMappedSchema();

Map<QName, FeatureTypeMapping> ftMappings = mappedSchema.getFtMappings();
assertThat(ftMappings.size(), is(2));

FeatureTypeMapping featureB = mappedSchema.getFtMapping(FEATURE_B);
List<Mapping> mappingsB = featureB.getMappings();
assertThat(mappingsB.size(), is(3));
assertThat(getPrimitive(mappingsB, "prop_B1").getJoinedTable(), is(notNullValue()));
assertThat(getPrimitive(mappingsB, "prop_B2").getJoinedTable(), is(nullValue()));
assertThat(getCompound(mappingsB, "featureA").getJoinedTable(), is(notNullValue()));

FeatureTypeMapping featureA = mappedSchema.getFtMapping(FEATURE_A);
List<Mapping> mappingsA = featureA.getMappings();
assertThat(mappingsA.size(), is(3));
assertThat(getPrimitive(mappingsA, "prop_A1").getJoinedTable(), is(notNullValue()));
assertThat(getPrimitive(mappingsA, "prop_A2").getJoinedTable(), is(nullValue()));
assertThat(getCompound(mappingsA, "complex_A4"), is(notNullValue()));
}

@Test
public void testWithReferenceDataAndNilProperties() throws Exception {
GMLAppSchemaReader xsdDecoder = new GMLAppSchemaReader(null, null, schemaWithNilValues);
Expand Down

0 comments on commit 24c2d39

Please sign in to comment.