Search in sources :

Example 6 with BusinessQuery

use of com.runwaysdk.business.BusinessQuery in project geoprism-registry by terraframe.

the class MasterListShapefileExporter method features.

public FeatureCollection<SimpleFeatureType, SimpleFeature> features(SimpleFeatureType featureType) {
    List<SimpleFeature> features = new ArrayList<SimpleFeature>();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    BusinessQuery query = this.version.buildQuery(this.filterJson);
    query.ORDER_BY_DESC(query.aCharacter(DefaultAttribute.CODE.getName()));
    OIterator<Business> objects = query.getIterator();
    try {
        while (objects.hasNext()) {
            Business row = objects.next();
            builder.set(GEOM, row.getObjectValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME));
            for (MdAttributeConcreteDAOIF mdAttribute : mdAttributes) {
                String attributeName = mdAttribute.definesAttribute();
                Object value = row.getObjectValue(attributeName);
                if (value != null) {
                    builder.set(this.getColumnName(attributeName), value);
                }
            }
            SimpleFeature feature = builder.buildFeature(row.getValue(DefaultAttribute.CODE.getName()));
            features.add(feature);
        }
    } finally {
        objects.close();
    }
    return new ListFeatureCollection(featureType, features);
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) ArrayList(java.util.ArrayList) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Business(com.runwaysdk.business.Business) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 7 with BusinessQuery

use of com.runwaysdk.business.BusinessQuery 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;
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) Condition(com.runwaysdk.query.Condition) BasicCondition(com.runwaysdk.query.BasicCondition) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) QueryFactory(com.runwaysdk.query.QueryFactory) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 8 with BusinessQuery

use of com.runwaysdk.business.BusinessQuery in project geoprism-registry by terraframe.

the class ListTypeVersion method values.

public JsonArray values(String value, String attributeName, JsonObject criteria) {
    ValueQuery vQuery = new ValueQuery(new QueryFactory());
    BusinessQuery query = new ListTypeVersionPageQuery(this, criteria, true, false).getQuery(vQuery);
    DateFormat filterFormat = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
    filterFormat.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
    JsonArray results = new JsonArray();
    vQuery.SELECT_DISTINCT(query.get(attributeName, "label"));
    vQuery.FROM(query);
    if (value != null && value.length() > 0) {
        vQuery.WHERE(F.UPPER(query.aCharacter(attributeName)).LIKEi("%" + value.toUpperCase() + "%"));
    }
    try (OIterator<ValueObject> it = vQuery.getIterator(100, 1)) {
        while (it.hasNext()) {
            ValueObject vObject = it.next();
            results.add(vObject.getValue("label"));
        // JsonObject result = new JsonObject();
        // result.addProperty("label", vObject.getValue("label"));
        // result.addProperty("value", vObject.getValue("value"));
        // 
        // results.add(result);
        }
    }
    return results;
}
Also used : ValueQuery(com.runwaysdk.query.ValueQuery) BusinessQuery(com.runwaysdk.business.BusinessQuery) JsonArray(com.google.gson.JsonArray) QueryFactory(com.runwaysdk.query.QueryFactory) ListTypeVersionPageQuery(net.geoprism.registry.query.ListTypeVersionPageQuery) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ValueObject(com.runwaysdk.dataaccess.ValueObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 9 with BusinessQuery

use of com.runwaysdk.business.BusinessQuery 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;
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) Condition(com.runwaysdk.query.Condition) BasicCondition(com.runwaysdk.query.BasicCondition) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) QueryFactory(com.runwaysdk.query.QueryFactory) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Example 10 with BusinessQuery

use of com.runwaysdk.business.BusinessQuery 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;
}
Also used : BusinessQuery(com.runwaysdk.business.BusinessQuery) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) MdAttributeCharacter(com.runwaysdk.system.metadata.MdAttributeCharacter) JsonObject(com.google.gson.JsonObject) MdAttributeMultiLineString(com.runwaysdk.system.gis.metadata.MdAttributeMultiLineString) MdAttributeLineString(com.runwaysdk.system.gis.metadata.MdAttributeLineString) MdAttributeDouble(com.runwaysdk.system.metadata.MdAttributeDouble) Date(java.util.Date) JsonArray(com.google.gson.JsonArray) Geometry(com.vividsolutions.jts.geom.Geometry) MdAttributeGeometry(com.runwaysdk.system.gis.metadata.MdAttributeGeometry) VertexObject(com.runwaysdk.business.graph.VertexObject) JsonObject(com.google.gson.JsonObject) ValueObject(com.runwaysdk.dataaccess.ValueObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) MdAttributeBoolean(com.runwaysdk.system.metadata.MdAttributeBoolean) AttributeBoolean(com.runwaysdk.query.AttributeBoolean) SimpleDateFormat(java.text.SimpleDateFormat) GeoJSONWriter(org.wololo.jts2geojson.GeoJSONWriter) NumberFormat(java.text.NumberFormat) MdBusiness(com.runwaysdk.system.metadata.MdBusiness) Business(com.runwaysdk.business.Business) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)

Aggregations

BusinessQuery (com.runwaysdk.business.BusinessQuery)17 Business (com.runwaysdk.business.Business)12 QueryFactory (com.runwaysdk.query.QueryFactory)9 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)7 JsonObject (com.google.gson.JsonObject)6 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)5 JsonArray (com.google.gson.JsonArray)4 ValueObject (com.runwaysdk.dataaccess.ValueObject)4 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)4 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)3 BasicCondition (com.runwaysdk.query.BasicCondition)3 Condition (com.runwaysdk.query.Condition)3 ArrayList (java.util.ArrayList)3 VertexObject (com.runwaysdk.business.graph.VertexObject)2 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)2 AttributeBoolean (com.runwaysdk.query.AttributeBoolean)2 ValueQuery (com.runwaysdk.query.ValueQuery)2 MdAttributeLineString (com.runwaysdk.system.gis.metadata.MdAttributeLineString)2