Search in sources :

Example 76 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl 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 77 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl 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 78 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl 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)

Example 79 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.

the class ValidationQueryFactoryTest method testSearchAnyAndShow.

@Test
public void testSearchAnyAndShow() throws StopProcessingException, PluginExecutionException, UnsupportedQueryException {
    QueryImpl query = new QueryImpl(filterBuilder.attribute(Metacard.MODIFIED).is().equalTo().text("sample"));
    assertThat(filterAdapter.adapt(query, testValidationQueryDelegate), is(false));
    QueryRequest sendQuery = new QueryRequestImpl(query);
    QueryRequest returnQuery = validationQueryFactory.getQueryRequestWithValidationFilter(sendQuery, true, true);
    assertThat(filterAdapter.adapt(returnQuery.getQuery(), testValidationQueryDelegate), is(false));
    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)

Example 80 with QueryRequestImpl

use of ddf.catalog.operation.impl.QueryRequestImpl in project ddf by codice.

the class QueryOperations method doQuery.

/**
     * Executes a query using the specified {@link QueryRequest} and {@link FederationStrategy}.
     * Based on the isEnterprise and sourceIds list in the query request, the federated query may
     * include the local provider and {@link ConnectedSource}s.
     *
     * @param queryRequest the {@link QueryRequest}
     * @param strategy     the {@link FederationStrategy}
     * @return the {@link QueryResponse}
     * @throws FederationException
     */
QueryResponse doQuery(QueryRequest queryRequest, FederationStrategy strategy) throws FederationException {
    Set<String> sourceIds = getCombinedIdSet(queryRequest);
    LOGGER.debug("source ids: {}", sourceIds);
    QuerySources querySources = new QuerySources(frameworkProperties).initializeSources(this, queryRequest, sourceIds).addConnectedSources(this, frameworkProperties).addCatalogProvider(this);
    if (querySources.isEmpty()) {
        // TODO change to SourceUnavailableException
        throw new FederationException("SiteNames could not be resolved due to invalid site names, none of the sites " + "were available, or the current subject doesn't have permission to access the sites.");
    }
    LOGGER.debug("Calling strategy.federate()");
    Query originalQuery = queryRequest.getQuery();
    if (originalQuery != null && originalQuery.getTimeoutMillis() <= 0) {
        Query modifiedQuery = new QueryImpl(originalQuery, originalQuery.getStartIndex(), originalQuery.getPageSize(), originalQuery.getSortBy(), originalQuery.requestsTotalResultsCount(), queryTimeoutMillis);
        queryRequest = new QueryRequestImpl(modifiedQuery, queryRequest.isEnterprise(), queryRequest.getSourceIds(), queryRequest.getProperties());
    }
    QueryResponse response = strategy.federate(querySources.sourcesToQuery, queryRequest);
    frameworkProperties.getQueryResponsePostProcessor().processResponse(response);
    return addProcessingDetails(querySources.exceptions, response);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) FederationException(ddf.catalog.federation.FederationException)

Aggregations

QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)216 QueryImpl (ddf.catalog.operation.impl.QueryImpl)187 Test (org.junit.Test)142 Filter (org.opengis.filter.Filter)103 SourceResponse (ddf.catalog.operation.SourceResponse)100 QueryRequest (ddf.catalog.operation.QueryRequest)86 Metacard (ddf.catalog.data.Metacard)72 Result (ddf.catalog.data.Result)60 QueryResponse (ddf.catalog.operation.QueryResponse)46 ArrayList (java.util.ArrayList)46 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)32 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)29 Query (ddf.catalog.operation.Query)28 HashMap (java.util.HashMap)28 FederationException (ddf.catalog.federation.FederationException)27 Serializable (java.io.Serializable)27 Matchers.containsString (org.hamcrest.Matchers.containsString)22 Matchers.anyString (org.mockito.Matchers.anyString)20 SortByImpl (ddf.catalog.filter.impl.SortByImpl)19 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)18