use of com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF in project geoprism-registry by terraframe.
the class ListTypeVersion method buildQuery.
public BusinessQuery buildQuery(String filterJson) {
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
BusinessQuery query = new QueryFactory().businessQuery(mdBusiness.definesType());
Map<MdAttributeConcreteDAOIF, Condition> conditionMap = this.buildQueryConditionsFromFilter(filterJson, null, query, mdBusiness);
for (Condition condition : conditionMap.values()) {
query.WHERE(condition);
}
return query;
}
use of com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF in project geoprism-registry by terraframe.
the class MasterListVersion method buildQuery.
public BusinessQuery buildQuery(String filterJson) {
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
BusinessQuery query = new QueryFactory().businessQuery(mdBusiness.definesType());
Map<MdAttributeConcreteDAOIF, Condition> conditionMap = this.buildQueryConditionsFromFilter(filterJson, null, query, mdBusiness);
for (Condition condition : conditionMap.values()) {
query.WHERE(condition);
}
return query;
}
use of com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF in project geoprism-registry by terraframe.
the class MasterListVersion method data.
public JsonObject data(Integer pageNumber, Integer pageSize, String filterJson, String sort, Boolean includeGeometries) {
if (includeGeometries == null) {
includeGeometries = Boolean.FALSE;
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
NumberFormat numberFormat = NumberFormat.getInstance(Session.getCurrentLocale());
JsonArray results = new JsonArray();
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributes();
BusinessQuery query = this.buildQuery(filterJson);
if (sort != null && sort.length() > 0) {
JsonObject jObject = JsonParser.parseString(sort).getAsJsonObject();
String attribute = jObject.get("attribute").getAsString();
String order = jObject.get("order").getAsString();
if (order.equalsIgnoreCase("DESC")) {
query.ORDER_BY_DESC(query.getS(attribute));
} else {
query.ORDER_BY_ASC(query.getS(attribute));
}
if (!attribute.equals(DefaultAttribute.CODE.getName())) {
query.ORDER_BY_ASC(query.aCharacter(DefaultAttribute.CODE.getName()));
}
}
try (OIterator<Business> iterator = query.getIterator(pageSize, pageNumber)) {
while (iterator.hasNext()) {
Business row = iterator.next();
JsonObject object = new JsonObject();
MdAttributeConcreteDAOIF mdGeometry = mdBusiness.definesAttribute(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
if (includeGeometries) {
Geometry geom = (Geometry) row.getObjectValue(mdGeometry.definesAttribute());
if (geom != null) {
GeoJSONWriter gw = new GeoJSONWriter();
org.wololo.geojson.Geometry gJSON = gw.write(geom);
JsonObject geojson = JsonParser.parseString(gJSON.toString()).getAsJsonObject();
object.add("geometry", geojson);
}
}
object.addProperty(ORIGINAL_OID, row.getValue(ORIGINAL_OID));
for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
if (this.isValid(mdAttribute)) {
String attributeName = mdAttribute.definesAttribute();
Object value = row.getObjectValue(attributeName);
if (value != null) {
if (value instanceof Double) {
object.addProperty(mdAttribute.definesAttribute(), numberFormat.format((Double) value));
} else if (value instanceof Number) {
object.addProperty(mdAttribute.definesAttribute(), (Number) value);
} else if (value instanceof Boolean) {
object.addProperty(mdAttribute.definesAttribute(), (Boolean) value);
} else if (value instanceof String) {
object.addProperty(mdAttribute.definesAttribute(), (String) value);
} else if (value instanceof Character) {
object.addProperty(mdAttribute.definesAttribute(), (Character) value);
} else if (value instanceof Date) {
object.addProperty(mdAttribute.definesAttribute(), format.format((Date) value));
}
}
}
}
results.add(object);
}
}
JsonObject page = new JsonObject();
page.addProperty("pageNumber", pageNumber);
page.addProperty("pageSize", pageSize);
page.addProperty("filter", filterJson);
page.addProperty("count", query.getCount());
page.add("results", results);
return page;
}
use of com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF 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;
}
use of com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF in project geoprism-registry by terraframe.
the class MasterListVersion method generateShapefile.
public File generateShapefile() {
String filename = this.getOid() + ".zip";
final MasterList list = this.getMasterlist();
final File directory = list.getShapefileDirectory();
directory.mkdirs();
final File file = new File(directory, filename);
MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.getMdBusinessOid());
List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> this.isValid(mdAttribute)).collect(Collectors.toList());
try {
MasterListShapefileExporter exporter = new MasterListShapefileExporter(this, mdBusiness, mdAttributes, null);
try (final InputStream istream = exporter.export()) {
try (final FileOutputStream fos = new FileOutputStream(file)) {
IOUtils.copy(istream, fos);
}
}
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
return file;
}
Aggregations