Search in sources :

Example 36 with GetFeatureType

use of ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType in project ddf by codice.

the class TestWfsSource method testSortingNoSortBySortingSupported.

@Test
public void testSortingNoSortBySortingSupported() throws Exception {
    // Setup
    final String searchPhrase = "*";
    final int pageSize = 1;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 1, false, false, 0);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    // Perform Test
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    // Verify
    QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
    assertFalse(queryType.isSetAbstractSortingClause());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) QueryType(net.opengis.wfs.v_2_0_0.QueryType) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 37 with GetFeatureType

use of ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType in project ddf by codice.

the class WfsSource method initProviders.

private List<? extends Object> initProviders() {
    // We need to tell the JAXBElementProvider to marshal the GetFeatureType
    // class as an element
    // because it is missing the @XmlRootElement Annotation
    JAXBElementProvider<GetFeatureType> provider = new Wfs20JaxbElementProvider<>();
    Map<String, String> jaxbClassMap = new HashMap<String, String>();
    // Ensure a namespace is used when the GetFeature request is generated
    String expandedName = new QName(Wfs20Constants.WFS_2_0_NAMESPACE, Wfs20Constants.GET_FEATURE).toString();
    jaxbClassMap.put(GetFeatureType.class.getName(), expandedName);
    provider.setJaxbElementClassMap(jaxbClassMap);
    provider.setMarshallAsJaxbElement(true);
    featureCollectionReader = new FeatureCollectionMessageBodyReaderWfs20();
    return Arrays.asList(provider, new XmlSchemaMessageBodyReaderWfs20(), featureCollectionReader);
}
Also used : XmlSchemaMessageBodyReaderWfs20(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.source.reader.XmlSchemaMessageBodyReaderWfs20) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) FeatureCollectionMessageBodyReaderWfs20(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.source.reader.FeatureCollectionMessageBodyReaderWfs20) Wfs20JaxbElementProvider(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20JaxbElementProvider) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType)

Example 38 with GetFeatureType

use of ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType 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();
    if (query == null) {
        LOGGER.debug("WFS Source {}: Incoming query is null.", getId());
        return null;
    }
    LOGGER.debug("WFS Source {}: Received query: \n{}", getId(), query);
    SourceResponseImpl simpleResponse = null;
    GetFeatureType getFeature = buildGetFeatureRequest(query);
    try {
        LOGGER.debug("WFS Source {}: Sending query ...", getId());
        Wfs20FeatureCollection featureCollection = wfs.getFeature(getFeature);
        int numResults = -1;
        if (featureCollection == null) {
            throw new UnsupportedQueryException("Invalid results returned from server");
        }
        numResults = featureCollection.getMembers().size();
        if (featureCollection.getNumberReturned() == null) {
            LOGGER.debug("Number Returned Attribute was not added to the response");
        } else if (!featureCollection.getNumberReturned().equals(BigInteger.valueOf(numResults))) {
            LOGGER.debug("Number Returned Attribute ({}) did not match actual number returned ({})", featureCollection.getNumberReturned(), numResults);
        }
        availabilityTask.updateLastAvailableTimestamp(System.currentTimeMillis());
        LOGGER.debug("WFS Source {}: Received featureCollection with {} metacards.", getId(), numResults);
        List<Result> results = new ArrayList<Result>(numResults);
        for (int i = 0; i < numResults; i++) {
            Metacard mc = featureCollection.getMembers().get(i);
            mc = transform(mc, DEFAULT_WFS_TRANSFORMER_ID);
            Result result = new ResultImpl(mc);
            results.add(result);
            debugResult(result);
        }
        //Fetch total results available
        long totalResults = 0;
        if (featureCollection.getNumberMatched() == null) {
            totalResults = Long.valueOf(numResults);
        } else if (featureCollection.getNumberMatched().equals(UNKNOWN)) {
            totalResults = Long.valueOf(numResults);
        } else if (StringUtils.isNumeric(featureCollection.getNumberMatched())) {
            totalResults = Long.parseLong(featureCollection.getNumberMatched());
        }
        simpleResponse = new SourceResponseImpl(request, results, totalResults);
    } 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.v2_0_0.catalog.common.Wfs) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Wfs20FeatureCollection(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) SecurityServiceException(ddf.security.service.SecurityServiceException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) JAXBException(javax.xml.bind.JAXBException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType)

Aggregations

QueryImpl (ddf.catalog.operation.impl.QueryImpl)30 Test (org.junit.Test)29 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)19 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)18 Filter (org.opengis.filter.Filter)18 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 ArrayList (java.util.ArrayList)12 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)12 QueryType (net.opengis.wfs.v_2_0_0.QueryType)11 Matchers.containsString (org.hamcrest.Matchers.containsString)7 SortByImpl (ddf.catalog.filter.impl.SortByImpl)6 QName (javax.xml.namespace.QName)6 SortBy (org.opengis.filter.sort.SortBy)6 Query (ddf.catalog.operation.Query)5 PropertyIsLikeType (ogc.schema.opengis.filter.v_1_0_0.PropertyIsLikeType)5 Metacard (ddf.catalog.data.Metacard)4 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)4 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)4 JAXBElement (javax.xml.bind.JAXBElement)3 JAXBException (javax.xml.bind.JAXBException)3