use of com.runwaysdk.query.OrderBy.SortOrder 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;
}
use of com.runwaysdk.query.OrderBy.SortOrder in project geoprism-registry by terraframe.
the class AbstractGraphPageQuery method getPage.
public Page<T> getPage() {
int pageSize = 10;
int pageNumber = 1;
Long count = this.getCount();
final MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(this.type);
StringBuilder statement = new StringBuilder();
statement.append("SELECT ");
this.addSelectAttributes(mdVertex, statement);
statement.append(" FROM " + mdVertex.getDBClassName() + "");
Map<String, Object> parameters = new HashMap<String, Object>();
if (criteria.has("filters")) {
JsonObject filters = criteria.get("filters").getAsJsonObject();
this.addCriteria(mdVertex, filters, statement, parameters);
}
if (criteria.has("sortField") && criteria.has("sortOrder")) {
String field = criteria.get("sortField").getAsString();
SortOrder order = criteria.get("sortOrder").getAsInt() == 1 ? SortOrder.ASC : SortOrder.DESC;
MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(field);
statement.append(" ORDER BY " + this.getColumnName(mdAttribute) + " " + order.name());
} 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;
MdAttributeDAOIF mdAttribute = mdVertex.definesAttribute(field);
if (i == 0) {
statement.append(" ORDER BY " + this.getColumnName(mdAttribute) + " " + order.name());
} else {
statement.append(", " + this.getColumnName(mdAttribute) + " " + order.name());
}
}
}
if (criteria.has("first") && criteria.has("rows")) {
int first = criteria.get("first").getAsInt();
int rows = criteria.get("rows").getAsInt();
statement.append(" SKIP " + first + " LIMIT " + rows);
pageNumber = (first / rows) + 1;
}
final GraphQuery<K> query = new GraphQuery<K>(statement.toString(), parameters);
return new Page<T>(count, pageNumber, pageSize, this.getResults(query));
}
Aggregations