use of com.runwaysdk.query.AttributeBoolean 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;
}
use of com.runwaysdk.query.AttributeBoolean 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;
}
Aggregations