Search in sources :

Example 11 with GetFeatureType

use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.

the class TestWfsSource method testSortingAscendingSortingNotSupported.

/**
     * Verify that the SortBy is NOT set.  In this case, sorting is not supported in the capabilities.
     */
@Test
public void testSortingAscendingSortingNotSupported() throws Exception {
    // Setup
    final String searchPhrase = "*";
    final String mockTemporalFeatureProperty = "myTemporalFeatureProperty";
    final String mockFeatureType = "{http://example.com}" + SAMPLE_FEATURE_NAME + 0;
    final int pageSize = 1;
    // Set ImplementsSorting to FALSE (sorting not supported)
    FilterCapabilities mockCapabilitiesSortingNotSupported = MockWfsServer.getFilterCapabilities();
    ConformanceType conformance = mockCapabilitiesSortingNotSupported.getConformance();
    List<DomainType> domainTypes = conformance.getConstraint();
    for (DomainType domainType : domainTypes) {
        if (StringUtils.equals(domainType.getName(), "ImplementsSorting")) {
            ValueType valueType = new ValueType();
            valueType.setValue("FALSE");
            domainType.setDefaultValue(valueType);
            break;
        }
    }
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, mockCapabilitiesSortingNotSupported, GeospatialUtil.EPSG_4326_URN, 1, false, false, 0);
    MetacardMapper mockMetacardMapper = mock(MetacardMapper.class);
    when(mockMetacardMapper.getFeatureType()).thenReturn(mockFeatureType);
    when(mockMetacardMapper.getSortByTemporalFeatureProperty()).thenReturn(mockTemporalFeatureProperty);
    List<MetacardMapper> mappers = new ArrayList<MetacardMapper>(1);
    mappers.add(mockMetacardMapper);
    source.setMetacardToFeatureMapper(mappers);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    // Perform Test
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    // Verify
    QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
    assertFalse(queryType.isSetAbstractSortingClause());
}
Also used : ValueType(net.opengis.ows.v_1_1_0.ValueType) SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) FilterCapabilities(net.opengis.filter.v_2_0_0.FilterCapabilities) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DomainType(net.opengis.ows.v_1_1_0.DomainType) SortByImpl(ddf.catalog.filter.impl.SortByImpl) ConformanceType(net.opengis.filter.v_2_0_0.ConformanceType) QueryType(net.opengis.wfs.v_2_0_0.QueryType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 12 with GetFeatureType

use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.

the class TestWfsSource method testPagingPageSizeNegative.

/**
     * Verify that, per DDF Query API Javadoc, if the startIndex is negative, the WfsSource throws
     * an UnsupportedQueryException.
     *
     * @throws WfsException,                     SecurityServiceException
     * @throws TransformerConfigurationException
     * @throws UnsupportedQueryException
     */
@Test(expected = UnsupportedQueryException.class)
public void testPagingPageSizeNegative() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
    //Setup
    int pageSize = -4;
    int startIndex = 0;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 10, false);
    Filter filter = builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL);
    Query query = new QueryImpl(filter, startIndex, pageSize, null, false, 0);
    //Execute
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) Filter(org.opengis.filter.Filter) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 13 with GetFeatureType

use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.

the class TestWfsSource method testSrsNameProvided.

@Test
public void testSrsNameProvided() throws Exception {
    int pageSize = 10;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 10, false);
    source.setSrsName(GeospatialUtil.EPSG_4326);
    Filter filter = builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(SAMPLE_FEATURE_NAME + "0");
    QueryImpl query = new QueryImpl(filter);
    query.setPageSize(pageSize);
    //Execute
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
    assertThat(queryType.getSrsName(), is(GeospatialUtil.EPSG_4326));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryType(net.opengis.wfs.v_2_0_0.QueryType) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 14 with GetFeatureType

use of net.opengis.wfs.v_1_1_0.GetFeatureType 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;
}
Also used : GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.GetCapabilitiesRequest) FeatureTypeType(net.opengis.wfs.v_2_0_0.FeatureTypeType) FeatureTypeListType(net.opengis.wfs.v_2_0_0.FeatureTypeListType) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) XmlSchema(org.apache.ws.commons.schema.XmlSchema) ByteArrayInputStream(java.io.ByteArrayInputStream) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) WfsUriResolver(org.codice.ddf.spatial.ogc.wfs.catalog.source.WfsUriResolver) List(java.util.List) ArrayList(java.util.ArrayList) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.DescribeFeatureTypeRequest) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType)

Example 15 with GetFeatureType

use of net.opengis.wfs.v_1_1_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 JAXBElementProvider<GetFeatureType>();
    Map<String, String> jaxbClassMap = new HashMap<String, String>();
    // Ensure a namespace is used when the GetFeature request is generated
    String expandedName = new QName(Wfs10Constants.WFS_NAMESPACE, Wfs10Constants.GET_FEATURE).toString();
    jaxbClassMap.put(GetFeatureType.class.getName(), expandedName);
    provider.setJaxbElementClassMap(jaxbClassMap);
    provider.setMarshallAsJaxbElement(true);
    featureCollectionReader = new FeatureCollectionMessageBodyReaderWfs10();
    return Arrays.asList(provider, new WfsResponseExceptionMapper(), new XmlSchemaMessageBodyReaderWfs10(), featureCollectionReader);
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) XmlSchemaMessageBodyReaderWfs10(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.source.reader.XmlSchemaMessageBodyReaderWfs10) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) FeatureCollectionMessageBodyReaderWfs10(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.source.reader.FeatureCollectionMessageBodyReaderWfs10) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)

Aggregations

QueryImpl (ddf.catalog.operation.impl.QueryImpl)58 Test (org.junit.Test)57 Filter (org.opengis.filter.Filter)34 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)32 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)31 QueryType (net.opengis.wfs.v_2_0_0.QueryType)21 ArrayList (java.util.ArrayList)19 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)19 QueryType (net.opengis.wfs.v_1_1_0.QueryType)17 Matchers.containsString (org.hamcrest.Matchers.containsString)15 SortByImpl (ddf.catalog.filter.impl.SortByImpl)12 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)12 SortBy (org.opengis.filter.sort.SortBy)12 Query (ddf.catalog.operation.Query)9 QName (javax.xml.namespace.QName)9 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)8 Metacard (ddf.catalog.data.Metacard)5 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)5 JAXBElement (javax.xml.bind.JAXBElement)5 SortByType (net.opengis.filter.v_2_0_0.SortByType)5