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));
}
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));
}
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;
}
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;
}
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));
}
Aggregations