Search in sources :

Example 1 with GeotoolsFilterAdapterImpl

use of ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl 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 GeotoolsFilterAdapterImpl

use of ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl in project alliance by codice.

the class NsiliSourceTest method buildSource.

private NsiliSource buildSource() throws Exception {
    NsiliSource source;
    Nsili nsili = mock(Nsili.class);
    Response clientResponse = mock(Response.class);
    when(clientResponse.getEntity()).thenReturn("");
    InputStream mockInputStream = mock(InputStream.class);
    when(nsili.getIorFile()).thenReturn(mockInputStream);
    SecureCxfClientFactory factory = getMockFactory(nsili);
    HashMap<String, String[]> resultAttributes = new HashMap<>();
    HashMap<String, List<String>> sortableAttributes = generateMockSortableAttributes();
    source = Mockito.spy(new NsiliSource(factory, resultAttributes, sortableAttributes, new NsiliFilterDelegate(attributeInformationMap, NsiliConstants.NSIL_ALL_VIEW), orb));
    source.setIorUrl(IOR_URL);
    source.setServerUsername(NsiliSource.SERVER_USERNAME);
    source.setServerPassword(NsiliSource.SERVER_PASSWORD);
    source.setMaxHitCount(MAX_HIT_COUNT);
    source.setId(ID);
    source.setPollInterval(POLL_INTERVAL);
    source.setDataModelMgr(getMockDataModelMgr());
    source.setCatalogMgr(getMockCatalogMgr());
    source.setFilterAdapter(new GeotoolsFilterAdapterImpl());
    source.setNumberWorkerThreads(6);
    source.setAdditionalQueryParams("and (not NSIL_PRODUCT:NSIL_CARD.status = 'OBSOLETE')");
    // Suppress CORBA communications to test refresh
    doNothing().when(source).init();
    when(mockAvailabilityTask.isAvailable()).thenReturn(true);
    source.setAvailabilityTask(mockAvailabilityTask);
    return source;
}
Also used : Nsili(org.codice.alliance.nsili.common.Nsili) Response(javax.ws.rs.core.Response) SourceResponse(ddf.catalog.operation.SourceResponse) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) HashMap(java.util.HashMap) InputStream(java.io.InputStream) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)

Example 3 with GeotoolsFilterAdapterImpl

use of ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl in project ddf by codice.

the class MetacardValidityFilterPluginTest method setUp.

@Before
public void setUp() {
    filterAdapter = new GeotoolsFilterAdapterImpl();
    filterBuilder = new GeotoolsFilterBuilder();
    errorsValidationQueryDelegate = new ValidationQueryDelegate(Validation.VALIDATION_ERRORS);
    warningsValidationQueryDelegate = new ValidationQueryDelegate(Validation.VALIDATION_WARNINGS);
    metacardValidityFilterPlugin = new MetacardValidityFilterPlugin(filterBuilder, Collections.singletonList(LOCAL_PROVIDER));
    metacardValidityFilterPlugin.setPermissions(new PermissionsImpl());
    metacardValidityFilterPlugin.setAttributeMap(ATTRIBUTE_MAPPING);
}
Also used : PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) Before(org.junit.Before)

Example 4 with GeotoolsFilterAdapterImpl

use of ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl in project ddf by codice.

the class CopyFilterDelegateTest method testFilterModification.

@Test
public void testFilterModification() {
    Filter filterIn = FF.equals(TEST_PROPERTY, FOO_LITERAL);
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    FilterDelegate<Filter> delegate = new FilterModifierDelegate(filterBuilder);
    FilterAdapter fa = new GeotoolsFilterAdapterImpl();
    Filter modifiedFilter = null;
    try {
        modifiedFilter = fa.adapt(filterIn, delegate);
    } catch (UnsupportedQueryException e) {
        fail(e.getMessage());
    }
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("testFeatureType");
    b.add(TEST_PROPERTY_VALUE, String.class);
    b.add("classification", String.class);
    SimpleFeatureType featureType = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    builder.add(FOO_LITERAL_VALUE);
    builder.add("UNCLASS");
    SimpleFeature feature = builder.buildFeature("test");
    assertTrue(modifiedFilter.evaluate(feature));
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FilterAdapter(ddf.catalog.filter.FilterAdapter) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Test(org.junit.Test)

Example 5 with GeotoolsFilterAdapterImpl

use of ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl in project ddf by codice.

the class CopyFilterDelegateTest method assertFilterEquals.

private void assertFilterEquals(Filter filterIn) {
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    FilterDelegate<Filter> delegate = new CopyFilterDelegate(filterBuilder);
    FilterAdapter fa = new GeotoolsFilterAdapterImpl();
    Filter filterCopy = null;
    try {
        filterCopy = fa.adapt(filterIn, delegate);
    } catch (UnsupportedQueryException e) {
        fail(e.getMessage());
    }
    assertNotNull(filterCopy);
    // Verify object references are different, indicating a copy was made of the filter
    assertNotSame(filterIn, filterCopy);
    assertFilterContentsEqual(filterIn, filterCopy);
}
Also used : Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FilterAdapter(ddf.catalog.filter.FilterAdapter) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)

Aggregations

GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)25 FilterAdapter (ddf.catalog.filter.FilterAdapter)10 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)10 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)9 ArrayList (java.util.ArrayList)7 FilterBuilder (ddf.catalog.filter.FilterBuilder)6 Test (org.junit.Test)6 List (java.util.List)5 QName (javax.xml.namespace.QName)5 Filter (org.opengis.filter.Filter)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 SecureCxfClientFactory (org.codice.ddf.cxf.SecureCxfClientFactory)4 Metacard (ddf.catalog.data.Metacard)3 SecurityLogger (ddf.security.audit.SecurityLogger)3 SecurityManager (ddf.security.service.SecurityManager)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 StreamSource (javax.xml.transform.stream.StreamSource)3 BeforeClass (org.junit.BeforeClass)3 FilterToTextDelegate (ddf.catalog.filter.delegate.FilterToTextDelegate)2 QueryRequest (ddf.catalog.operation.QueryRequest)2