use of com.runwaysdk.query.SelectableChar in project geoprism-registry by terraframe.
the class AbstractBusinessPageQuery method getQuery.
protected BusinessQuery getQuery(ComponentQuery qQuery, BusinessQuery query) {
if (criteria.has("sortField") && criteria.has("sortOrder")) {
String field = criteria.get("sortField").getAsString();
SortOrder order = criteria.get("sortOrder").getAsInt() == 1 ? SortOrder.ASC : SortOrder.DESC;
qQuery.ORDER_BY(query.getS(field), order);
} else if (criteria.has("multiSortMeta")) {
JsonArray sorts = criteria.get("multiSortMeta").getAsJsonArray();
for (int i = 0; i < sorts.size(); i++) {
JsonObject sort = sorts.get(i).getAsJsonObject();
String field = sort.get("field").getAsString();
SortOrder order = sort.get("order").getAsInt() == 1 ? SortOrder.ASC : SortOrder.DESC;
qQuery.ORDER_BY(query.getS(field), order);
}
}
if (criteria.has("filters")) {
JsonObject filters = criteria.get("filters").getAsJsonObject();
Iterator<String> keys = filters.keySet().iterator();
while (keys.hasNext()) {
String attributeName = keys.next();
Selectable attribute = query.get(attributeName);
if (attribute != null) {
JsonObject filter = filters.get(attributeName).getAsJsonObject();
String mode = filter.get("matchMode").getAsString();
if (attribute instanceof SelectableMoment) {
JsonObject value = filter.get("value").getAsJsonObject();
if (value.has("startDate") && !value.get("startDate").isJsonNull()) {
String date = value.get("startDate").getAsString();
if (date.length() > 0) {
qQuery.WHERE(((SelectableMoment) attribute).GE(GeoRegistryUtil.parseDate(date)));
}
}
if (value.has("endDate") && !value.get("endDate").isJsonNull()) {
String date = value.get("endDate").getAsString();
if (date.length() > 0) {
qQuery.WHERE(((SelectableMoment) attribute).LE(GeoRegistryUtil.parseDate(date)));
}
}
} else if (attribute instanceof SelectableBoolean) {
String value = filter.get("value").getAsString();
filterBoolean(qQuery, attribute, Boolean.valueOf(value));
} else if (mode.equals("contains")) {
String value = filter.get("value").getAsString();
SelectableChar selectable = (SelectableChar) attribute;
qQuery.WHERE(selectable.LIKEi("%" + value + "%"));
} else if (mode.equals("equals")) {
String value = filter.get("value").getAsString();
qQuery.WHERE(attribute.EQ(value));
}
}
}
}
return query;
}
Aggregations