Search in sources :

Example 1 with FeatureTypeListType

use of ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeListType 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 2 with FeatureTypeListType

use of ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeListType 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();
}
Also used : SecurityManager(ddf.security.service.SecurityManager) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) ArrayList(java.util.ArrayList) SpatialCapabilitiesType(net.opengis.filter.v_1_1_0.SpatialCapabilitiesType) FilterCapabilities(net.opengis.filter.v_1_1_0.FilterCapabilities) SpatialOperatorsType(net.opengis.filter.v_1_1_0.SpatialOperatorsType) WfsFeatureCollectionImpl(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollectionImpl) GeometryOperandsType(net.opengis.filter.v_1_1_0.GeometryOperandsType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.wfs.v110.catalog.common.GetCapabilitiesRequest) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) FeatureTypeType(net.opengis.wfs.v_1_1_0.FeatureTypeType) FeatureTypeListType(net.opengis.wfs.v_1_1_0.FeatureTypeListType) QName(javax.xml.namespace.QName) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) SpatialOperatorType(net.opengis.filter.v_1_1_0.SpatialOperatorType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SecurityLogger(ddf.security.audit.SecurityLogger)

Example 3 with FeatureTypeListType

use of ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeListType in project ddf by codice.

the class TestWfsSource method setUp.

public void setUp(final String schema, final List<Object> supportedGeos, final String srsName, final Integer numFeatures, final Integer numResults) throws WfsException, SecurityServiceException {
    mockFactory = mock(SecureCxfClientFactory.class);
    when(mockFactory.getClient()).thenReturn(mockWfs);
    // GetCapabilities Response
    when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilites);
    mockCapabilites.setFilterCapabilities(new FilterCapabilities());
    mockCapabilites.getFilterCapabilities().setSpatialCapabilities(new SpatialCapabilitiesType());
    mockCapabilites.getFilterCapabilities().getSpatialCapabilities().setSpatialOperators(new SpatialOperatorsType());
    if (null != supportedGeos && !supportedGeos.isEmpty()) {
        mockCapabilites.getFilterCapabilities().getSpatialCapabilities().getSpatialOperators().getBBOXOrEqualsOrDisjoint().addAll(supportedGeos);
    }
    // DescribeFeatureType Response
    XmlSchema xmlSchema = null;
    if (null != schema) {
        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        wfsUriResolver.setGmlNamespace(Wfs10Constants.GML_NAMESPACE);
        wfsUriResolver.setWfsNamespace(Wfs10Constants.WFS_NAMESPACE);
        schemaCollection.setSchemaResolver(wfsUriResolver);
        xmlSchema = schemaCollection.read(new StreamSource(new ByteArrayInputStream(schema.getBytes())));
    }
    when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenReturn(xmlSchema);
    sampleFeatures = new ArrayList<>();
    mockCapabilites.setFeatureTypeList(new FeatureTypeListType());
    if (numFeatures != null) {
        for (int ii = 0; ii < numFeatures; 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);
            // feature.setName(SAMPLE_FEATURE[ii]);
            if (null != srsName) {
                feature.setSRS(srsName);
            }
            mockCapabilites.getFeatureTypeList().getFeatureType().add(feature);
        }
    }
    // GetFeature Response
    when(mockWfs.getFeature(any(GetFeatureType.class))).thenReturn(mockFeatureCollection);
    when(mockFeatureCollection.getFeatureMembers()).thenAnswer(new Answer<List<Metacard>>() {

        @Override
        public List<Metacard> answer(InvocationOnMock invocation) {
            // Create as many metacards as there are features
            Integer resultsToReturn = numResults;
            if (resultsToReturn == null && numFeatures != null) {
                resultsToReturn = numFeatures;
            }
            List<Metacard> metacards = new ArrayList<Metacard>(resultsToReturn);
            for (int i = 0; i < resultsToReturn; i++) {
                MetacardImpl mc = new MetacardImpl();
                mc.setId("ID_" + String.valueOf(i + 1));
                metacards.add(mc);
            }
            return metacards;
        }
    });
    when(mockAvailabilityTask.isAvailable()).thenReturn(true);
    source = new WfsSource(new GeotoolsFilterAdapterImpl(), mockContext, mockAvailabilityTask, mockFactory, encryptionService);
}
Also used : SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) SpatialCapabilitiesType(ogc.schema.opengis.filter_capabilities.v_1_0_0.SpatialCapabilitiesType) FilterCapabilities(ogc.schema.opengis.filter_capabilities.v_1_0_0.FilterCapabilities) SpatialOperatorsType(ogc.schema.opengis.filter_capabilities.v_1_0_0.SpatialOperatorsType) List(java.util.List) ArrayList(java.util.ArrayList) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.GetCapabilitiesRequest) FeatureTypeType(ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType) FeatureTypeListType(ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeListType) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) BigInteger(java.math.BigInteger) Metacard(ddf.catalog.data.Metacard) XmlSchema(org.apache.ws.commons.schema.XmlSchema) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.DescribeFeatureTypeRequest) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)

Example 4 with FeatureTypeListType

use of ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeListType in project ddf by codice.

the class WfsSourceTest method getWfsSource.

private WfsSource getWfsSource(final String schema, final FilterCapabilities filterCapabilities, final int numFeatures, final boolean throwExceptionOnDescribeFeatureType, boolean prefix, int numReturned) throws WfsException {
    mockFactory = mock(SecureCxfClientFactory.class);
    when(mockFactory.getClient()).thenReturn(mockWfs);
    ClientBuilder<Wfs> clientBuilder = new ClientBuilderImpl<Wfs>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {

        @Override
        public SecureCxfClientFactory<Wfs> build() {
            return mockFactory;
        }
    };
    when(mockClientBuilderFactory.<Wfs>getClientBuilder()).thenReturn(clientBuilder);
    // GetCapabilities Response
    when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilities);
    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<>(numFeatures);
            for (int i = 0; i < numFeatures; i++) {
                MetacardImpl mc = new MetacardImpl();
                mc.setId("ID_" + (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);
    mockCapabilities.setFilterCapabilities(filterCapabilities);
    when(mockAvailabilityTask.isAvailable()).thenReturn(true);
    mockCapabilities.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);
        mockCapabilities.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);
    }
    final ScheduledFuture<?> mockAvailabilityPollFuture = mock(ScheduledFuture.class);
    doReturn(mockAvailabilityPollFuture).when(mockScheduler).scheduleWithFixedDelay(any(), anyInt(), anyInt(), any());
    WfsSource wfsSource = new WfsSource(mockClientBuilderFactory, encryptionService, mockScheduler);
    wfsSource.setContext(mockContext);
    wfsSource.setFilterAdapter(new GeotoolsFilterAdapterImpl());
    wfsSource.setFeatureCollectionReader(mockReader);
    wfsSource.setMetacardToFeatureMapper(metacardMappers);
    wfsSource.setPollInterval(10);
    wfsSource.setWfsUrl(SAMPLE_WFS_URL);
    wfsSource.init();
    return wfsSource;
}
Also used : SecurityManager(ddf.security.service.SecurityManager) SecureCxfClientFactory(org.codice.ddf.cxf.client.SecureCxfClientFactory) WfsUriResolver(org.codice.ddf.spatial.ogc.wfs.catalog.source.WfsUriResolver) List(java.util.List) ArrayList(java.util.ArrayList) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.GetCapabilitiesRequest) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) FeatureTypeType(net.opengis.wfs.v_2_0_0.FeatureTypeType) FeatureTypeListType(net.opengis.wfs.v_2_0_0.FeatureTypeListType) Wfs(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs) QName(javax.xml.namespace.QName) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) StreamSource(javax.xml.transform.stream.StreamSource) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) 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) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.DescribeFeatureTypeRequest) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SecurityLogger(ddf.security.audit.SecurityLogger)

Aggregations

MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)4 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)4 Metacard (ddf.catalog.data.Metacard)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 List (java.util.List)3 StreamSource (javax.xml.transform.stream.StreamSource)3 XmlSchema (org.apache.ws.commons.schema.XmlSchema)3 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 SecurityLogger (ddf.security.audit.SecurityLogger)2 SecurityManager (ddf.security.service.SecurityManager)2 FeatureTypeListType (net.opengis.wfs.v_2_0_0.FeatureTypeListType)2 FeatureTypeType (net.opengis.wfs.v_2_0_0.FeatureTypeType)2 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)2 SecureCxfClientFactory (org.codice.ddf.cxf.SecureCxfClientFactory)2 ClientBuilderImpl (org.codice.ddf.cxf.client.impl.ClientBuilderImpl)2 OAuthSecurity (org.codice.ddf.cxf.oauth.OAuthSecurity)2 SamlSecurity (org.codice.ddf.security.jaxrs.SamlSecurity)2