use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class TestQueryImpl method testSetFilter.
/**
* Test method for {@link ddf.catalog.operation.impl.QueryImpl#setFilter(org.opengis.filter.Filter)}
* .
*/
@Test
public void testSetFilter() {
QueryImpl qi = new QueryImpl(filter1);
assertEquals(filter1, qi.getFilter());
qi.setFilter(filter2);
assertEquals(filter2, qi.getFilter());
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class TestQueryImpl method testQueryImpleFilterWithNullFilter.
@Test(expected = IllegalArgumentException.class)
public void testQueryImpleFilterWithNullFilter() {
Filter filter = null;
QueryImpl qi = new QueryImpl(filter);
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class RemoveCommand method executeRemoveFromStore.
private Object executeRemoveFromStore() throws Exception {
CatalogFacade catalogProvider = getCatalog();
if (hasFilter()) {
QueryImpl query = new QueryImpl(getFilter());
query.setRequestsTotalResultsCount(true);
query.setPageSize(-1);
Map<String, Serializable> properties = new HashMap<>();
properties.put("mode", "native");
SourceResponse queryResponse = catalogProvider.query(new QueryRequestImpl(query, properties));
final List<String> idsFromFilteredQuery = queryResponse.getResults().stream().map(result -> result.getMetacard().getId()).collect(Collectors.toList());
if (ids == null) {
ids = idsFromFilteredQuery;
} else {
ids = ids.stream().filter(id -> idsFromFilteredQuery.contains(id)).collect(Collectors.toList());
}
}
final int numberOfMetacardsToRemove = ids.size();
if (numberOfMetacardsToRemove > 0) {
printSuccessMessage("Found " + numberOfMetacardsToRemove + " metacards to remove.");
} else {
printErrorMessage("No records found meeting filter criteria.");
return null;
}
DeleteRequestImpl request = new DeleteRequestImpl(ids.toArray(new String[numberOfMetacardsToRemove]));
DeleteResponse response = catalogProvider.delete(request);
if (response.getDeletedMetacards().size() > 0) {
printSuccessMessage(ids + " successfully deleted.");
LOGGER.info(ids + " removed using catalog:remove command");
} else {
printErrorMessage(ids + " could not be deleted.");
LOGGER.info(ids + " could not be deleted using catalog:remove command");
}
return null;
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class SearchCommand method executeSearchStore.
private Object executeSearchStore(Filter filter) throws Exception {
String formatString = "%1$-33s %2$-26s %3$-" + TITLE_MAX_LENGTH + "s %4$-" + EXCERPT_MAX_LENGTH + "s%n";
CatalogFacade catalogProvider = getCatalog();
QueryImpl query = new QueryImpl(filter);
query.setRequestsTotalResultsCount(true);
if (numberOfItems > -1) {
query.setPageSize(numberOfItems);
}
long start = System.currentTimeMillis();
SourceResponse response = catalogProvider.query(new QueryRequestImpl(query));
long end = System.currentTimeMillis();
int size = 0;
if (response.getResults() != null) {
size = response.getResults().size();
}
console.println();
console.printf(" %d result(s) out of %s%d%s in %3.3f seconds", (size), Ansi.ansi().fg(Ansi.Color.CYAN).toString(), response.getHits(), Ansi.ansi().reset().toString(), (end - start) / MS_PER_SECOND);
console.printf(formatString, "", "", "", "");
printHeaderMessage(String.format(formatString, ID, DATE, TITLE, EXCERPT));
for (Result result : response.getResults()) {
Metacard metacard = result.getMetacard();
String title = (metacard.getTitle() != null ? metacard.getTitle() : "N/A");
String excerpt = "N/A";
String modifiedDate = "";
if (searchPhrase != null) {
if (metacard.getMetadata() != null) {
XPathHelper helper = new XPathHelper(metacard.getMetadata());
String indexedText = helper.getDocument().getDocumentElement().getTextContent();
indexedText = indexedText.replaceAll("\\r\\n|\\r|\\n", " ");
String normalizedSearchPhrase = searchPhrase.replaceAll("\\*", "");
int index = -1;
if (caseSensitive) {
index = indexedText.indexOf(normalizedSearchPhrase);
} else {
index = indexedText.toLowerCase().indexOf(normalizedSearchPhrase.toLowerCase());
}
if (index != -1) {
int contextLength = (EXCERPT_MAX_LENGTH - normalizedSearchPhrase.length() - 8) / 2;
excerpt = "..." + indexedText.substring(Math.max(index - contextLength, 0), index);
excerpt = excerpt + Ansi.ansi().fg(Ansi.Color.GREEN).toString();
excerpt = excerpt + indexedText.substring(index, index + normalizedSearchPhrase.length());
excerpt = excerpt + Ansi.ansi().reset().toString();
excerpt = excerpt + indexedText.substring(index + normalizedSearchPhrase.length(), Math.min(indexedText.length(), index + normalizedSearchPhrase.length() + contextLength)) + "...";
}
}
}
if (metacard.getModifiedDate() != null) {
modifiedDate = new DateTime(metacard.getModifiedDate().getTime()).toString(DATETIME_FORMATTER);
}
console.printf(formatString, metacard.getId(), modifiedDate, title.substring(0, Math.min(title.length(), TITLE_MAX_LENGTH)), excerpt);
}
return null;
}
use of ddf.catalog.operation.impl.QueryImpl 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;
}
Aggregations