Search in sources :

Example 71 with QueryRequest

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

the class ConfluenceSourceTest method testNonConfluenceQuery.

@Test
public void testNonConfluenceQuery() throws Exception {
    QueryRequest request = new QueryRequestImpl(new QueryImpl(builder.attribute("metacard-tags").is().like().text("nonConfluecneTag"), 1, 1, new SortByImpl("title", SortOrder.DESCENDING), false, 1000));
    SourceResponse response = confluence.query(request);
    assertThat(response.getHits(), is(0L));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 72 with QueryRequest

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

the class ConfluenceSourceTest method testQueryWithSpace.

@Test
public void testQueryWithSpace() throws Exception {
    QueryRequest request = new QueryRequestImpl(new QueryImpl(builder.attribute("anyText").is().like().text("searchValue"), 1, 1, new SortByImpl("title", SortOrder.DESCENDING), false, 1000));
    InputStream entity = new ByteArrayInputStream(JSON_RESPONSE.getBytes(StandardCharsets.UTF_8));
    confluence.setConfluenceSpaces(Collections.singletonList("DDF"));
    when(clientResponse.getEntity()).thenReturn(entity);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    SourceResponse response = confluence.query(request);
    assertThat(response.getHits(), is(1L));
    Metacard mcard = response.getResults().get(0).getMetacard();
    assertThat(mcard, notNullValue());
    assertThat(mcard.getAttribute("attrib1").getValue(), is("val1"));
    assertThat(mcard.getAttribute("attrib2").getValues().size(), is(3));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) SortByImpl(ddf.catalog.filter.impl.SortByImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 73 with QueryRequest

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

the class RemoveAllCommand method executeRemoveAllFromStore.

private Object executeRemoveAllFromStore() throws Exception {
    CatalogFacade catalog = getCatalog();
    QueryRequest firstQuery = getIntendedQuery(filterBuilder, true);
    QueryRequest subsequentQuery = getIntendedQuery(filterBuilder, false);
    long totalAmountDeleted = 0;
    long start = System.currentTimeMillis();
    SourceResponse response;
    try {
        response = catalog.query(firstQuery);
    } catch (UnsupportedQueryException e) {
        firstQuery = getAlternateQuery(filterBuilder, true);
        subsequentQuery = getAlternateQuery(filterBuilder, false);
        response = catalog.query(firstQuery);
    }
    if (response == null) {
        printErrorMessage("No response from Catalog.");
        return null;
    }
    if (needsAlternateQueryAndResponse(response)) {
        firstQuery = getAlternateQuery(filterBuilder, true);
        subsequentQuery = getAlternateQuery(filterBuilder, false);
        response = catalog.query(firstQuery);
    }
    String totalAmount = getTotalAmount(response.getHits());
    while (response.getResults().size() > 0) {
        // Add metacard ids to string array
        List<String> ids = response.getResults().stream().filter(Objects::nonNull).map(Result::getMetacard).filter(Objects::nonNull).map(Metacard::getId).collect(Collectors.toList());
        // Delete the records
        DeleteRequestImpl request = new DeleteRequestImpl(ids.toArray(new String[ids.size()]));
        DeleteResponse deleteResponse = catalog.delete(request);
        int amountDeleted = deleteResponse.getDeletedMetacards().size();
        totalAmountDeleted += amountDeleted;
        console.print(String.format(PROGRESS_FORMAT, totalAmountDeleted, totalAmount));
        console.flush();
        // Break out if there are no more records to delete
        if (amountDeleted < batchSize || batchSize < 1) {
            break;
        }
        // Re-query when necessary
        response = catalog.query(subsequentQuery);
    }
    long end = System.currentTimeMillis();
    String info = String.format(" %d file(s) removed in %3.3f seconds%n", totalAmountDeleted, (end - start) / MS_PER_SECOND);
    LOGGER.info(info);
    LOGGER.info(totalAmountDeleted + " files removed using cache:removeAll command");
    console.println();
    console.print(info);
    return null;
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) Objects(java.util.Objects) CatalogFacade(org.codice.ddf.commands.catalog.facade.CatalogFacade)

Example 74 with QueryRequest

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

the class MigrateCommand method query.

@Override
protected SourceResponse query(CatalogFacade framework, Filter filter, int startIndex, long querySize) {
    QueryImpl query = new QueryImpl(filter);
    query.setRequestsTotalResultsCount(true);
    query.setPageSize((int) querySize);
    query.setSortBy(new SortByImpl(Metacard.MODIFIED, SortOrder.DESCENDING));
    QueryRequest queryRequest = new QueryRequestImpl(query);
    query.setStartIndex(startIndex);
    SourceResponse response;
    try {
        LOGGER.debug("Querying with startIndex: {}", startIndex);
        response = framework.query(queryRequest);
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        printErrorMessage(String.format("Received error from Frameworks: %s%n", e.getMessage()));
        return null;
    }
    if (response.getProcessingDetails() != null && !response.getProcessingDetails().isEmpty()) {
        for (SourceProcessingDetails details : response.getProcessingDetails()) {
            LOGGER.debug("Got Issues: {}", details.getWarnings());
        }
        return null;
    }
    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) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) SourceProcessingDetails(ddf.catalog.operation.SourceProcessingDetails)

Example 75 with QueryRequest

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

the class ReplicateCommandTest method verifyReplicate.

private void verifyReplicate(int actualMaxMetacards, String sortBy) throws Exception {
    ArgumentCaptor<QueryRequest> argument = ArgumentCaptor.forClass(QueryRequest.class);
    verify(catalogFramework, times((int) Math.ceil((double) actualMaxMetacards / (double) replicateCommand.batchSize))).query(argument.capture());
    QueryRequest request = argument.getValue();
    assertThat(request, notNullValue());
    Query query = request.getQuery();
    assertThat(query, notNullValue());
    assertThat(query.getPageSize(), is(replicateCommand.batchSize));
    if (replicateCommand.multithreaded == 1) {
        assertThat(query.getStartIndex(), is((((int) ((double) (actualMaxMetacards - 1) / (double) replicateCommand.batchSize)) * replicateCommand.batchSize + 1)));
    }
    assertThat(query.getSortBy().getPropertyName().getPropertyName(), is(sortBy));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) Query(ddf.catalog.operation.Query)

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