Search in sources :

Example 66 with QueryRequestImpl

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

the class RegistryIdPostIngestPlugin method init.

/**
     * Init method initializes the id sets from the catalog. If the catalog is not available it
     * will retry later.
     */
public void init() {
    try {
        List<Metacard> registryMetacards;
        Filter registryFilter = filterBuilder.anyOf(filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG), filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG_INTERNAL));
        QueryImpl query = new QueryImpl(registryFilter);
        query.setPageSize(PAGE_SIZE);
        QueryRequest request = new QueryRequestImpl(query);
        QueryResponse response = security.runAsAdminWithException(() -> security.runWithSubjectOrElevate(() -> catalogFramework.query(request)));
        if (response == null) {
            throw new PluginExecutionException("Failed to initialize RegistryIdPostIngestPlugin. Query for registry metacards came back null");
        }
        registryMetacards = response.getResults().stream().map(Result::getMetacard).collect(Collectors.toList());
        addIdsFromMetacards(registryMetacards);
    } catch (PrivilegedActionException | PluginExecutionException e) {
        LOGGER.debug("Error getting registry metacards. Will try again later");
        executorService.schedule(this::init, RETRY_INTERVAL, TimeUnit.SECONDS);
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) PrivilegedActionException(java.security.PrivilegedActionException) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) Result(ddf.catalog.data.Result)

Example 67 with QueryRequestImpl

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

the class TestWfsSource method testResultNumReturnedNegative.

@Test
public void testResultNumReturnedNegative() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
    //Setup
    final String TITLE = "title";
    final String searchPhrase = "*";
    final int pageSize = 1;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 3, false, true, -1);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(TITLE, SortOrder.DESCENDING);
    query.setSortBy(sortBy);
    QueryRequestImpl queryReq = new QueryRequestImpl(query);
    // Perform test
    SourceResponse resp = source.query(queryReq);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 68 with QueryRequestImpl

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

the class QueryRunnable method queryCatalog.

protected QueryResponse queryCatalog(String sourceId, SearchRequest searchRequest, Subject subject, Map<String, Serializable> properties) {
    Query query = searchRequest.getQuery();
    QueryResponse response = getEmptyResponse(sourceId);
    long startTime = System.currentTimeMillis();
    try {
        if (query != null) {
            List<String> sourceIds;
            if (sourceId == null) {
                sourceIds = new ArrayList<>(searchRequest.getSourceIds());
            } else {
                sourceIds = Collections.singletonList(sourceId);
            }
            QueryRequest request = new QueryRequestImpl(query, false, sourceIds, properties);
            if (subject != null) {
                LOGGER.debug("Adding {} property with value {} to request.", SecurityConstants.SECURITY_SUBJECT, subject);
                request.getProperties().put(SecurityConstants.SECURITY_SUBJECT, subject);
            }
            LOGGER.debug("Sending query: {}", query);
            response = searchController.getFramework().query(request);
        }
    } catch (UnsupportedQueryException | FederationException e) {
        LOGGER.info("Error executing query. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("Error executing query", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    } catch (SourceUnavailableException e) {
        LOGGER.info("Error executing query because the underlying source was unavailable. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("Error executing query because the underlying source was unavailable.", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    } catch (RuntimeException e) {
        // Account for any runtime exceptions and send back a server error
        // this prevents full stacktraces returning to the client
        // this allows for a graceful server error to be returned
        LOGGER.info("RuntimeException on executing query. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("RuntimeException on executing query", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    }
    long estimatedTime = System.currentTimeMillis() - startTime;
    response.getProperties().put("elapsed", estimatedTime);
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Example 69 with QueryRequestImpl

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

the class SolrCache method query.

@Override
public List<Metacard> query(Filter filter) throws UnsupportedQueryException {
    QueryRequest queryRequest = new QueryRequestImpl(new QueryImpl(filter), true);
    SourceResponse response = solrClientAdaptor.getSolrMetacardClient().query(queryRequest);
    return getMetacardsFromResponse(response);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Example 70 with QueryRequestImpl

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

the class CacheQueryFactory method getQueryRequestWithSourcesFilter.

QueryRequest getQueryRequestWithSourcesFilter(QueryRequest input) {
    QueryRequest queryWithSources = input;
    if (input.getSourceIds() != null) {
        List<Filter> sourceFilters = new ArrayList<>();
        for (String sourceId : input.getSourceIds()) {
            sourceFilters.add(builder.attribute(StringUtils.removeEnd(SolrCache.METACARD_SOURCE_NAME, SchemaFields.TEXT_SUFFIX)).is().equalTo().text(sourceId));
        }
        QueryImpl sourceQuery = new QueryImpl(builder.allOf(input.getQuery(), builder.anyOf(sourceFilters)));
        sourceQuery.setPageSize(input.getQuery().getPageSize());
        sourceQuery.setStartIndex(input.getQuery().getStartIndex());
        sourceQuery.setSortBy(input.getQuery().getSortBy());
        sourceQuery.setTimeoutMillis(input.getQuery().getTimeoutMillis());
        queryWithSources = new QueryRequestImpl(sourceQuery, input.isEnterprise(), input.getSourceIds(), input.getProperties());
    }
    return queryWithSources;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ArrayList(java.util.ArrayList)

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