Search in sources :

Example 6 with ValueQuery

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

the class UserInfo method page.

public static JSONObject page(Integer pageSize, Integer pageNumber) {
    final RolePermissionService perms = ServiceFactory.getRolePermissionService();
    List<Organization> organizations = Organization.getUserOrganizations();
    boolean isSRA = perms.isSRA();
    boolean isRMorRCorAC = (!isSRA && !perms.isRA()) && (perms.isRM() || perms.isRC() || perms.isAC());
    List<ExternalSystem> externalSystemList = ExternalSystem.getExternalSystemsForOrg(1, 100);
    JSONArray externalSystems = new JSONArray();
    for (ExternalSystem externalSystem : externalSystemList) {
        externalSystems.put(new JSONObject(externalSystem.toJSON().toString()));
    }
    if (organizations.size() > 0 || isSRA) {
        ValueQuery vQuery = new ValueQuery(new QueryFactory());
        GeoprismUserQuery uQuery = new GeoprismUserQuery(vQuery);
        UserInfoQuery iQuery = new UserInfoQuery(vQuery);
        vQuery.SELECT(uQuery.getOid(), uQuery.getUsername(), uQuery.getFirstName(), uQuery.getLastName(), uQuery.getPhoneNumber(), uQuery.getEmail(), uQuery.getInactive());
        vQuery.SELECT(iQuery.getAltFirstName(), iQuery.getAltLastName(), iQuery.getAltPhoneNumber(), iQuery.getPosition());
        vQuery.SELECT(iQuery.getExternalSystemOid());
        vQuery.WHERE(new LeftJoinEq(uQuery.getOid(), iQuery.getGeoprismUser()));
        if (organizations.size() > 0) {
            // restrict by org code
            OrganizationQuery orgQuery = new OrganizationQuery(vQuery);
            OrganizationUserQuery relQuery = new OrganizationUserQuery(vQuery);
            for (Organization org : organizations) {
                orgQuery.OR(orgQuery.getCode().EQ(org.getCode()));
            }
            vQuery.WHERE(relQuery.parentOid().EQ(orgQuery.getOid()));
            vQuery.WHERE(uQuery.getOid().EQ(relQuery.childOid()));
        }
        if (isRMorRCorAC) {
            vQuery.WHERE(uQuery.getInactive().EQ(false));
        }
        vQuery.ORDER_BY_ASC(uQuery.getUsername());
        return serializePage(pageSize, pageNumber, externalSystems, vQuery);
    }
    JSONObject page = new JSONObject();
    page.put("resultSet", new JSONArray());
    page.put("count", 0);
    page.put("pageNumber", pageNumber);
    page.put("pageSize", pageSize);
    page.put("externalSystems", externalSystems);
    return page;
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) ValueQuery(com.runwaysdk.query.ValueQuery) QueryFactory(com.runwaysdk.query.QueryFactory) ExternalSystem(net.geoprism.registry.graph.ExternalSystem) JSONArray(org.json.JSONArray) LeftJoinEq(com.runwaysdk.query.LeftJoinEq) JSONObject(org.json.JSONObject) GeoprismUserQuery(net.geoprism.GeoprismUserQuery)

Example 7 with ValueQuery

use of com.runwaysdk.query.ValueQuery 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 8 with ValueQuery

use of com.runwaysdk.query.ValueQuery 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

ValueQuery (com.runwaysdk.query.ValueQuery)8 ValueObject (com.runwaysdk.dataaccess.ValueObject)7 QueryFactory (com.runwaysdk.query.QueryFactory)7 JsonArray (com.google.gson.JsonArray)3 JsonObject (com.google.gson.JsonObject)3 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)3 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)3 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)3 OIterator (com.runwaysdk.query.OIterator)3 BusinessQuery (com.runwaysdk.business.BusinessQuery)2 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)2 Condition (com.runwaysdk.query.Condition)2 LeftJoinEq (com.runwaysdk.query.LeftJoinEq)2 Session (com.runwaysdk.session.Session)2 IOException (java.io.IOException)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 DefaultConfiguration (net.geoprism.DefaultConfiguration)2 JSONException (org.json.JSONException)2