Search in sources :

Example 1 with SelectableMoment

use of com.runwaysdk.query.SelectableMoment 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)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 SortOrder (com.runwaysdk.query.OrderBy.SortOrder)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