use of org.geotools.filter.text.cql2.CQL in project ddf by codice.
the class PersistentStoreImpl method get.
@Override
public List<Map<String, Object>> get(String type, String cql, int startIndex, int pageSize) 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.");
}
if (startIndex < 0) {
throw new IllegalArgumentException("The start index must be nonnegative.");
}
if (pageSize <= 0 || pageSize > MAX_PAGE_SIZE) {
throw new IllegalArgumentException(String.format("The page size must be greater than 0 and less than or equal to %d.", MAX_PAGE_SIZE));
}
// Set Solr Core name to type and create/connect to Solr Core
SolrClient solrClient = getSolrClient(type);
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 = ECQL.toFilter(cql);
solrQuery = (SolrQuery) filter.accept(visitor, null);
}
if (solrQuery == null) {
throw new PersistenceException("Unsupported query " + cql);
}
solrQuery.setRows(pageSize);
solrQuery.setStart(startIndex);
solrQuery.addSort(PersistentItem.ID, SolrQuery.ORDER.asc);
QueryResponse solrResponse = solrClient.query(solrQuery, METHOD.POST);
long numResults = solrResponse.getResults().getNumFound();
LOGGER.debug("numResults = {}", numResults);
final SolrDocumentList docs = solrResponse.getResults();
return documentListToResultList(docs);
} catch (CQLException e) {
throw new PersistenceException("CQLException while getting Solr data with cql statement " + cql, e);
} catch (SolrServerException | SolrException | IOException e) {
throw new PersistenceException("Exception while getting Solr data with cql statement " + cql, e);
}
}
use of org.geotools.filter.text.cql2.CQL in project hale by halestudio.
the class FilterTest method testComplexInstancesECQL.
@Test
public void testComplexInstancesECQL() throws Exception {
/*
* SchemaReader reader = new XmlSchemaReader();
* reader.setSharedTypes(null); reader.setSource(new
* DefaultInputSupplier
* ((getClass().getResource("/testdata/inspire3/HydroPhysicalWaters.xsd"
* ).toURI()))); IOReport report = reader.execute(null);
* assertTrue(report.isSuccess()); Schema schema = reader.getSchema();
*
* StreamGmlReader instanceReader = new GmlInstanceReader();
* instanceReader.setSource(new
* DefaultInputSupplier(getClass().getResource
* ("/testdata/out/transformWrite_ERM_HPW.gml").toURI()));
* instanceReader.setSourceSchema(schema);
*
* instanceReader.validate(); report = instanceReader.execute(null);
* assertTrue(report.isSuccess());
*
* InstanceCollection instances = instanceReader.getInstances();
* assertFalse(instances.isEmpty());
*/
ResourceIterator<Instance> ri = FilterTest.complexinstances.iterator();
try {
boolean foundIt = false;
boolean stayFalse = false;
boolean stayFalseToo = false;
boolean foundIt11 = false;
boolean foundIt1 = false;
boolean foundIt2 = false;
boolean foundIt3 = false;
Filter ecqlfilter = new FilterGeoECqlImpl("\"geometry.Polygon.srsName\" = 'EPSG:4326'");
Filter ecqlfilter11 = new FilterGeoECqlImpl("width.WidthRange.upper = 15.0");
Filter ecqlfilter1 = new FilterGeoECqlImpl("\"width.WidthRange.upper\" = 15.0");
Filter foulfilter1 = new FilterGeoECqlImpl("\"location.AbstractSolid.id\" = 'HURR'");
Filter foulfilter = new FilterGeoECqlImpl("HERP = 'DERP'");
Filter ecqlfilter2 = new FilterGeoECqlImpl("\"id\" = '_00000000-7953-b57f-0000-00000010cb14'");
Filter ecqlfilter3 = new FilterGeoECqlImpl("'_00000000-7953-b57f-0000-00000010cb14' = \"id\"");
// this should throw a CQL Exception
try {
new FilterGeoECqlImpl("id = '_00000000-7953-b57f-0000-00000010cb14'");
fail("Expected exception!");
} catch (CQLException e) {
System.out.println("CQL Exception thrown because \"id\" is reserved");
}
while (ri.hasNext()) {
Instance inst = ri.next();
assertNotNull(inst);
if (ecqlfilter.match(inst)) {
foundIt = true;
}
if (ecqlfilter1.match(inst)) {
foundIt1 = true;
}
if (ecqlfilter11.match(inst)) {
foundIt11 = true;
}
if (foulfilter.match(inst)) {
stayFalse = true;
}
if (foulfilter1.match(inst)) {
stayFalseToo = true;
}
if (ecqlfilter2.match(inst)) {
foundIt2 = true;
}
if (ecqlfilter3.match(inst)) {
foundIt3 = true;
}
}
assertTrue(foundIt);
assertTrue(foundIt1);
assertTrue(foundIt11);
assertTrue(foundIt2);
assertTrue(foundIt3);
assertFalse(stayFalse);
assertFalse(stayFalseToo);
// TODO
} finally {
ri.close();
}
}
Aggregations