use of org.geotools.filter.text.cql2.CQLException in project ddf by codice.
the class SearchService method executeQuery.
/**
* Creates the query requests for each source and hands off the query to the Search Controller
*
* @param queryMessage
* - JSON message received from cometd
*/
public void executeQuery(Map<String, Object> queryMessage, Subject subject) {
String sources = castObject(String.class, queryMessage.get(SOURCES));
Long maxTimeout = castObject(Long.class, queryMessage.get(MAX_TIMEOUT));
Long startIndex = castObject(Long.class, queryMessage.get(START_INDEX));
Long count = castObject(Long.class, queryMessage.get(COUNT));
String cql = castObject(String.class, queryMessage.get(CQL_FILTER));
String sort = castObject(String.class, queryMessage.get(SORT));
String id = castObject(String.class, queryMessage.get(ID));
Set<String> sourceIds = getSourceIds(sources);
Filter filter = null;
try {
if (StringUtils.isNotBlank(cql)) {
filter = ECQL.toFilter(cql);
}
} catch (CQLException e) {
LOGGER.debug("Unable to parse CQL filter", e);
return;
}
Query query = createQuery(filter, startIndex, count, sort, maxTimeout);
SearchRequest searchRequest = new SearchRequest(sourceIds, query, id);
try {
// Hand off to the search controller for the actual query
searchController.executeQuery(searchRequest, serverSession, subject);
} catch (Exception e) {
LOGGER.debug("Exception while executing a query", e);
}
}
use of org.geotools.filter.text.cql2.CQLException in project ddf by codice.
the class PersistentStoreImpl method get.
@Override
public // Returned Map will have suffixes in the key names - client is responsible for handling them
List<Map<String, Object>> get(String type, String cql) throws PersistenceException {
if (StringUtils.isBlank(type)) {
throw new PersistenceException("The type of object(s) to retrieve must be non-null and not blank, e.g., notification, metacard, etc.");
}
List<Map<String, Object>> results = new ArrayList<>();
// Set Solr Core name to type and create/connect to Solr Core
SolrClient solrClient = getSolrClient(type);
if (solrClient == null) {
throw new PersistenceException("Unable to create Solr client.");
}
SolrQueryFilterVisitor visitor = new SolrQueryFilterVisitor(solrClient, type);
try {
SolrQuery solrQuery;
// If not cql specified, then return all items
if (StringUtils.isBlank(cql)) {
solrQuery = new SolrQuery("*:*");
} else {
Filter filter = CQL.toFilter(cql);
solrQuery = (SolrQuery) filter.accept(visitor, null);
}
QueryResponse solrResponse = solrClient.query(solrQuery, METHOD.POST);
long numResults = solrResponse.getResults().getNumFound();
LOGGER.debug("numResults = {}", numResults);
SolrDocumentList docs = solrResponse.getResults();
for (SolrDocument doc : docs) {
PersistentItem result = new PersistentItem();
Collection<String> fieldNames = doc.getFieldNames();
for (String name : fieldNames) {
LOGGER.debug("field name = {} has value = {}", name, doc.getFieldValue(name));
if (name.endsWith(PersistentItem.TEXT_SUFFIX) && doc.getFieldValues(name).size() > 1) {
result.addProperty(name, doc.getFieldValues(name).stream().filter(s -> s instanceof String).map(s -> (String) s).collect(Collectors.toSet()));
} else if (name.endsWith(PersistentItem.XML_SUFFIX)) {
result.addXmlProperty(name, (String) doc.getFirstValue(name));
} else if (name.endsWith(PersistentItem.TEXT_SUFFIX)) {
result.addProperty(name, (String) doc.getFirstValue(name));
} else if (name.endsWith(PersistentItem.LONG_SUFFIX)) {
result.addProperty(name, (Long) doc.getFirstValue(name));
} else if (name.endsWith(PersistentItem.INT_SUFFIX)) {
result.addProperty(name, (Integer) doc.getFirstValue(name));
} else if (name.endsWith(PersistentItem.DATE_SUFFIX)) {
result.addProperty(name, (Date) doc.getFirstValue(name));
} else if (name.endsWith(PersistentItem.BINARY_SUFFIX)) {
result.addProperty(name, (byte[]) doc.getFirstValue(name));
} else {
LOGGER.debug("Not adding field {} because it has invalid suffix", name);
}
}
results.add(result);
}
} catch (CQLException e) {
throw new PersistenceException("CQLException while getting Solr data with cql statement " + cql, e);
} catch (SolrServerException | IOException e) {
throw new PersistenceException("SolrServerException while getting Solr data with cql statement " + cql, e);
}
return results;
}
use of org.geotools.filter.text.cql2.CQLException in project ddf by codice.
the class RemoveCommand method executeRemoveFromStore.
private Object executeRemoveFromStore() throws CatalogCommandException {
try {
int batchCount = 0;
int deletedCount = 0;
if (CollectionUtils.isNotEmpty(ids) && !hasFilter()) {
deletedCount = deletedIdsPassedAsArguments();
}
if (hasFilter()) {
QueryRequestImpl queryRequest = new QueryRequestImpl(new QueryImpl(getFilter()), false);
String[] idsToDelete = getNextQueryBatch(queryRequest);
while (idsToDelete.length > 0) {
if (CollectionUtils.isNotEmpty(ids)) {
idsToDelete = Arrays.asList(idsToDelete).stream().filter(id -> ids.contains(id)).toArray(String[]::new);
}
DeleteRequestImpl deleteRequest = new DeleteRequestImpl(idsToDelete);
LOGGER.debug("Attempting to delete {} metacards from batch {}", idsToDelete.length, ++batchCount);
DeleteResponse deleteResponse = catalogFramework.delete(deleteRequest);
deletedCount += deleteResponse.getDeletedMetacards().size();
idsToDelete = getNextQueryBatch(queryRequest);
}
}
if (deletedCount > 0) {
printSuccessMessage(deletedCount + " documents successfully deleted.");
LOGGER.debug("{} documents removed using catalog:remove command", deletedCount);
} else {
printErrorMessage("No documents match provided IDs or filter");
LOGGER.debug("No documents deleted using the catalog:remove command");
}
} catch (IngestException | SourceUnavailableException | ParseException | CQLException e) {
throw new CatalogCommandException("Error executing catalog:remove", e);
}
return null;
}
use of org.geotools.filter.text.cql2.CQLException in project hale by halestudio.
the class FilterGeoECqlImpl method createFilter.
@Override
protected Filter createFilter(String filterTerm) throws CQLException {
CQLException filterException = null;
try {
return ECQL.toFilter(filterTerm);
} catch (CQLException e) {
filterException = e;
}
// Try if filterTerm can be evaluated as an Expression and if so,
// use it in a EqualsTrue filter. This is the same as if
// "= true" were added to the filter term.
Expression expr;
try {
expr = ECQL.toExpression(filterTerm);
return new EqualsTrue(expr);
} catch (CQLException e) {
throw filterException;
}
}
use of org.geotools.filter.text.cql2.CQLException in project hale by halestudio.
the class ModelClassMappingCell method buildMappingConditions.
private List<ModelMappingCondition> buildMappingConditions(List<Restriction> mappingRestrictions) throws TranslationException {
List<ModelMappingCondition> result;
try {
result = new ArrayList<ModelMappingCondition>();
for (Restriction restriction : mappingRestrictions) {
ModelMappingCondition condition = DIGESTER.translate(CQL.toFilter(restriction.getCqlStr()));
result.add(condition);
}
} catch (CQLException e) {
throw new TranslationException(e);
}
return result;
}
Aggregations