Search in sources :

Example 1 with Wfs

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs in project ddf by codice.

the class WfsFilterDelegate method updateAllowedOperations.

private final void updateAllowedOperations(FilterCapabilities filterCapabilities) {
    comparisonOps = Collections.newSetFromMap(new ConcurrentHashMap<COMPARISON_OPERATORS, Boolean>(new EnumMap<COMPARISON_OPERATORS, Boolean>(COMPARISON_OPERATORS.class)));
    geometryOperands = new ArrayList<QName>();
    temporalOperands = new ArrayList<QName>();
    if (filterCapabilities == null) {
        LOGGER.debug("WFS 2.0 Service doesn't support any filters");
        return;
    }
    // CONFORMANCE
    configureConformance(filterCapabilities.getConformance());
    ScalarCapabilitiesType scalarCapabilities = filterCapabilities.getScalarCapabilities();
    if (scalarCapabilities != null) {
        // LOGICAL OPERATORS
        if (scalarCapabilities.getLogicalOperators() != null) {
            logicalOps = true;
        }
        // COMPARISON OPERATORS
        ComparisonOperatorsType comparisonOperators = scalarCapabilities.getComparisonOperators();
        if (comparisonOperators != null) {
            for (ComparisonOperatorType comp : comparisonOperators.getComparisonOperator()) {
                if (null != comp) {
                    comparisonOps.add(COMPARISON_OPERATORS.valueOf(comp.getName()));
                }
            }
        }
    }
    // SPATIAL OPERATORS
    SpatialCapabilitiesType spatialCapabilities = filterCapabilities.getSpatialCapabilities();
    if (spatialCapabilities != null) {
        if (spatialCapabilities.getSpatialOperators() != null) {
            setSpatialOps(spatialCapabilities.getSpatialOperators());
        }
        // GEOMETRY OPERANDS
        GeometryOperandsType geometryOperandsType = spatialCapabilities.getGeometryOperands();
        if (geometryOperandsType != null) {
            for (GeometryOperandsType.GeometryOperand geoOperand : geometryOperandsType.getGeometryOperand()) {
                if (geoOperand.getName() != null) {
                    geometryOperands.add(geoOperand.getName());
                }
            }
            LOGGER.debug("geometryOperands: {}", geometryOperands);
        }
    }
    // TEMPORAL OPERATORS
    TemporalCapabilitiesType temporalCapabilitiesType = filterCapabilities.getTemporalCapabilities();
    if (temporalCapabilitiesType != null) {
        if (temporalCapabilitiesType.getTemporalOperators() != null) {
            setTemporalOps(temporalCapabilitiesType.getTemporalOperators());
        }
        // TEMPORAL OPERANDS
        TemporalOperandsType temporalOperandsType = temporalCapabilitiesType.getTemporalOperands();
        if (temporalOperandsType != null) {
            for (TemporalOperandsType.TemporalOperand temporalOperand : temporalOperandsType.getTemporalOperand()) {
                if (temporalOperand.getName() != null) {
                    temporalOperands.add(temporalOperand.getName());
                }
            }
            LOGGER.debug("temporalOperands: {}", temporalOperands);
        }
    }
}
Also used : TemporalCapabilitiesType(net.opengis.filter.v_2_0_0.TemporalCapabilitiesType) QName(javax.xml.namespace.QName) SpatialCapabilitiesType(net.opengis.filter.v_2_0_0.SpatialCapabilitiesType) ComparisonOperatorsType(net.opengis.filter.v_2_0_0.ComparisonOperatorsType) ScalarCapabilitiesType(net.opengis.filter.v_2_0_0.ScalarCapabilitiesType) GeometryOperandsType(net.opengis.filter.v_2_0_0.GeometryOperandsType) ComparisonOperatorType(net.opengis.filter.v_2_0_0.ComparisonOperatorType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) COMPARISON_OPERATORS(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20Constants.COMPARISON_OPERATORS) GeometryOperand(net.opengis.filter.v_2_0_0.GeometryOperandsType.GeometryOperand) TemporalOperandsType(net.opengis.filter.v_2_0_0.TemporalOperandsType) TemporalOperand(net.opengis.filter.v_2_0_0.TemporalOperandsType.TemporalOperand)

Example 2 with Wfs

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs in project ddf by codice.

the class WfsSource method getCapabilities.

private WFSCapabilitiesType getCapabilities() throws SecurityServiceException {
    WFSCapabilitiesType capabilities = null;
    Wfs wfs = factory.getClient();
    try {
        capabilities = wfs.getCapabilities(new GetCapabilitiesRequest());
    } catch (WfsException wfse) {
        LOGGER.info(WFS_ERROR_MESSAGE + " Received HTTP code '{}' from server for source with id='{}'", wfse.getHttpStatus(), getId());
        LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
    } catch (WebApplicationException wae) {
        LOGGER.debug(handleWebApplicationException(wae), wae);
    } catch (Exception e) {
        handleClientException(e);
    }
    return capabilities;
}
Also used : WFSCapabilitiesType(ogc.schema.opengis.wfs_capabilities.v_1_0_0.WFSCapabilitiesType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.GetCapabilitiesRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Wfs(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) JAXBException(javax.xml.bind.JAXBException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) WebApplicationException(javax.ws.rs.WebApplicationException) SecurityServiceException(ddf.security.service.SecurityServiceException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException)

Example 3 with Wfs

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs in project ddf by codice.

the class WfsSource method query.

@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
    Wfs wfs = factory.getClient();
    Query query = request.getQuery();
    LOGGER.debug("WFS Source {}: Received query: \n{}", getId(), query);
    if (query.getStartIndex() < 1) {
        throw new UnsupportedQueryException("Start Index is one-based and must be an integer greater than 0; should not be [" + query.getStartIndex() + "]");
    }
    SourceResponseImpl simpleResponse = null;
    // WFS v1.0 specification does not support response indicating total
    // number
    // of features satisfying query constraints.
    // Hence, we save off the original
    // page size from the query request and create a copy of the query,
    // changing
    // the page size by a multiplier and the current page number of results
    // so that
    // more features are returned as the user pages through the results,
    // getting
    // a better sense of how many total features exist that satisfy the
    // query.
    int origPageSize = query.getPageSize();
    if (origPageSize <= 0 || origPageSize > WFS_MAX_FEATURES_RETURNED) {
        origPageSize = WFS_MAX_FEATURES_RETURNED;
    }
    QueryImpl modifiedQuery = new QueryImpl(query);
    // Determine current page number of results being requested.
    // Example: startIndex = 21 and origPageSize=10, then requesting to go
    // to page number 3.
    // Note: Integer division will truncate remainders so 4 / 2 will return 0 and not .5.  Also,
    // pages are numbered 1 - N so we add 1 to the result
    int pageNumber = query.getStartIndex() / origPageSize + 1;
    // Modified page size is based on current page number and a constant
    // multiplier,
    // but limited to a max value to prevent time consuming queries just to
    // get an
    // approximation of total number of features.
    // So as page number increases the pageSize increases.
    // Example:
    // pageNumber=2, modifiedPageSize=60
    // pageNumber=3, modifiedPageSize=90
    int modifiedPageSize = Math.min(pageNumber * origPageSize * WFS_QUERY_PAGE_SIZE_MULTIPLIER, WFS_MAX_FEATURES_RETURNED);
    LOGGER.debug("WFS Source {}: modified page size = {}", getId(), modifiedPageSize);
    modifiedQuery.setPageSize(modifiedPageSize);
    GetFeatureType getFeature = buildGetFeatureRequest(modifiedQuery);
    try {
        LOGGER.debug("WFS Source {}: Sending query ...", getId());
        WfsFeatureCollection featureCollection = wfs.getFeature(getFeature);
        if (featureCollection == null) {
            throw new UnsupportedQueryException("Invalid results returned from server");
        }
        availabilityTask.updateLastAvailableTimestamp(System.currentTimeMillis());
        LOGGER.debug("WFS Source {}: Received featureCollection with {} metacards.", getId(), featureCollection.getFeatureMembers().size());
        // Only return the number of results originally asked for in the
        // query, or the entire list of results if it is smaller than the
        // original page size.
        int numberOfResultsToReturn = Math.min(origPageSize, featureCollection.getFeatureMembers().size());
        List<Result> results = new ArrayList<Result>(numberOfResultsToReturn);
        int stopIndex = Math.min((origPageSize * pageNumber) + query.getStartIndex(), featureCollection.getFeatureMembers().size() + 1);
        LOGGER.debug("WFS Source {}: startIndex = {}, stopIndex = {}, origPageSize = {}, pageNumber = {}", getId(), query.getStartIndex(), stopIndex, origPageSize, pageNumber);
        for (int i = query.getStartIndex(); i < stopIndex; i++) {
            Metacard mc = featureCollection.getFeatureMembers().get(i - 1);
            mc = transform(mc, DEFAULT_WFS_TRANSFORMER_ID);
            Result result = new ResultImpl(mc);
            results.add(result);
            debugResult(result);
        }
        Long totalHits = (long) featureCollection.getFeatureMembers().size();
        simpleResponse = new SourceResponseImpl(request, results, totalHits);
    } catch (WfsException wfse) {
        LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
        throw new UnsupportedQueryException("Error received from WFS Server", wfse);
    } catch (Exception ce) {
        String msg = handleClientException(ce);
        throw new UnsupportedQueryException(msg, ce);
    }
    return simpleResponse;
}
Also used : Query(ddf.catalog.operation.Query) Wfs(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) JAXBException(javax.xml.bind.JAXBException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) WebApplicationException(javax.ws.rs.WebApplicationException) SecurityServiceException(ddf.security.service.SecurityServiceException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollection) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)

Example 4 with Wfs

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs 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 Wfs

use of org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs in project ddf by codice.

the class TestGenericFeatureConverter method testUnmarshalNoMetacardTypeRegisteredInConverter.

@Test(expected = IllegalArgumentException.class)
public void testUnmarshalNoMetacardTypeRegisteredInConverter() throws Throwable {
    XStream xstream = new XStream(new WstxDriver());
    xstream.registerConverter(new GenericFeatureConverterWfs20());
    xstream.registerConverter(new GmlGeometryConverter());
    xstream.alias(FEATURE_TYPE, Metacard.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set.xml");
    try {
        Wfs20FeatureCollection wfs = (Wfs20FeatureCollection) xstream.fromXML(is);
    } catch (Exception e) {
        throw e.getCause();
    }
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) Wfs20FeatureCollection(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection) Test(org.junit.Test)

Aggregations

WebApplicationException (javax.ws.rs.WebApplicationException)7 WfsException (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)6 JAXBException (javax.xml.bind.JAXBException)5 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)4 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)4 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)4 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)4 SecurityServiceException (ddf.security.service.SecurityServiceException)4 IOException (java.io.IOException)4 ConnectException (java.net.ConnectException)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 ArrayList (java.util.ArrayList)3 Wfs (org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.Wfs)3 Wfs (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs)3 Wfs20FeatureCollection (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection)3 Metacard (ddf.catalog.data.Metacard)2 Result (ddf.catalog.data.Result)2 ResultImpl (ddf.catalog.data.impl.ResultImpl)2 Query (ddf.catalog.operation.Query)2