Search in sources :

Example 91 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class FanoutCatalogFrameworkTest method testReplaceSourceId.

@Test
public void testReplaceSourceId() {
    QueryRequest request = new QueryRequestImpl(null);
    List<Result> results = new ArrayList<Result>();
    MetacardImpl newCard1 = new MetacardImpl();
    newCard1.setSourceId(OLD_SOURCE_ID);
    ResultImpl result1 = new ResultImpl(newCard1);
    MetacardImpl newCard2 = new MetacardImpl();
    newCard2.setSourceId(OLD_SOURCE_ID);
    ResultImpl result2 = new ResultImpl(newCard2);
    results.add(result1);
    results.add(result2);
    QueryResponse response = new QueryResponseImpl(request, results, 2);
    QueryResponse newResponse = framework.getQueryOperations().replaceSourceId(response);
    assertNotNull(newResponse);
    List<Result> newResults = newResponse.getResults();
    assertNotNull(newResults);
    assertEquals(2, newResults.size());
    Metacard card = new MetacardImpl();
    for (Result newResult : newResults) {
        card = newResult.getMetacard();
        assertNotNull(card);
        assertEquals(NEW_SOURCE_ID, card.getSourceId());
    }
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 92 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class TestRegistryStore method testRegistryQueryNullGetId.

@Test
public void testRegistryQueryNullGetId() throws Exception {
    Filter filter = filterBuilder.attribute(Metacard.TAGS).is().like().text(RegistryConstants.REGISTRY_TAG);
    queryResults.add(new ResultImpl(getDefaultMetacard()));
    QueryRequest testRequest = new QueryRequestImpl(new QueryImpl(filter));
    registryStore.setRegistryId("registryId");
    SourceResponse answer = registryStore.query(testRequest);
    List<Result> testResults = answer.getResults();
    assertThat(testResults.size(), is(1));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 93 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class TestRegistryStore method setup.

@Before
public void setup() throws Exception {
    parser = new XmlParser();
    marshaller = new MetacardMarshaller(new XmlParser());
    context = mock(BundleContext.class);
    provider = mock(Converter.class);
    cswSourceConfiguration = new CswSourceConfiguration();
    factory = mock(SecureCxfClientFactory.class);
    transformer = mock(TransformerManager.class);
    encryptionService = mock(EncryptionService.class);
    configAdmin = mock(ConfigurationAdmin.class);
    configuration = mock(Configuration.class);
    subject = mock(Subject.class);
    queryResults = new ArrayList<>();
    registryStore = spy(new RegistryStoreImpl(context, cswSourceConfiguration, provider, factory, encryptionService) {

        @Override
        protected void validateOperation() {
        }

        @Override
        public boolean isAvailable() {
            return availability;
        }

        @Override
        protected SourceResponse query(QueryRequest queryRequest, ElementSetType elementSetName, List<QName> elementNames, Csw csw) throws UnsupportedQueryException {
            if (queryResults == null) {
                throw new UnsupportedQueryException("Test - Bad Query");
            }
            return new SourceResponseImpl(queryRequest, queryResults);
        }

        @Override
        protected CapabilitiesType getCapabilities() {
            return mock(CapabilitiesType.class);
        }

        @Override
        public void configureCswSource() {
        }

        ;

        @Override
        protected Subject getSystemSubject() {
            return subject;
        }

        @Override
        BundleContext getBundleContext() {
            return context;
        }
    });
    registryStore.setFilterBuilder(filterBuilder);
    registryStore.setFilterAdapter(filterAdapter);
    registryStore.setConfigAdmin(configAdmin);
    registryStore.setMetacardMarshaller(new MetacardMarshaller(parser));
    registryStore.setSchemaTransformerManager(transformer);
    registryStore.setAutoPush(true);
    registryStore.setRegistryUrl("http://test.url:0101/example");
    properties = new Hashtable<>();
    properties.put(RegistryStoreImpl.ID, "registryId");
    registryStore.setMetacardMarshaller(marshaller);
    when(configAdmin.getConfiguration(any())).thenReturn(configuration);
    when(configuration.getProperties()).thenReturn(properties);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) XmlParser(org.codice.ddf.parser.xml.XmlParser) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) Configuration(org.osgi.service.cm.Configuration) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) QueryRequest(ddf.catalog.operation.QueryRequest) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Subject(ddf.security.Subject) EncryptionService(ddf.security.encryption.EncryptionService) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) Converter(com.thoughtworks.xstream.converters.Converter) List(java.util.List) ArrayList(java.util.ArrayList) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 94 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class TestRegistryStore method registryInfoQuery.

@Test
public void registryInfoQuery() throws Exception {
    assertThat(registryStore.getRegistryId(), is(""));
    queryResults.add(new ResultImpl(getDefaultMetacard()));
    registryStore.registryInfoQuery();
    ArgumentCaptor<QueryRequest> captor = ArgumentCaptor.forClass(QueryRequest.class);
    verify(registryStore).query(captor.capture());
    assertThat(captor.getValue().getPropertyValue(SecurityConstants.SECURITY_SUBJECT), notNullValue());
    assertThat(registryStore.getRegistryId(), is("registryId"));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ResultImpl(ddf.catalog.data.impl.ResultImpl) Test(org.junit.Test)

Example 95 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class QueryApplication method executeCqlQuery.

private CqlQueryResponse executeCqlQuery(CqlRequest cqlRequest) throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    QueryRequest request = cqlRequest.createQueryRequest(catalogFramework.getId(), filterBuilder);
    Stopwatch stopwatch = Stopwatch.createStarted();
    QueryResponse response = catalogFramework.query(request);
    stopwatch.stop();
    return new CqlQueryResponse(cqlRequest.getId(), request, response, cqlRequest.getSource(), stopwatch.elapsed(TimeUnit.MILLISECONDS), cqlRequest.isNormalize(), filterAdapter, actionRegistry);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) CqlQueryResponse(org.codice.ddf.catalog.ui.query.cql.CqlQueryResponse) QueryResponse(ddf.catalog.operation.QueryResponse) Stopwatch(com.google.common.base.Stopwatch) CqlQueryResponse(org.codice.ddf.catalog.ui.query.cql.CqlQueryResponse)

Aggregations

QueryRequest (ddf.catalog.operation.QueryRequest)153 Test (org.junit.Test)98 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)86 QueryImpl (ddf.catalog.operation.impl.QueryImpl)66 QueryResponse (ddf.catalog.operation.QueryResponse)57 ArrayList (java.util.ArrayList)41 SourceResponse (ddf.catalog.operation.SourceResponse)39 Metacard (ddf.catalog.data.Metacard)33 Result (ddf.catalog.data.Result)31 Filter (org.opengis.filter.Filter)31 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)30 Query (ddf.catalog.operation.Query)29 Source (ddf.catalog.source.Source)24 FederationException (ddf.catalog.federation.FederationException)20 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)15 InputStream (java.io.InputStream)15 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)13 SortByImpl (ddf.catalog.filter.impl.SortByImpl)11 HashMap (java.util.HashMap)11