Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance SqlFeatureStoreConfigCreator to apply useRefDataProps to complex xml elements (3.6) #1728

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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