Search in sources :

Example 1 with SortOrder

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;
}
Also used : JsonArray(com.google.gson.JsonArray) SelectableChar(com.runwaysdk.query.SelectableChar) Selectable(com.runwaysdk.query.Selectable) SelectableMoment(com.runwaysdk.query.SelectableMoment) SortOrder(com.runwaysdk.query.OrderBy.SortOrder) JsonObject(com.google.gson.JsonObject) SelectableBoolean(com.runwaysdk.query.SelectableBoolean)

Example 2 with SortOrder

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));
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) SortOrder(com.runwaysdk.query.OrderBy.SortOrder) Page(net.geoprism.registry.view.Page) JsonArray(com.google.gson.JsonArray) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) JsonObject(com.google.gson.JsonObject) GraphQuery(com.runwaysdk.business.graph.GraphQuery)

Aggregations

JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 SortOrder (com.runwaysdk.query.OrderBy.SortOrder)2 GraphQuery (com.runwaysdk.business.graph.GraphQuery)1 MdAttributeDAOIF (com.runwaysdk.dataaccess.MdAttributeDAOIF)1 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)1 Selectable (com.runwaysdk.query.Selectable)1 SelectableBoolean (com.runwaysdk.query.SelectableBoolean)1 SelectableChar (com.runwaysdk.query.SelectableChar)1 SelectableMoment (com.runwaysdk.query.SelectableMoment)1 HashMap (java.util.HashMap)1 Page (net.geoprism.registry.view.Page)1