Skip to content

Commit

Permalink
#18 - limit generated mapping to feature types in the refernce data
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoltz committed Nov 25, 2021
1 parent 7a0eb3e commit 3068a96
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static org.apache.xerces.xs.XSComplexTypeDefinition.CONTENTTYPE_ELEMENT;
import static org.apache.xerces.xs.XSComplexTypeDefinition.CONTENTTYPE_EMPTY;
Expand Down Expand Up @@ -236,7 +238,6 @@ public AppSchemaMapper( AppSchema appSchema, boolean createBlobMapping, boolean
Map<String, String> prefixToNs = appSchema.getNamespaceBindings();
GMLSchemaInfoSet xsModel = appSchema.getGMLSchema();

FeatureTypeMapping[] ftMappings = null;

nsToPrefix = new HashMap<String, String>();
Iterator<String> nsIter = CommonNamespaces.getNamespaceContext().getNamespaceURIs();
Expand All @@ -247,6 +248,7 @@ public AppSchemaMapper( AppSchema appSchema, boolean createBlobMapping, boolean
nsToPrefix.putAll( xsModel.getNamespacePrefixes() );

mcManager = new MappingContextManager( nsToPrefix, maxLength, usePrefixedSQLIdentifiers );
FeatureTypeMapping[] ftMappings = null;
if ( createRelationalMapping ) {
ftMappings = generateFtMappings( fts );
}
Expand Down Expand Up @@ -283,11 +285,11 @@ private BBoxTableMapping generateBBoxMapping() {
}

private FeatureTypeMapping[] generateFtMappings( FeatureType[] fts ) {
FeatureTypeMapping[] ftMappings = new FeatureTypeMapping[fts.length];
for ( int i = 0; i < fts.length; i++ ) {
ftMappings[i] = generateFtMapping( fts[i] );
}
return ftMappings;
return Arrays.stream( fts ).filter(
ft -> referenceData != null ?
referenceData.shouldFeatureTypeMapped( ft.getName() ) :
true ).map(
ft -> generateFtMapping( ft ) ).toArray( FeatureTypeMapping[]::new );
}

private FeatureTypeMapping generateFtMapping( FeatureType ft ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.deegree.cs.exceptions.UnknownCRSException;
import org.deegree.feature.Feature;
import org.deegree.feature.FeatureCollection;
import org.deegree.feature.types.FeatureType;
import org.deegree.gml.GMLInputFactory;
import org.deegree.gml.GMLStreamReader;
import org.deegree.gml.GMLVersion;
Expand Down Expand Up @@ -47,6 +48,11 @@ public boolean hasZeroOrOneProperty( QName featureTypeName, List<QName> xpath )
return false;
}

@Override
public boolean shouldFeatureTypeMapped( QName featureTypeName ) {
return features.containsKey( featureTypeName );
}

private boolean hasMoreThanOne( Feature feature, List<QName> xpath ) {
if ( xpath.isEmpty() )
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ public interface ReferenceData {
*/
boolean hasZeroOrOneProperty( QName featureTypeName, List<QName> xpath );

/**
* @param featureTypeName
* the name of the feature type, never <code>null</code>
* @return <code>true</code> if the feature type with this name should be mapped, <code>false</code> otherwise
*/
boolean shouldFeatureTypeMapped( QName featureTypeName );

}
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ public void testWithReferenceData()

QName featureTypeName = new QName( "http://test.de/schema", "FeatureA", "te" );
ReferenceData referenceData = mock( ReferenceData.class );
when( referenceData.shouldFeatureTypeMapped( featureTypeName ) ).thenReturn( true );
QName propA1 = new QName( "http://test.de/schema", "prop_A1", "te" );
when( referenceData.hasZeroOrOneProperty( featureTypeName, Collections.singletonList( propA1 ) ) ).thenReturn( false );
QName propA3 = new QName( "http://test.de/schema", "prop_A3", "te" );
Expand All @@ -506,7 +507,7 @@ public void testWithReferenceData()
MappedAppSchema mappedSchema = mapper.getMappedSchema();

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

FeatureTypeMapping featureA = mappedSchema.getFtMapping( FEATURE_A );
List<Mapping> mappings = featureA.getMappings();
Expand All @@ -524,6 +525,7 @@ public void testWithReferenceData_ComplexData_ComplexN()

QName featureTypeName = new QName( "http://test.de/schema", "FeatureA", "te" );
ReferenceData referenceData = mock( ReferenceData.class );
when( referenceData.shouldFeatureTypeMapped( featureTypeName ) ).thenReturn( true );
QName propA1 = new QName( "http://test.de/schema", "prop_A1", "te" );
when( referenceData.hasZeroOrOneProperty( featureTypeName, Collections.singletonList( propA1 ) ) ).thenReturn( false );
QName propA3 = new QName( "http://test.de/schema", "prop_A3", "te" );
Expand All @@ -546,7 +548,7 @@ public void testWithReferenceData_ComplexData_ComplexN()
MappedAppSchema mappedSchema = mapper.getMappedSchema();

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

FeatureTypeMapping feature = mappedSchema.getFtMapping( FEATURE_A );
List<Mapping> mappings = feature.getMappings();
Expand All @@ -570,6 +572,7 @@ public void testWithReferenceData_ComplexData_Complex1()

QName featureTypeName = new QName( "http://test.de/schema", "FeatureA", "te" );
ReferenceData referenceData = mock( ReferenceData.class );
when( referenceData.shouldFeatureTypeMapped( featureTypeName ) ).thenReturn( true );
QName propA1 = new QName( "http://test.de/schema", "prop_A1", "te" );
when( referenceData.hasZeroOrOneProperty( featureTypeName, Collections.singletonList( propA1 ) ) ).thenReturn( false );
QName propA3 = new QName( "http://test.de/schema", "prop_A3", "te" );
Expand All @@ -592,7 +595,7 @@ public void testWithReferenceData_ComplexData_Complex1()
MappedAppSchema mappedSchema = mapper.getMappedSchema();

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

FeatureTypeMapping feature = mappedSchema.getFtMapping( FEATURE_A );
List<Mapping> mappings = feature.getMappings();
Expand All @@ -616,6 +619,7 @@ public void testWithReferenceData_ReferencedFeature_RefN()

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, Collections.singletonList( propB1 ) ) ).thenReturn( false );
QName propB3 = new QName( "http://test.de/schema", "prop_B3", "te" );
Expand All @@ -625,6 +629,7 @@ public void testWithReferenceData_ReferencedFeature_RefN()

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, Collections.singletonList( propA1 ) ) ).thenReturn( false );
QName propA3 = new QName( "http://test.de/schema", "prop_A3", "te" );
when( referenceData.hasZeroOrOneProperty( featureTypeNameA, Collections.singletonList( propA3 ) ) ).thenReturn( true );
Expand Down Expand Up @@ -662,6 +667,7 @@ public void testWithReferenceData_ReferencedFeature_Ref1()

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, Collections.singletonList( propB1 ) ) ).thenReturn( false );
QName propB3 = new QName( "http://test.de/schema", "prop_B3", "te" );
Expand All @@ -670,6 +676,7 @@ public void testWithReferenceData_ReferencedFeature_Ref1()
when( referenceData.hasZeroOrOneProperty( featureTypeNameB, Collections.singletonList( propFfeatureA ) ) ).thenReturn( true );

QName featureTypeNameA = new QName( "http://test.de/schema", "FeatureA", "te" );
when( referenceData.shouldFeatureTypeMapped( featureTypeNameA ) ).thenReturn( true );
QName propA1 = new QName( "http://test.de/schema", "prop_A1", "te" );
when( referenceData.hasZeroOrOneProperty( featureTypeNameA, Collections.singletonList( propA1 ) ) ).thenReturn( false );
QName propA3 = new QName( "http://test.de/schema", "prop_A3", "te" );
Expand Down

0 comments on commit 3068a96

Please sign in to comment.