use of ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType in project ddf by codice.
the class TestWfsSource method getWfsSource.
public WfsSource getWfsSource(final String schema, final FilterCapabilities filterCapabilities, final String srsName, final int numFeatures, final boolean throwExceptionOnDescribeFeatureType, boolean prefix, int numReturned) throws WfsException, SecurityServiceException {
mockFactory = mock(SecureCxfClientFactory.class);
when(mockFactory.getClient()).thenReturn(mockWfs);
// GetCapabilities Response
when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilites);
when(mockFeatureCollection.getMembers()).thenAnswer(new Answer<List<Metacard>>() {
@Override
public List<Metacard> answer(InvocationOnMock invocation) {
// Create as many metacards as there are features
List<Metacard> metacards = new ArrayList<Metacard>(numFeatures);
for (int i = 0; i < numFeatures; i++) {
MetacardImpl mc = new MetacardImpl();
mc.setId("ID_" + String.valueOf(i + 1));
metacards.add(mc);
}
return metacards;
}
});
if (numReturned != NULL_NUM_RETURNED) {
when(mockFeatureCollection.getNumberReturned()).thenReturn(BigInteger.valueOf(numReturned));
} else {
when(mockFeatureCollection.getNumberReturned()).thenReturn(null);
}
when(mockWfs.getFeature(any(GetFeatureType.class))).thenReturn(mockFeatureCollection);
mockCapabilites.setFilterCapabilities(filterCapabilities);
when(mockAvailabilityTask.isAvailable()).thenReturn(true);
mockCapabilites.setFeatureTypeList(new FeatureTypeListType());
for (int ii = 0; ii < numFeatures; ii++) {
FeatureTypeType feature = new FeatureTypeType();
QName qName;
if (prefix) {
qName = new QName("http://example.com", SAMPLE_FEATURE_NAME + ii, "Prefix" + ii);
} else {
qName = new QName("http://example.com", SAMPLE_FEATURE_NAME + ii);
}
feature.setName(qName);
feature.setDefaultCRS(GeospatialUtil.EPSG_4326_URN);
mockCapabilites.getFeatureTypeList().getFeatureType().add(feature);
}
XmlSchema xmlSchema = null;
if (StringUtils.isNotBlank(schema)) {
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
WfsUriResolver wfsUriResolver = new WfsUriResolver();
wfsUriResolver.setGmlNamespace(Wfs20Constants.GML_3_2_NAMESPACE);
wfsUriResolver.setWfsNamespace(Wfs20Constants.WFS_2_0_NAMESPACE);
schemaCollection.setSchemaResolver(wfsUriResolver);
xmlSchema = schemaCollection.read(new StreamSource(new ByteArrayInputStream(schema.getBytes())));
}
if (throwExceptionOnDescribeFeatureType) {
when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenThrow(new WfsException(""));
} else {
when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenReturn(xmlSchema);
}
WfsSource wfsSource = new WfsSource(new GeotoolsFilterAdapterImpl(), mockContext, mockAvailabilityTask, mockFactory, encryptionService);
wfsSource.setFeatureCollectionReader(mockReader);
return wfsSource;
}
use of ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType in project ddf by codice.
the class WfsSource method buildFeatureFilters.
private void buildFeatureFilters(List<FeatureTypeType> featureTypes, List<String> supportedSpatialOperators, List<QName> supportedGeometryOperands) {
ExtendedWfs wfs = factory.getClient();
// Use local Map for metacardtype registrations and once they are populated with latest
// MetacardTypes, then do actual registration
Map<String, FeatureMetacardType> mcTypeRegs = new HashMap<>();
this.featureTypeFilters.clear();
for (FeatureTypeType featureTypeType : featureTypes) {
String ftSimpleName = featureTypeType.getName().getLocalPart();
if (StringUtils.isNotBlank(forcedFeatureType) && !StringUtils.equals(forcedFeatureType, ftSimpleName)) {
continue;
}
if (mcTypeRegs.containsKey(ftSimpleName)) {
LOGGER.debug("WfsSource {}: MetacardType {} is already registered - skipping to next metacard type", getId(), ftSimpleName);
continue;
}
LOGGER.debug("ftName: {}", ftSimpleName);
try {
XmlSchema schema = wfs.describeFeatureType(new DescribeFeatureTypeRequest(featureTypeType.getName()));
if (schema == null) {
schema = wfs.describeFeatureType(new DescribeFeatureTypeRequest(new QName(featureTypeType.getName().getNamespaceURI(), featureTypeType.getName().getLocalPart(), "")));
}
if (schema != null) {
FeatureMetacardType featureMetacardType = createFeatureMetacardTypeRegistration(featureTypeType, ftSimpleName, schema);
MetacardMapper metacardMapper = getMetacardMapper(featureTypeType.getName());
this.featureTypeFilters.put(featureMetacardType.getFeatureType(), new WfsFilterDelegate(featureMetacardType, metacardMapper, supportedSpatialOperators, supportedGeometryOperands, getCoordinateStrategy(), wildcardChar, singleChar, escapeChar));
mcTypeRegs.put(ftSimpleName, featureMetacardType);
((WfsMetadataImpl<FeatureTypeType>) wfsMetadata).addEntry(featureTypeType);
}
} catch (WfsException | IllegalArgumentException wfse) {
LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
} catch (WebApplicationException wae) {
LOGGER.debug(handleWebApplicationException(wae), wae);
}
}
registerFeatureMetacardTypes(mcTypeRegs);
if (featureTypeFilters.isEmpty()) {
LOGGER.debug("Wfs Source {}: No Feature Type schemas validated.", getId());
}
LOGGER.debug("Wfs Source {}: Number of validated Features = {}", getId(), featureTypeFilters.size());
}
use of ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType in project ddf by codice.
the class WfsSource method createFeatureMetacardTypeRegistration.
private FeatureMetacardType createFeatureMetacardTypeRegistration(FeatureTypeType featureTypeType, String ftName, XmlSchema schema) {
MetacardTypeEnhancer metacardTypeEnhancer = metacardTypeEnhancers.stream().filter(me -> me.getFeatureName() != null).filter(me -> me.getFeatureName().equalsIgnoreCase(ftName)).findAny().orElse(FeatureMetacardType.DEFAULT_METACARD_TYPE_ENHANCER);
FeatureMetacardType ftMetacard = new FeatureMetacardType(schema, featureTypeType.getName(), nonQueryableProperties != null ? Arrays.stream(nonQueryableProperties).collect(toSet()) : new HashSet<>(), Wfs11Constants.GML_3_1_1_NAMESPACE, metacardTypeEnhancer);
Dictionary<String, Object> props = new DictionaryMap<>();
props.put(Metacard.CONTENT_TYPE, new String[] { ftName });
LOGGER.debug("WfsSource {}: Registering MetacardType: {}", getId(), ftName);
return ftMetacard;
}
use of ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType in project ddf by codice.
the class WfsSourceTest method setUpMocks.
private void setUpMocks(final List<String> supportedGeos, final String srsName, final int results, final int hits) throws WfsException {
SecureCxfClientFactory<ExtendedWfs> mockFactory = mock(SecureCxfClientFactory.class);
when(mockFactory.getClient()).thenReturn(mockWfs);
clientBuilderFactory = mock(ClientBuilderFactory.class);
ClientBuilder<ExtendedWfs> clientBuilder = new ClientBuilderImpl<ExtendedWfs>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {
@Override
public SecureCxfClientFactory<ExtendedWfs> build() {
return mockFactory;
}
};
when(clientBuilderFactory.<ExtendedWfs>getClientBuilder()).thenReturn(clientBuilder);
// GetCapabilities Response
when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilities);
mockCapabilities.setFilterCapabilities(new FilterCapabilities());
mockCapabilities.getFilterCapabilities().setSpatialCapabilities(new SpatialCapabilitiesType());
mockCapabilities.getFilterCapabilities().getSpatialCapabilities().setSpatialOperators(new SpatialOperatorsType());
if (CollectionUtils.isNotEmpty(supportedGeos)) {
mockCapabilities.getFilterCapabilities().getSpatialCapabilities().getSpatialOperators().getSpatialOperator().addAll(supportedGeos.stream().map(opName -> {
SpatialOperatorType spatialOperatorType = new SpatialOperatorType();
spatialOperatorType.setName(SpatialOperatorNameType.fromValue(opName));
return spatialOperatorType;
}).collect(Collectors.toList()));
}
mockCapabilities.getFilterCapabilities().getSpatialCapabilities().setGeometryOperands(new GeometryOperandsType());
mockCapabilities.getFilterCapabilities().getSpatialCapabilities().getGeometryOperands().getGeometryOperand().addAll(Arrays.asList(Wfs11Constants.POLYGON, Wfs11Constants.POINT));
sampleFeatures = new ArrayList<>();
mockCapabilities.setFeatureTypeList(new FeatureTypeListType());
for (int ii = 0; ii < results; ii++) {
FeatureTypeType feature = new FeatureTypeType();
QName qName;
if (ii == 0) {
qName = new QName("SampleFeature" + ii);
} else {
qName = new QName("http://example.com", "SampleFeature" + ii, "Prefix" + ii);
}
sampleFeatures.add(qName);
feature.setName(qName);
if (null != srsName) {
feature.setDefaultSRS(srsName);
}
mockCapabilities.getFeatureTypeList().getFeatureType().add(feature);
}
List<Metacard> metacards = new ArrayList<>(results);
for (int i = 0; i < results; i++) {
MetacardImpl mc = new MetacardImpl();
mc.setId("ID_" + (i + 1));
metacards.add(mc);
}
when(mockWfs.getFeature(withResultType(ResultTypeType.HITS))).thenReturn(new WfsFeatureCollectionImpl(hits));
when(mockWfs.getFeature(withResultType(ResultTypeType.RESULTS))).thenReturn(new WfsFeatureCollectionImpl(results, metacards));
final ScheduledFuture<?> mockAvailabilityPollFuture = mock(ScheduledFuture.class);
doReturn(mockAvailabilityPollFuture).when(mockScheduler).scheduleWithFixedDelay(any(), anyInt(), anyInt(), any());
source = new WfsSource(clientBuilderFactory, encryptionService, mockScheduler);
source.setId(WFS_ID);
source.setFilterAdapter(new GeotoolsFilterAdapterImpl());
source.setContext(mockContext);
source.setWfsMetacardTypeRegistry(mockWfsMetacardTypeRegistry);
source.setMetacardTypeEnhancers(Collections.emptyList());
source.setMetacardMappers(metacardMappers);
source.setPollInterval(10);
source.setWfsUrl(SAMPLE_WFS_URL);
source.setSupportsStartIndex(false);
source.setForceAllGeometryOperands(forceAllGeometryOperands);
source.init();
}
use of ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType in project ddf by codice.
the class XStreamWfs11FeatureTransformer method apply.
@Override
public Optional<Metacard> apply(InputStream document, WfsMetadata<FeatureTypeType> metadata) {
XStream xStream = new XStream(new WstxDriver());
xStream.addPermission(NoTypePermission.NONE);
xStream.allowTypeHierarchy(Metacard.class);
xStream.setClassLoader(this.getClass().getClassLoader());
xStream.registerConverter(new GmlGeometryConverter());
xStream.registerConverter(new GmlEnvelopeConverter());
xStream.alias(metadata.getActiveFeatureMemberNodeName(), Metacard.class);
FeatureTypeType featureType = null;
for (FeatureTypeType ft : metadata.getDescriptors()) {
if (ft.getName() != null && metadata.getActiveFeatureMemberNodeName().equals(ft.getName().getLocalPart())) {
featureType = ft;
}
}
lookupFeatureConverter(metadata, featureType).ifPresent(xStream::registerConverter);
Metacard metacard = null;
try {
metacard = (Metacard) xStream.fromXML(document);
} catch (XStreamException e) {
LOGGER.trace("Failed to parse FeatureMember into Metacard", e);
}
return Optional.ofNullable(metacard);
}
Aggregations