Search in sources :

Example 1 with BasicCondition

use of com.runwaysdk.query.BasicCondition in project geoprism-registry by terraframe.

the class ListTypeVersion method buildQueryConditionsFromFilter.

private Map<MdAttributeConcreteDAOIF, Condition> buildQueryConditionsFromFilter(String filterJson, String ignoreAttribute, ComponentQuery query, MdBusinessDAOIF mdBusiness) {
    Map<MdAttributeConcreteDAOIF, Condition> conditionMap = new HashMap<MdAttributeConcreteDAOIF, Condition>();
    if (filterJson != null && filterJson.length() > 0) {
        DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
        filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
        JsonArray filters = JsonParser.parseString(filterJson).getAsJsonArray();
        for (int i = 0; i < filters.size(); i++) {
            JsonObject filter = filters.get(i).getAsJsonObject();
            String attribute = filter.get("attribute").getAsString();
            if (ignoreAttribute == null || !attribute.equals(ignoreAttribute)) {
                MdAttributeConcreteDAOIF mdAttr = mdBusiness.definesAttribute(attribute);
                BasicCondition condition = null;
                if (mdAttr instanceof MdAttributeMomentDAOIF) {
                    JsonObject jObject = filter.get("value").getAsJsonObject();
                    try {
                        if (jObject.has("start") && !jObject.get("start").isJsonNull()) {
                            String date = jObject.get("start").getAsString();
                            if (date.length() > 0) {
                                condition = query.aDateTime(attribute).GE(filterFormat.parse(date));
                            }
                        }
                        if (jObject.has("end") && !jObject.get("end").isJsonNull()) {
                            String date = jObject.get("end").getAsString();
                            if (date.length() > 0) {
                                condition = query.aDateTime(attribute).LE(filterFormat.parse(date));
                            }
                        }
                    } catch (ParseException e) {
                        throw new ProgrammingErrorException(e);
                    }
                } else if (mdAttr instanceof MdAttributeBooleanDAOIF) {
                    String value = filter.get("value").getAsString();
                    Boolean bVal = Boolean.valueOf(value);
                    condition = ((AttributeBoolean) query.get(attribute)).EQ(bVal);
                } else {
                    String value = filter.get("value").getAsString();
                    condition = query.get(attribute).EQ(value);
                }
                if (condition != null) {
                    if (conditionMap.containsKey(mdAttr)) {
                        conditionMap.put(mdAttr, conditionMap.get(mdAttr).OR(condition));
                    } else {
                        conditionMap.put(mdAttr, condition);
                    }
                }
            }
        }
    }
    return conditionMap;
}
Also used : Condition(com.runwaysdk.query.Condition) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) Point(com.vividsolutions.jts.geom.Point) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JsonArray(com.google.gson.JsonArray) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) ParseException(java.text.ParseException) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) SimpleDateFormat(java.text.SimpleDateFormat) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 2 with BasicCondition

use of com.runwaysdk.query.BasicCondition in project geoprism-registry by terraframe.

the class MasterListVersion method buildQueryConditionsFromFilter.

private Map<MdAttributeConcreteDAOIF, Condition> buildQueryConditionsFromFilter(String filterJson, String ignoreAttribute, ComponentQuery query, MdBusinessDAOIF mdBusiness) {
    Map<MdAttributeConcreteDAOIF, Condition> conditionMap = new HashMap<MdAttributeConcreteDAOIF, Condition>();
    if (filterJson != null && filterJson.length() > 0) {
        DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
        filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
        JsonArray filters = JsonParser.parseString(filterJson).getAsJsonArray();
        for (int i = 0; i < filters.size(); i++) {
            JsonObject filter = filters.get(i).getAsJsonObject();
            String attribute = filter.get("attribute").getAsString();
            if (ignoreAttribute == null || !attribute.equals(ignoreAttribute)) {
                MdAttributeConcreteDAOIF mdAttr = mdBusiness.definesAttribute(attribute);
                BasicCondition condition = null;
                if (mdAttr instanceof MdAttributeMomentDAOIF) {
                    JsonObject jObject = filter.get("value").getAsJsonObject();
                    try {
                        if (jObject.has("start") && !jObject.get("start").isJsonNull()) {
                            String date = jObject.get("start").getAsString();
                            if (date.length() > 0) {
                                condition = query.aDateTime(attribute).GE(filterFormat.parse(date));
                            }
                        }
                        if (jObject.has("end") && !jObject.get("end").isJsonNull()) {
                            String date = jObject.get("end").getAsString();
                            if (date.length() > 0) {
                                condition = query.aDateTime(attribute).LE(filterFormat.parse(date));
                            }
                        }
                    } catch (ParseException e) {
                        throw new ProgrammingErrorException(e);
                    }
                } else if (mdAttr instanceof MdAttributeBooleanDAOIF) {
                    String value = filter.get("value").getAsString();
                    Boolean bVal = Boolean.valueOf(value);
                    condition = ((AttributeBoolean) query.get(attribute)).EQ(bVal);
                } else {
                    String value = filter.get("value").getAsString();
                    condition = query.get(attribute).EQ(value);
                }
                if (condition != null) {
                    if (conditionMap.containsKey(mdAttr)) {
                        conditionMap.put(mdAttr, conditionMap.get(mdAttr).OR(condition));
                    } else {
                        conditionMap.put(mdAttr, condition);
                    }
                }
            }
        }
    }
    return conditionMap;
}
Also used : Condition(com.runwaysdk.query.Condition) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeMomentDAOIF(com.runwaysdk.dataaccess.MdAttributeMomentDAOIF) MdAttributePoint(com.runwaysdk.system.gis.metadata.MdAttributePoint) MdAttributeMultiPoint(com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JsonArray(com.google.gson.JsonArray) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) ParseException(java.text.ParseException) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) SimpleDateFormat(java.text.SimpleDateFormat) BasicCondition(com.runwaysdk.query.BasicCondition) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Aggregations

JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 MdAttributeBooleanDAOIF (com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF)2 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)2 MdAttributeMomentDAOIF (com.runwaysdk.dataaccess.MdAttributeMomentDAOIF)2 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)2 AttributeBoolean (com.runwaysdk.query.AttributeBoolean)2 BasicCondition (com.runwaysdk.query.BasicCondition)2 Condition (com.runwaysdk.query.Condition)2 MdAttributeLineString (com.runwaysdk.system.gis.metadata.MdAttributeLineString)2 MdAttributeMultiLineString (com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString)2 MdAttributeMultiPoint (com.runwaysdk.system.gis.metadata.MdAttributeMultiPoint)2 MdAttributePoint (com.runwaysdk.system.gis.metadata.MdAttributePoint)2 MdAttributeBoolean (com.runwaysdk.system.metadata.MdAttributeBoolean)2 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)1 Point (com.vividsolutions.jts.geom.Point)1