Search in sources :

Example 1 with DescribeFeatureTypeRequest

use of org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.DescribeFeatureTypeRequest in project ddf by codice.

the class TestWfsSource method testConfigureFeatureTypes.

@Test
public void testConfigureFeatureTypes() throws WfsException, SecurityServiceException {
    ArgumentCaptor<DescribeFeatureTypeRequest> captor = ArgumentCaptor.forClass(DescribeFeatureTypeRequest.class);
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 1);
    final String SAMPLE_FEATURE_NAME0 = SAMPLE_FEATURE_NAME + "0";
    verify(mockWfs).describeFeatureType(captor.capture());
    DescribeFeatureTypeRequest describeFeatureType = captor.getValue();
    // sample feature 0 does not have a prefix
    assertThat(SAMPLE_FEATURE_NAME0, equalTo(describeFeatureType.getTypeName()));
    assertTrue(source.isAvailable());
    assertThat(source.featureTypeFilters.size(), is(1));
    WfsFilterDelegate delegate = source.featureTypeFilters.get(new QName(SAMPLE_FEATURE_NAME0));
    assertThat(delegate, notNullValue());
    assertThat(source.getContentTypes().size(), is(1));
    List<ContentType> types = new ArrayList<ContentType>();
    types.addAll(source.getContentTypes());
    assertTrue(SAMPLE_FEATURE_NAME0.equals(types.get(0).getName()));
}
Also used : ContentType(ddf.catalog.data.ContentType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.DescribeFeatureTypeRequest) Test(org.junit.Test)

Example 2 with DescribeFeatureTypeRequest

use of org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.DescribeFeatureTypeRequest in project ddf by codice.

the class TestWfsSource method testConfigureFeatureTypesDescribeFeatureException.

@Test
public void testConfigureFeatureTypesDescribeFeatureException() throws WfsException, SecurityServiceException {
    ArgumentCaptor<DescribeFeatureTypeRequest> captor = ArgumentCaptor.forClass(DescribeFeatureTypeRequest.class);
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 1, true);
    final String SAMPLE_FEATURE_NAME0 = SAMPLE_FEATURE_NAME + "0";
    verify(mockWfs).describeFeatureType(captor.capture());
    DescribeFeatureTypeRequest describeFeatureType = captor.getValue();
    // sample feature 0 does not have a prefix
    assertThat(SAMPLE_FEATURE_NAME0, equalTo(describeFeatureType.getTypeName()));
    assertTrue(source.featureTypeFilters.isEmpty());
    assertTrue(source.getContentTypes().isEmpty());
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.DescribeFeatureTypeRequest) Test(org.junit.Test)

Example 3 with DescribeFeatureTypeRequest

use of org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.DescribeFeatureTypeRequest 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());
}
Also used : FeatureTypeType(net.opengis.wfs.v_1_1_0.FeatureTypeType) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) WfsMetadataImpl(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsMetadataImpl) XmlSchema(org.apache.ws.commons.schema.XmlSchema) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v110.catalog.common.DescribeFeatureTypeRequest) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)

Example 4 with DescribeFeatureTypeRequest

use of org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.DescribeFeatureTypeRequest in project ddf by codice.

the class WfsSource method buildFeatureFilters.

private void buildFeatureFilters(List<FeatureTypeType> featureTypes, List<String> supportedGeo) throws SecurityServiceException {
    // Use local Map for metacardtype registrations and once they are populated with latest
    // MetacardTypes, then do actual registration
    Map<String, MetacardTypeRegistration> mcTypeRegs = new HashMap<String, MetacardTypeRegistration>();
    Wfs wfs = factory.getClient();
    for (FeatureTypeType featureTypeType : featureTypes) {
        String ftName = featureTypeType.getName().getLocalPart();
        if (StringUtils.isNotBlank(forcedFeatureType) && !StringUtils.equals(forcedFeatureType, ftName)) {
            continue;
        }
        if (mcTypeRegs.containsKey(ftName)) {
            LOGGER.debug("WfsSource {}: MetacardType {} is already registered - skipping to next metacard type", getId(), ftName);
            continue;
        }
        LOGGER.debug("ftName: {}", ftName);
        try {
            XmlSchema schema = wfs.describeFeatureType(new DescribeFeatureTypeRequest(featureTypeType.getName()));
            if ((schema != null)) {
                FeatureMetacardType ftMetacard = new FeatureMetacardType(schema, featureTypeType.getName(), nonQueryableProperties != null ? Arrays.asList(nonQueryableProperties) : new ArrayList<String>(), Wfs10Constants.GML_NAMESPACE);
                Dictionary<String, Object> props = new Hashtable<String, Object>();
                props.put(Metacard.CONTENT_TYPE, new String[] { ftName });
                LOGGER.debug("WfsSource {}: Registering MetacardType: {}", getId(), ftName);
                // Update local map with enough info to create actual MetacardType registrations
                // later
                mcTypeRegs.put(ftName, new MetacardTypeRegistration(ftMetacard, props, featureTypeType.getSRS()));
                FeatureConverter featureConverter = null;
                if (!CollectionUtils.isEmpty(featureConverterFactories)) {
                    for (FeatureConverterFactory factory : featureConverterFactories) {
                        if (ftName.equalsIgnoreCase(factory.getFeatureType())) {
                            featureConverter = factory.createConverter();
                            LOGGER.debug("WFS Source {}: Features of type: {} will be converted using {}", getId(), ftName, featureConverter.getClass().getSimpleName());
                            break;
                        }
                    }
                    if (featureConverter == null) {
                        LOGGER.debug("WfsSource {}: Unable to find a feature specific converter; {} will be converted using the GenericFeatureConverter", getId(), ftName);
                        featureConverter = new GenericFeatureConverter(featureTypeType.getSRS());
                    }
                } else {
                    LOGGER.debug("WfsSource {}: Unable to find a feature specific converter; {} will be converted using the GenericFeatureConverter", getId(), ftName);
                    featureConverter = new GenericFeatureConverter(featureTypeType.getSRS());
                }
                featureConverter.setSourceId(getId());
                featureConverter.setMetacardType(ftMetacard);
                featureConverter.setWfsUrl(wfsUrl);
                // Add the Feature Type name as an alias for xstream
                featureCollectionReader.registerConverter(featureConverter);
            }
        } catch (WfsException | IllegalArgumentException wfse) {
            LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
        } catch (WebApplicationException wae) {
            LOGGER.debug(handleWebApplicationException(wae), wae);
        }
    }
    // Unregister all MetacardType services - the DescribeFeatureTypeRequest should
    // have returned all of the most current metacard types that will now be registered.
    // As Source(s) are added/removed from this instance or to other Source(s)
    // that this instance is federated to, the list of metacard types will change.
    // This is done here vs. inside the above loop so that minimal time is spent clearing and
    // registering the MetacardTypes - the concern is that if this registration is too lengthy
    // a query could come in that is handled while the MetacardType registrations are
    // in a state of flux.
    unregisterAllMetacardTypes();
    this.featureTypeFilters.clear();
    if (!mcTypeRegs.isEmpty()) {
        Set<Entry<String, MetacardTypeRegistration>> entries = mcTypeRegs.entrySet();
        for (Map.Entry<String, MetacardTypeRegistration> entry : mcTypeRegs.entrySet()) {
            MetacardTypeRegistration mcTypeReg = entry.getValue();
            FeatureMetacardType ftMetacard = mcTypeReg.getFtMetacard();
            ServiceRegistration serviceRegistration = context.registerService(MetacardType.class.getName(), ftMetacard, mcTypeReg.getProps());
            this.metacardTypeServiceRegistrations.put(entry.getKey(), serviceRegistration);
            this.featureTypeFilters.put(ftMetacard.getFeatureType(), new WfsFilterDelegate(ftMetacard, supportedGeo, mcTypeReg.getSrs()));
        }
    }
    if (featureTypeFilters.isEmpty()) {
        LOGGER.info("Wfs Source {}: No Feature Type schemas validated. Marking source as unavailable", getId());
    }
    LOGGER.debug("Wfs Source {}: Number of validated Features = {}", getId(), featureTypeFilters.size());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Entry(java.util.Map.Entry) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) FeatureConverterFactory(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.converter.FeatureConverterFactory) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) FeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) ServiceRegistration(org.osgi.framework.ServiceRegistration) FeatureTypeType(ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType) Wfs(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs) Hashtable(java.util.Hashtable) MetacardType(ddf.catalog.data.MetacardType) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) XmlSchema(org.apache.ws.commons.schema.XmlSchema) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.DescribeFeatureTypeRequest) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with DescribeFeatureTypeRequest

use of org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.DescribeFeatureTypeRequest in project ddf by codice.

the class WfsSource method buildFeatureFilters.

private void buildFeatureFilters(List<FeatureTypeType> featureTypes, FilterCapabilities filterCapabilities) {
    Wfs wfs = factory.getClient();
    if (filterCapabilities == null) {
        return;
    }
    // Use local Map for metacardtype registrations and once they are populated with latest
    // MetacardTypes, then do actual registration
    Map<String, MetacardTypeRegistration> 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) {
                // Some WFS 2.0.0 DescribeFeatureRequests return inconsistent results when
                // the `:` character is encoded in the URL, ie Prefix:SomeFeature is encoded to
                // Prefix%3ASomeFeature. To avoid this issue, we will make a call without the prefix
                // if the previous call does not work.
                schema = wfs.describeFeatureType(new DescribeFeatureTypeRequest(new QName(featureTypeType.getName().getNamespaceURI(), featureTypeType.getName().getLocalPart(), "")));
            }
            if (schema != null) {
                // Update local map with enough info to create actual MetacardType registrations
                // later
                MetacardTypeRegistration registration = createFeatureMetacardTypeRegistration(featureTypeType, ftSimpleName, schema);
                mcTypeRegs.put(ftSimpleName, registration);
                FeatureMetacardType featureMetacardType = registration.getFtMetacard();
                lookupFeatureConverter(ftSimpleName, featureMetacardType);
                MetacardMapper metacardAttributeToFeaturePropertyMapper = lookupMetacardAttributeToFeaturePropertyMapper(featureMetacardType.getFeatureType(), metacardToFeatureMappers);
                if (metacardAttributeToFeaturePropertyMapper == null) {
                    LOGGER.debug("Unable to find a metacard mapper for featureType {} - using a default implementation", featureMetacardType.getFeatureType());
                    metacardAttributeToFeaturePropertyMapper = new MetacardMapperImpl();
                }
                this.featureTypeFilters.put(featureMetacardType.getFeatureType(), new WfsFilterDelegate(featureMetacardType, filterCapabilities, registration.getSrs(), metacardAttributeToFeaturePropertyMapper, coordinateOrder));
            }
        } 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());
    updateSupportedSpatialOperators(filterCapabilities.getSpatialCapabilities().getSpatialOperators());
}
Also used : FeatureTypeType(net.opengis.wfs.v_2_0_0.FeatureTypeType) WebApplicationException(javax.ws.rs.WebApplicationException) Wfs(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) MetacardMapperImpl(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl) XmlSchema(org.apache.ws.commons.schema.XmlSchema) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.DescribeFeatureTypeRequest) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)

Aggregations

DescribeFeatureTypeRequest (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.DescribeFeatureTypeRequest)5 QName (javax.xml.namespace.QName)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 XmlSchema (org.apache.ws.commons.schema.XmlSchema)3 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)3 WfsException (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)3 ContentType (ddf.catalog.data.ContentType)2 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)2 MetacardType (ddf.catalog.data.MetacardType)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 FeatureTypeType (net.opengis.wfs.v_1_1_0.FeatureTypeType)1 FeatureTypeType (net.opengis.wfs.v_2_0_0.FeatureTypeType)1 FeatureTypeType (ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType)1 WfsMetadataImpl (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsMetadataImpl)1