Search in sources :

Example 6 with ValueObject

use of com.runwaysdk.dataaccess.ValueObject in project geoprism-registry by terraframe.

the class ChangeRequestService method findPageNumber.

// An attempt to do this without selectable sqls
// private int findPageNumber(String crOid, ChangeRequestQuery query, int pageSize)
// {
// QueryFactory qf = new QueryFactory();
// ValueQuery vq = new ValueQuery(qf);
// 
// vq.FROM(query);
// 
// vq.SELECT(query.getOid());
// vq.SELECT(query.getCreateDate());
// 
// Selectable createDate = query.getCreateDate();
// 
// vq.SELECT(vq.RANK("rn").OVER(null, new OrderBy(createDate, SortOrder.DESC)));
// 
// vq.WHERE(query.getOid().EQ(crOid));
// 
// ValueObject vo = vq.getIterator().getAll().get(0);
// 
// long rowNum = Long.parseLong(vo.getValue("rn"));
// 
// int pageNum = (int) ( (rowNum / pageSize) + 1 );
// 
// return pageNum;
// }
private int findPageNumber(String crOid, ChangeRequestQuery query, int pageSize) {
    QueryFactory qf = new QueryFactory();
    ValueQuery innerVq = new ValueQuery(qf);
    String sub1Sql = query.getSQL();
    innerVq.FROM("(" + sub1Sql + ")", "sub1");
    String createDateAlias = query.getCreateDate().getColumnAlias();
    Matcher m = Pattern.compile("change_request_\\d+\\.create_date AS (create_date_\\d+),").matcher(sub1Sql);
    if (m.find()) {
        createDateAlias = m.group(1);
    }
    innerVq.SELECT(innerVq.aSQLCharacter("oid", "oid"));
    // The rank function is forcing a group by, which we don't want to do. It also doesn't use our alias.
    // SelectableSQLDate createDate = innerVq.aSQLDate(query.getCreateDate().getColumnAlias(), query.getCreateDate().getColumnAlias());
    // AggregateFunction rank = innerVq.RANK("rn").OVER(null, new OrderBy(createDate, SortOrder.DESC));
    Selectable rank = innerVq.aSQLInteger("rn", "(ROW_NUMBER() OVER (ORDER BY " + createDateAlias + " DESC))");
    innerVq.SELECT(rank);
    ValueQuery outerVq = new ValueQuery(qf);
    outerVq.FROM("(" + innerVq.getSQL() + ")", "sub2");
    Selectable oidSel = outerVq.aSQLCharacter("oid", "oid");
    outerVq.SELECT(oidSel);
    outerVq.SELECT(outerVq.aSQLInteger("rn", "rn"));
    outerVq.WHERE(oidSel.EQ(crOid));
    List<ValueObject> voList = outerVq.getIterator().getAll();
    if (voList.size() > 0) {
        ValueObject vo = voList.get(0);
        long rowNum = Long.parseLong(vo.getValue("rn"));
        int pageNum = (int) ((rowNum / pageSize) + 1);
        return pageNum;
    } else {
        return 1;
    }
}
Also used : ValueQuery(com.runwaysdk.query.ValueQuery) QueryFactory(com.runwaysdk.query.QueryFactory) Matcher(java.util.regex.Matcher) Selectable(com.runwaysdk.query.Selectable) ValueObject(com.runwaysdk.dataaccess.ValueObject)

Example 7 with ValueObject

use of com.runwaysdk.dataaccess.ValueObject in project geoprism-registry by terraframe.

the class VectorTileBuilder method writeVectorTiles.

protected byte[] writeVectorTiles(String layerName, Envelope envelope, ValueQuery query) throws IOException {
    OIterator<ValueObject> iterator = query.getIterator();
    try {
        List<Geometry> geometries = new LinkedList<Geometry>();
        while (iterator.hasNext()) {
            ValueObject object = iterator.next();
            AttributeGeometryIF attributeIF = (AttributeGeometryIF) object.getAttributeIF(GeoserverFacade.GEOM_COLUMN);
            Geometry geometry = attributeIF.getGeometry();
            geometry.setUserData(this.getUserData(object));
            geometries.add(geometry);
        }
        GeometryFactory geomFactory = new GeometryFactory();
        IGeometryFilter acceptAllGeomFilter = geometry -> true;
        MvtLayerParams layerParams = new MvtLayerParams();
        TileGeomResult tileGeom = JtsAdapter.createTileGeom(geometries, envelope, geomFactory, layerParams, acceptAllGeomFilter);
        final VectorTile.Tile.Builder tileBuilder = VectorTile.Tile.newBuilder();
        // Create MVT layer
        final MvtLayerProps layerProps = new MvtLayerProps();
        final IUserDataConverter ignoreUserData = new UserDataConverter();
        // MVT tile geometry to MVT features
        final List<VectorTile.Tile.Feature> features = JtsAdapter.toFeatures(tileGeom.mvtGeoms, layerProps, ignoreUserData);
        final VectorTile.Tile.Layer.Builder layerBuilder = MvtLayerBuild.newLayerBuilder(layerName, layerParams);
        layerBuilder.addAllFeatures(features);
        MvtLayerBuild.writeProps(layerBuilder, layerProps);
        // Build MVT layer
        final VectorTile.Tile.Layer layer = layerBuilder.build();
        // Add built layer to MVT
        tileBuilder.addLayers(layer);
        // / Build MVT
        Tile mvt = tileBuilder.build();
        return mvt.toByteArray();
    } finally {
        iterator.close();
    }
}
Also used : VectorLayerPublisherIF(net.geoprism.ontology.VectorLayerPublisherIF) TableEntity(net.geoprism.registry.TableEntity) IUserDataConverter(com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) IGeometryFilter(com.wdtinc.mapbox_vector_tile.adapt.jts.IGeometryFilter) JtsAdapter(com.wdtinc.mapbox_vector_tile.adapt.jts.JtsAdapter) ValueObject(com.runwaysdk.dataaccess.ValueObject) VectorTile(com.wdtinc.mapbox_vector_tile.VectorTile) MvtLayerBuild(com.wdtinc.mapbox_vector_tile.build.MvtLayerBuild) MvtLayerParams(com.wdtinc.mapbox_vector_tile.build.MvtLayerParams) PSQLException(org.postgresql.util.PSQLException) ValueQuery(com.runwaysdk.query.ValueQuery) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) SQLException(java.sql.SQLException) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) JSONException(org.json.JSONException) LocalizationFacade(com.runwaysdk.localization.LocalizationFacade) GeoEntity(com.runwaysdk.system.gis.geo.GeoEntity) ResultSet(java.sql.ResultSet) Locale(java.util.Locale) Map(java.util.Map) AttributeGeometryIF(com.runwaysdk.gis.dataaccess.AttributeGeometryIF) Tile(com.wdtinc.mapbox_vector_tile.VectorTile.Tile) Geometry(com.vividsolutions.jts.geom.Geometry) LinkedList(java.util.LinkedList) AttributeIF(com.runwaysdk.dataaccess.AttributeIF) Database(com.runwaysdk.dataaccess.database.Database) MasterListVersion(net.geoprism.registry.MasterListVersion) JtsGeometry(org.postgis.jts.JtsGeometry) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) Envelope(com.vividsolutions.jts.geom.Envelope) GeoserverFacade(com.runwaysdk.system.gis.mapping.GeoserverFacade) Collection(java.util.Collection) IOException(java.io.IOException) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer) RegistryConstants(net.geoprism.registry.RegistryConstants) TileGeomResult(com.wdtinc.mapbox_vector_tile.adapt.jts.TileGeomResult) UserDataConverter(net.geoprism.ontology.UserDataConverter) OIterator(com.runwaysdk.query.OIterator) List(java.util.List) TreeMap(java.util.TreeMap) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) MvtLayerProps(com.wdtinc.mapbox_vector_tile.build.MvtLayerProps) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) IUserDataConverter(com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter) IUserDataConverter(com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter) UserDataConverter(net.geoprism.ontology.UserDataConverter) VectorTile(com.wdtinc.mapbox_vector_tile.VectorTile) Tile(com.wdtinc.mapbox_vector_tile.VectorTile.Tile) TileGeomResult(com.wdtinc.mapbox_vector_tile.adapt.jts.TileGeomResult) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer) LinkedList(java.util.LinkedList) AttributeGeometryIF(com.runwaysdk.gis.dataaccess.AttributeGeometryIF) Geometry(com.vividsolutions.jts.geom.Geometry) JtsGeometry(org.postgis.jts.JtsGeometry) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer) MvtLayerProps(com.wdtinc.mapbox_vector_tile.build.MvtLayerProps) VectorTile(com.wdtinc.mapbox_vector_tile.VectorTile) ValueObject(com.runwaysdk.dataaccess.ValueObject) MvtLayerParams(com.wdtinc.mapbox_vector_tile.build.MvtLayerParams) IGeometryFilter(com.wdtinc.mapbox_vector_tile.adapt.jts.IGeometryFilter)

Aggregations

ValueObject (com.runwaysdk.dataaccess.ValueObject)7 ValueQuery (com.runwaysdk.query.ValueQuery)6 QueryFactory (com.runwaysdk.query.QueryFactory)5 JsonArray (com.google.gson.JsonArray)3 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)3 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)3 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)3 JsonObject (com.google.gson.JsonObject)2 BusinessQuery (com.runwaysdk.business.BusinessQuery)2 Condition (com.runwaysdk.query.Condition)2 OIterator (com.runwaysdk.query.OIterator)2 IOException (java.io.IOException)2 DateFormat (java.text.DateFormat)2 JSONException (org.json.JSONException)2 UnsupportedOperationException (com.amazonaws.services.kms.model.UnsupportedOperationException)1 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)1 MdAttributeDateTimeUtil (com.runwaysdk.constants.MdAttributeDateTimeUtil)1 AttributeBooleanIF (com.runwaysdk.dataaccess.AttributeBooleanIF)1 AttributeIF (com.runwaysdk.dataaccess.AttributeIF)1 DataNotFoundException (com.runwaysdk.dataaccess.cache.DataNotFoundException)1