Search in sources :

Example 46 with QueryRequest

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

the class TestQueryMonitor method testQueryMonitorAddActiveSearchNullParameters.

@Test
public void testQueryMonitorAddActiveSearchNullParameters() {
    QueryRequest mockQR = mock(QueryRequest.class);
    propertyMap = new ConcurrentHashMap<>();
    when(mockQR.getProperties()).thenReturn(propertyMap);
    when(mockQR.toString()).thenReturn(QUERY_REQUEST_TEXT);
    as = new ActiveSearch(null, null, null, null);
    qmpi.addActiveSearch(as);
    Map<UUID, ActiveSearch> activeSearchTable = qmpi.getActiveSearches();
    assertThat(activeSearchTable, hasValue(as));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) UUID(java.util.UUID) Test(org.junit.Test)

Example 47 with QueryRequest

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

the class DuplicationValidator method query.

private SourceResponse query(Set<Attribute> attributes, String originalId) {
    final Filter filter = filterBuilder.allOf(filterBuilder.anyOf(buildFilters(attributes)), filterBuilder.not(filterBuilder.attribute(Metacard.ID).is().equalTo().text(originalId)));
    LOGGER.debug("filter {}", filter);
    QueryImpl query = new QueryImpl(filter);
    query.setRequestsTotalResultsCount(false);
    QueryRequest request = new QueryRequestImpl(query);
    SourceResponse response = null;
    try {
        response = catalogFramework.query(request);
    } catch (FederationException | SourceUnavailableException | UnsupportedQueryException e) {
        LOGGER.debug("Query failed ", e);
    }
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) 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) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException)

Example 48 with QueryRequest

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

the class ResourceCacheService method queryForMetacard.

private Optional<Metacard> queryForMetacard(String metacardId) {
    Filter filter = frameworkProperties.getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(metacardId);
    QueryRequest queryRequest = new QueryRequestImpl(new QueryImpl(filter), true);
    QueryResponse queryResponse = null;
    try {
        queryResponse = catalogFramework.query(queryRequest);
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        LOGGER.error("Unable to lookup metacard for metacard id [{}].", metacardId);
        return Optional.empty();
    }
    return queryResponse != null && queryResponse.getResults().size() == 1 ? Optional.of(queryResponse.getResults().get(0).getMetacard()) : Optional.empty();
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException)

Example 49 with QueryRequest

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

the class ValidationQueryFactoryTest method testSearchErrorsAndNotWarnings.

@Test
public void testSearchErrorsAndNotWarnings() throws UnsupportedQueryException {
    QueryImpl query = new QueryImpl(filterBuilder.attribute(Metacard.MODIFIED).is().equalTo().text("sample"));
    QueryRequest returnQuery = validationQueryFactory.getQueryRequestWithValidationFilter(new QueryRequestImpl(query), true, false);
    assertThat(filterAdapter.adapt(returnQuery.getQuery(), testValidationQueryDelegate), is(true));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 50 with QueryRequest

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

the class ValidationQueryFactoryTest method testSearchInvalidAndNotShow.

@Test
public void testSearchInvalidAndNotShow() throws StopProcessingException, PluginExecutionException, UnsupportedQueryException {
    QueryImpl query = new QueryImpl(filterBuilder.attribute(Validation.VALIDATION_WARNINGS).is().equalTo().text("sample"));
    assertThat(filterAdapter.adapt(query, testValidationQueryDelegate), is(true));
    QueryRequest sendQuery = new QueryRequestImpl(query);
    QueryRequest returnQuery = validationQueryFactory.getQueryRequestWithValidationFilter(sendQuery, false, false);
    assertThat(filterAdapter.adapt(returnQuery.getQuery(), testValidationQueryDelegate), is(true));
    assertThat(sendQuery, is(returnQuery));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

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