Commit 64e3c84c authored by Matija Obreza's avatar Matija Obreza

Use AppliedFilters instead of ObjectNode/String jsonFilter

parent 367bf5b7
......@@ -19,10 +19,9 @@ package org.genesys2.server.persistence.domain;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.springframework.jdbc.core.RowCallbackHandler;
import com.fasterxml.jackson.databind.node.ObjectNode;
public interface GenesysLowlevelRepository {
void updateCountryRefs();
......@@ -38,20 +37,20 @@ public interface GenesysLowlevelRepository {
void refreshMetadataMethods();
void listAccessions(ObjectNode filter, RowCallbackHandler rowCallbackHandler);
void listAccessions(AppliedFilters filter, RowCallbackHandler rowCallbackHandler);
void listAccessionsGeo(ObjectNode filter, RowCallbackHandler rowCallbackHandler);
void listAccessionsGeo(AppliedFilters filter, RowCallbackHandler rowCallbackHandler);
void listAccessionsColl(ObjectNode filter, RowCallbackHandler rowCallbackHandler);
void listAccessionsColl(AppliedFilters filter, RowCallbackHandler rowCallbackHandler);
void listMetadataAccessions(long id, RowCallbackHandler rowCallbackHandler);
void listAccessionsAlias(ObjectNode filter, RowCallbackHandler rowCallbackHandler);
void listAccessionsAlias(AppliedFilters filter, RowCallbackHandler rowCallbackHandler);
void listAccessionsAccenames(RowCallbackHandler rowCallbackHandler);
void listAccessionsAlias(RowCallbackHandler rowCallbackHandler);
int countAccessions(ObjectNode filter);
int countAccessions(AppliedFilters filter);
}
......@@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.service.impl.DirectMysqlQuery;
import org.genesys2.server.service.impl.DirectMysqlQuery.MethodResolver;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
......@@ -40,8 +41,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.fasterxml.jackson.databind.node.ObjectNode;
@Repository
@Transactional(readOnly = true)
public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository {
......@@ -218,7 +217,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public int countAccessions(final ObjectNode filter) {
public int countAccessions(final AppliedFilters filter) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
......@@ -231,7 +230,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public void listAccessions(final ObjectNode filter, final RowCallbackHandler rowCallbackHandler) {
public void listAccessions(final AppliedFilters filter, final RowCallbackHandler rowCallbackHandler) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.outerJoin("taxonomy2", "t", "t.id=a.taxonomyId2");
directQuery.jsonFilter(filter, new MethodResolver() {
......@@ -258,7 +257,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public void listAccessionsGeo(final ObjectNode filter, final RowCallbackHandler rowCallbackHandler) {
public void listAccessionsGeo(final AppliedFilters filter, final RowCallbackHandler rowCallbackHandler) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accessiongeo", "geo");
directQuery.innerJoin("accession", "a", "a.id=geo.accessionId");
directQuery.jsonFilter(filter, new MethodResolver() {
......@@ -285,7 +284,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public void listAccessionsAlias(final ObjectNode filter, final RowCallbackHandler rowCallbackHandler) {
public void listAccessionsAlias(final AppliedFilters filter, final RowCallbackHandler rowCallbackHandler) {
// from n inner join accession a on a.id=n.accessionId
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accessionalias", "n");
directQuery.innerJoin("accession", "a", "a.id=n.accessionId");
......@@ -326,7 +325,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public void listAccessionsColl(final ObjectNode filter, final RowCallbackHandler rowCallbackHandler) {
public void listAccessionsColl(final AppliedFilters filter, final RowCallbackHandler rowCallbackHandler) {
// from accessioncollect coll inner join accession a on
// a.id=coll.accessionId
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accessioncollect", "coll");
......
......@@ -19,13 +19,14 @@ package org.genesys2.server.service;
import java.util.Collection;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
public interface ElasticService {
void reindexByFilter(String jsonFilter, boolean slow);
void reindexByFilter(AppliedFilters filters, boolean slow);
Page<AccessionDetails> search(String query, Pageable pageable) throws SearchException;
......@@ -39,4 +40,5 @@ public interface ElasticService {
Page<AccessionDetails> filter(String jsonFilter, Pageable pageable) throws SearchException;
}
......@@ -55,4 +55,6 @@ public interface FilterConstants {
public static final String TAXONOMY_SPECIES = "taxonomy.species";
public static final String TAXONOMY_GENUS = "taxonomy.genus";
public static final String ID = "id";
}
......@@ -19,21 +19,20 @@ package org.genesys2.server.service;
import java.util.List;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.GenesysFilterServiceImpl.LabelValue;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.RowCallbackHandler;
import com.fasterxml.jackson.databind.node.ObjectNode;
public interface GenesysFilterService {
Page<Accession> listAccessions(ObjectNode jsonTree, Pageable pageable);
Page<Accession> listAccessions(AppliedFilters filters, Pageable pageable);
List<LabelValue<String>> autocomplete(String filter, String ac,ObjectNode jsonTree);
List<LabelValue<String>> autocomplete(String filter, String ac, AppliedFilters filters);
void listGeo(ObjectNode jsonTree, Integer limit, RowCallbackHandler rowHandler);
void listGeo(AppliedFilters filters, Integer limit, RowCallbackHandler rowHandler);
void listGeoTile(boolean distinct, ObjectNode jsonTree, Integer limit, int zoom, int xtile, int ytile, RowCallbackHandler rowHandler);
void listGeoTile(boolean distinct, AppliedFilters filters, Integer limit, int zoom, int xtile, int ytile, RowCallbackHandler rowHandler);
}
......@@ -42,6 +42,7 @@ import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -149,7 +150,7 @@ public interface GenesysService {
long countDatasets(FaoInstitute faoInstitute);
void writeAccessions(String jsonFilter, OutputStream outputStream) throws IOException;
void writeAccessions(AppliedFilters filters, OutputStream outputStream) throws IOException;
List<AccessionAlias> saveAliases(List<AccessionAlias> aliases);
......@@ -183,7 +184,7 @@ public interface GenesysService {
Set<Long> listAccessions(FaoInstitute holdingInstitute, Set<Long> accessionIds);
int countAccessions(String jsonFilter);
int countAccessions(AppliedFilters filters);
List<AccessionRemark> saveRemarks(List<AccessionRemark> toSaveRemarks);
......
......@@ -18,15 +18,17 @@ package org.genesys2.server.service;
import java.io.IOException;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
public interface MappingService {
void clearCache();
String filteredKml(String jsonFilter);
String filteredKml(AppliedFilters filters);
String filteredGeoJson(String string, Integer limit) throws IOException;
String filteredGeoJson(AppliedFilters filters, Integer limit) throws IOException;
byte[] getTile(String jsonFilter, int zoom, int xtile, int ytile);
byte[] getTile(AppliedFilters filters, int zoom, int xtile, int ytile);
public static class CoordUtil {
public static double tileToLon(int zoom, int xtile) {
......
......@@ -18,7 +18,6 @@ package org.genesys2.server.service.impl;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
......@@ -29,13 +28,17 @@ import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.MappingService.CoordUtil;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.FilterHandler.FilterValue;
import org.genesys2.server.service.impl.FilterHandler.LiteralValueFilter;
import org.genesys2.server.service.impl.FilterHandler.MaxValueFilter;
import org.genesys2.server.service.impl.FilterHandler.MinValueFilter;
import org.genesys2.server.service.impl.FilterHandler.StartsWithFilter;
import org.genesys2.server.service.impl.FilterHandler.ValueRangeFilter;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Order;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class DirectMysqlQuery {
private static final Log LOG = LogFactory.getLog(DirectMysqlQuery.class);
......@@ -51,7 +54,8 @@ public class DirectMysqlQuery {
public DirectMysqlQuery innerJoin(String table, String alias, String onExpr) {
if (tables.contains(table)) {
LOG.warn("Table already inner-joined: " + table);
if (LOG.isDebugEnabled())
LOG.debug("Table already inner-joined: " + table);
return this;
}
if (LOG.isDebugEnabled()) {
......@@ -85,91 +89,85 @@ public class DirectMysqlQuery {
return this;
}
public DirectMysqlQuery jsonFilter(ObjectNode jsonTree, MethodResolver methodResolver) {
return join(jsonTree).filter(jsonTree, methodResolver);
public DirectMysqlQuery jsonFilter(AppliedFilters filters, MethodResolver methodResolver) {
return join(filters).filter(filters, methodResolver);
}
protected DirectMysqlQuery join(ObjectNode jsonTree) {
if (hasFilter(jsonTree, FilterConstants.CROPS) || hasFilter(jsonTree, FilterConstants.TAXONOMY_GENUS)
|| hasFilter(jsonTree, FilterConstants.TAXONOMY_SPECIES) || hasFilter(jsonTree, FilterConstants.TAXONOMY_SCINAME)) {
protected DirectMysqlQuery join(AppliedFilters filters) {
if (hasFilter(filters, FilterConstants.CROPS) || hasFilter(filters, FilterConstants.TAXONOMY_GENUS)
|| hasFilter(filters, FilterConstants.TAXONOMY_SPECIES) || hasFilter(filters, FilterConstants.TAXONOMY_SCINAME)) {
innerJoin("taxonomy2", "t", "t.id=a.taxonomyId2");
if (hasFilter(jsonTree, FilterConstants.CROPS)) {
if (hasFilter(filters, FilterConstants.CROPS)) {
innerJoin("croptaxonomy", "ct", "ct.taxonomyId=t.id");
innerJoin("crop", null, "crop.id=ct.cropId");
}
}
if (hasFilter(jsonTree, FilterConstants.ORGANIZATION)) {
if (hasFilter(filters, FilterConstants.ORGANIZATION)) {
innerJoin("faoinstitute", "fao", "fao.id=a.instituteId");
innerJoin("organizationinstitute", "oi", "oi.instituteId=fao.id");
innerJoin("organization", "org", "org.id=oi.organizationId");
}
if (hasFilter(jsonTree, FilterConstants.GEO_LATITUDE) || hasFilter(jsonTree, FilterConstants.GEO_LONGITUDE)
|| hasFilter(jsonTree, FilterConstants.GEO_ELEVATION)) {
if (hasFilter(filters, FilterConstants.GEO_LATITUDE) || hasFilter(filters, FilterConstants.GEO_LONGITUDE)
|| hasFilter(filters, FilterConstants.GEO_ELEVATION)) {
innerJoin("accessiongeo", "geo", "geo.accessionId=a.id");
}
if (hasFilter(jsonTree, FilterConstants.ALIAS)) {
if (hasFilter(filters, FilterConstants.ALIAS)) {
innerJoin("accessionalias", "accename", "accename.accessionId=a.id");
}
if (hasFilter(jsonTree, FilterConstants.COLLMISSID)) {
if (hasFilter(filters, FilterConstants.COLLMISSID)) {
innerJoin("accessioncollect", "col", "col.accessionId=a.id");
}
if (hasFilter(jsonTree, FilterConstants.STORAGE)) {
if (hasFilter(filters, FilterConstants.STORAGE)) {
innerJoin("accessionstorage", "storage", "storage.accessionId=a.id");
}
return this;
}
static boolean hasFilter(ObjectNode jsonTree, String filterName) {
final JsonNode f = jsonTree.get(filterName);
return f != null && f.isArray() && f.size() > 0;
static boolean hasFilter(AppliedFilters filters, String filterName) {
final AppliedFilter f = filters.get(filterName);
return f != null && f.getValues().size() > 0;
}
protected DirectMysqlQuery filter(ObjectNode jsonTree, MethodResolver methodResolver) {
createQuery(whereBuffer, "a.id", jsonTree.get("id"), params);
createQuery(whereBuffer, "a.taxGenus", jsonTree.get("genusId"), params);
createQuery(whereBuffer, "a.taxSpecies", jsonTree.get("speciesId"), params);
createQuery(whereBuffer, "a.acceNumb", jsonTree.get(FilterConstants.ACCENUMB), params);
createQuery(whereBuffer, "a.orgCty", jsonTree.get(FilterConstants.ORGCTY_ISO3), params);
createQuery(whereBuffer, "a.instCode", jsonTree.get(FilterConstants.INSTCODE), params);
createQuery(whereBuffer, "a.inSGSV", jsonTree.get(FilterConstants.SGSV), params);
createQuery(whereBuffer, "a.mlsStat", jsonTree.get(FilterConstants.MLSSTATUS), params);
createQuery(whereBuffer, "a.inTrust", jsonTree.get(FilterConstants.ART15), params);
createQuery(whereBuffer, "a.sampStat", jsonTree.get(FilterConstants.SAMPSTAT), params);
createQuery(whereBuffer, "a.available", jsonTree.get(FilterConstants.AVAILABLE), params);
createQuery(whereBuffer, "org.slug", jsonTree.get(FilterConstants.ORGANIZATION), params);
createQuery(whereBuffer, "t.genus", jsonTree.get(FilterConstants.TAXONOMY_GENUS), params);
createQuery(whereBuffer, "t.species", jsonTree.get(FilterConstants.TAXONOMY_SPECIES), params);
createQuery(whereBuffer, "t.taxonName", jsonTree.get(FilterConstants.TAXONOMY_SCINAME), params);
createQuery(whereBuffer, "geo.longitude", jsonTree.get(FilterConstants.GEO_LONGITUDE), params);
createQuery(whereBuffer, "geo.latitude", jsonTree.get(FilterConstants.GEO_LATITUDE), params);
createQuery(whereBuffer, "geo.elevation", jsonTree.get(FilterConstants.GEO_ELEVATION), params);
createQuery(whereBuffer, "crop.shortName", jsonTree.get(FilterConstants.CROPS), params);
createQuery(whereBuffer, "accename.name", jsonTree.get(FilterConstants.ALIAS), params);
createQuery(whereBuffer, "col.collMissId", jsonTree.get(FilterConstants.COLLMISSID), params);
createQuery(whereBuffer, "storage.storage", jsonTree.get(FilterConstants.STORAGE), params);
for (final Iterator<String> it = jsonTree.fieldNames(); it.hasNext();) {
final String fieldName = it.next();
if (fieldName.startsWith("gm:")) {
if (LOG.isDebugEnabled()) {
LOG.debug("Filtering on C&E data, method=" + fieldName);
}
// Handle Genesys Method!
final long methodId = Long.parseLong(fieldName.substring(3));
// Need to validate method
final Method method = methodResolver.getMethod(methodId);
if (method != null) {
final String alias = "gm" + methodId;
innerJoin("`" + methodId + "`", alias, alias + ".accessionId=a.id");
createQuery(whereBuffer, alias + ".`" + method.getFieldName() + "`", jsonTree.get(fieldName), params);
} else {
LOG.warn("No such method with id=" + methodId);
}
protected DirectMysqlQuery filter(AppliedFilters filters, MethodResolver methodResolver) {
createQuery(whereBuffer, "a.id", filters.get("id"), params);
createQuery(whereBuffer, "a.taxGenus", filters.get("genusId"), params);
createQuery(whereBuffer, "a.taxSpecies", filters.get("speciesId"), params);
createQuery(whereBuffer, "a.acceNumb", filters.get(FilterConstants.ACCENUMB), params);
createQuery(whereBuffer, "a.orgCty", filters.get(FilterConstants.ORGCTY_ISO3), params);
createQuery(whereBuffer, "a.instCode", filters.get(FilterConstants.INSTCODE), params);
createQuery(whereBuffer, "a.inSGSV", filters.get(FilterConstants.SGSV), params);
createQuery(whereBuffer, "a.mlsStat", filters.get(FilterConstants.MLSSTATUS), params);
createQuery(whereBuffer, "a.inTrust", filters.get(FilterConstants.ART15), params);
createQuery(whereBuffer, "a.sampStat", filters.get(FilterConstants.SAMPSTAT), params);
createQuery(whereBuffer, "a.available", filters.get(FilterConstants.AVAILABLE), params);
createQuery(whereBuffer, "org.slug", filters.get(FilterConstants.ORGANIZATION), params);
createQuery(whereBuffer, "t.genus", filters.get(FilterConstants.TAXONOMY_GENUS), params);
createQuery(whereBuffer, "t.species", filters.get(FilterConstants.TAXONOMY_SPECIES), params);
createQuery(whereBuffer, "t.taxonName", filters.get(FilterConstants.TAXONOMY_SCINAME), params);
createQuery(whereBuffer, "geo.longitude", filters.get(FilterConstants.GEO_LONGITUDE), params);
createQuery(whereBuffer, "geo.latitude", filters.get(FilterConstants.GEO_LATITUDE), params);
createQuery(whereBuffer, "geo.elevation", filters.get(FilterConstants.GEO_ELEVATION), params);
createQuery(whereBuffer, "crop.shortName", filters.get(FilterConstants.CROPS), params);
createQuery(whereBuffer, "accename.name", filters.get(FilterConstants.ALIAS), params);
createQuery(whereBuffer, "col.collMissId", filters.get(FilterConstants.COLLMISSID), params);
createQuery(whereBuffer, "storage.storage", filters.get(FilterConstants.STORAGE), params);
for (final AppliedFilter methodFilter : filters.methodFilters()) {
// Handle Genesys Method!
final long methodId = Long.parseLong(methodFilter.getFilterName().substring(3));
// Need to validate method
final Method method = methodResolver.getMethod(methodId);
if (method != null) {
final String alias = "gm" + methodId;
innerJoin("`" + methodId + "`", alias, alias + ".accessionId=a.id");
createQuery(whereBuffer, alias + ".`" + method.getFieldName() + "`", methodFilter, params);
} else {
LOG.warn("No such method with id=" + methodId);
}
}
......@@ -211,15 +209,16 @@ public class DirectMysqlQuery {
}
}
private void createQuery(StringBuffer sb, String dbName, JsonNode fieldQuery, List<Object> params) {
private void createQuery(StringBuffer sb, String dbName, AppliedFilter appliedFilter, List<Object> params) {
if (LOG.isDebugEnabled()) {
LOG.debug("Handling " + dbName);
}
if (fieldQuery != null && fieldQuery.isArray() && fieldQuery.size() > 0) {
// Always an array of filters
if (appliedFilter != null && appliedFilter.getValues().size() > 0) {
Set<FilterValue> filterValues = appliedFilter.getValues();
if (LOG.isDebugEnabled()) {
LOG.debug("Adding " + fieldQuery + " sz=" + fieldQuery.size() + " t=" + fieldQuery.getNodeType());
LOG.debug("Adding " + appliedFilter + " sz=" + filterValues.size() + " t=" + appliedFilter.getClass().getSimpleName());
}
if (sb.length() == 0) {
......@@ -234,24 +233,24 @@ public class DirectMysqlQuery {
// A filter value can be (a) explicit value or (b) an operation
// (a) explicit values are handled by =? or by IN (?,?,..)
int handledCount = handleExplicitValues(sb, dbName, fieldQuery.elements(), params);
int handledCount = handleExplicitValues(sb, dbName, filterValues, params);
// do we have more?
if (handledCount > 0 && fieldQuery.size() > handledCount) {
if (handledCount > 0 && filterValues.size() > handledCount) {
sb.append(" OR ");
}
int handledCountNull = handleNullValues(sb, dbName, fieldQuery.elements(), params);
int handledCountNull = handleNullValues(sb, dbName, appliedFilter, params);
handledCount += handledCountNull;
// do we have more?
if (handledCountNull > 0 && handledCount > 0 && fieldQuery.size() > handledCount) {
if (handledCountNull > 0 && handledCount > 0 && filterValues.size() > handledCount) {
sb.append(" OR ");
}
// (b) operations are expressed as {"min":12} or {"max":33} or
// {"range":[3,10]} or {"like":"test"}
handleOperations(sb, dbName, fieldQuery.elements(), params);
handleOperations(sb, dbName, filterValues, params);
// closing
sb.append(" ) ");
......@@ -259,122 +258,103 @@ public class DirectMysqlQuery {
}
private int handleOperations(StringBuffer sb, String dbName, Iterator<JsonNode> elements, List<Object> params) {
private int handleOperations(StringBuffer sb, String dbName, Set<FilterValue> set, List<Object> params) {
int counter = 0;
while (elements.hasNext()) {
final JsonNode filterValue = elements.next();
for (FilterValue filterValue : set) {
if (LOG.isDebugEnabled()) {
LOG.debug("Inspecting " + dbName + " ... " + filterValue);
}
if (filterValue.isObject()) {
if (filterValue instanceof ValueRangeFilter) {
ValueRangeFilter vrf = (ValueRangeFilter) filterValue;
if (LOG.isDebugEnabled()) {
LOG.debug("Adding " + filterValue);
LOG.debug("Adding array: " + vrf);
}
final JsonNode range = filterValue.findValue("range");
if (range != null && range.isArray()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding array: " + range);
}
if (counter > 0) {
sb.append(" or ");
}
counter++;
// must be an array
sb.append("\n ( ").append(dbName);
sb.append(" between ? and ? ) ");
addParam(params, range.get(0));
addParam(params, range.get(1));
if (counter > 0) {
sb.append(" or ");
}
counter++;
// must be an array
sb.append("\n ( ").append(dbName);
sb.append(" between ? and ? ) ");
addParam(params, vrf.getFrom());
addParam(params, vrf.getTo());
}
final JsonNode min = filterValue.findValue("min");
if (min != null && min.isNumber()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding min number: " + min);
}
if (counter > 0) {
sb.append(" or ");
}
counter++;
// must be an number
sb.append("\n ( ").append(dbName);
sb.append(" >= ? ) ");
addParam(params, min);
if (filterValue instanceof MinValueFilter) {
MinValueFilter mvf = (MinValueFilter) filterValue;
if (LOG.isDebugEnabled()) {
LOG.debug("Adding min number: " + mvf);
}
final JsonNode max = filterValue.findValue("max");
if (max != null && max.isNumber()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding max number: " + max);
}
if (counter > 0) {
sb.append(" or ");
}
counter++;
// must be an number
sb.append("\n ( ").append(dbName);
sb.append(" <= ? ) ");
addParam(params, max);
if (counter > 0) {
sb.append(" or ");
}
counter++;
// must be an number
sb.append("\n ( ").append(dbName);
sb.append(" >= ? ) ");
addParam(params, mvf.getFrom());
}
final JsonNode like = filterValue.findValue("like");
if (like != null && like.isTextual()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding LIKE : " + like);
}
if (counter > 0) {
sb.append(" or ");
}
counter++;
// must be an number
sb.append("\n ( ").append(dbName);
sb.append(" LIKE ? ) ");
addParamLike(params, like);
if (filterValue instanceof MaxValueFilter) {
MaxValueFilter mvf = (MaxValueFilter) filterValue;
if (LOG.isDebugEnabled()) {
LOG.debug("Adding max number: " + mvf);
}
if (counter > 0) {
sb.append(" or ");
}
counter++;
// must be an number
sb.append("\n ( ").append(dbName);
sb.append(" <= ? ) ");
addParam(params, mvf.getTo());
}
}
return counter;
}
private int handleNullValues(StringBuffer sb, String dbName, Iterator<JsonNode> elements, List<Object> params) {
int counter = 0;
while (elements.hasNext