Search in sources :

Example 66 with ProgrammingErrorException

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

the class VectorTileBuilder method writeVectorLayer.

public VectorTile.Tile.Layer writeVectorLayer(String layerName, Envelope bounds, ResultSet resultSet) throws IOException {
    try {
        List<Geometry> geometries = new LinkedList<Geometry>();
        while (resultSet.next()) {
            String label = resultSet.getString("default_locale");
            Map<String, String> data = new TreeMap<String, String>();
            data.put(GeoEntity.OID, resultSet.getString("oid"));
            data.put(DefaultAttribute.CODE.getName(), resultSet.getString("code"));
            data.put(DefaultAttribute.UID.getName(), resultSet.getString("uid"));
            data.put(GeoEntity.DISPLAYLABEL, label);
            for (Locale locale : locales) {
                try {
                    data.put(GeoEntity.DISPLAYLABEL + "_" + locale.toString().toLowerCase(), resultSet.getString(locale.toString()));
                } catch (PSQLException e) {
                // Ignore: The column doesn't exist because the list was created
                // before the locale was installed
                }
            }
            JtsGeometry geom = (JtsGeometry) resultSet.getObject(GeoserverFacade.GEOM_COLUMN);
            if (geom != null) {
                Geometry geometry = geom.getGeometry();
                geometry.setUserData(data);
                geometries.add(geometry);
            }
        }
        GeometryFactory geomFactory = new GeometryFactory();
        IGeometryFilter acceptAllGeomFilter = geometry -> true;
        MvtLayerParams layerParams = new MvtLayerParams();
        TileGeomResult tileGeom = JtsAdapter.createTileGeom(geometries, bounds, geomFactory, layerParams, acceptAllGeomFilter);
        // 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
        return layerBuilder.build();
    } catch (SQLException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : Locale(java.util.Locale) 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) PSQLException(org.postgresql.util.PSQLException) SQLException(java.sql.SQLException) IUserDataConverter(com.wdtinc.mapbox_vector_tile.adapt.jts.IUserDataConverter) UserDataConverter(net.geoprism.ontology.UserDataConverter) PSQLException(org.postgresql.util.PSQLException) TreeMap(java.util.TreeMap) TileGeomResult(com.wdtinc.mapbox_vector_tile.adapt.jts.TileGeomResult) Layer(com.wdtinc.mapbox_vector_tile.VectorTile.Tile.Layer) LinkedList(java.util.LinkedList) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Geometry(com.vividsolutions.jts.geom.Geometry) JtsGeometry(org.postgis.jts.JtsGeometry) JtsGeometry(org.postgis.jts.JtsGeometry) MvtLayerProps(com.wdtinc.mapbox_vector_tile.build.MvtLayerProps) VectorTile(com.wdtinc.mapbox_vector_tile.VectorTile) MvtLayerParams(com.wdtinc.mapbox_vector_tile.build.MvtLayerParams) IGeometryFilter(com.wdtinc.mapbox_vector_tile.adapt.jts.IGeometryFilter)

Example 67 with ProgrammingErrorException

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

the class DHIS2TestService method metadataGet.

@Override
public <T> MetadataGetResponse<T> metadataGet(Class<?> dhis2Type, List<NameValuePair> params) throws InvalidLoginException, HTTPException {
    String objectNamePlural = DHIS2Objects.getPluralObjectNameFromClass(dhis2Type);
    try {
        if (objectNamePlural.equals(DHIS2Objects.OPTIONS)) {
            InputStream data = Thread.currentThread().getContextClassLoader().getResourceAsStream("dhis2/2.31.9/options.json");
            String resp = IOUtils.toString(data, "UTF-8");
            return new MetadataGetResponse<T>(resp, 200, objectNamePlural, dhis2Type);
        } else if (objectNamePlural.equals(DHIS2Objects.OPTIONSETS)) {
            InputStream data = Thread.currentThread().getContextClassLoader().getResourceAsStream("dhis2/2.31.9/optionsets.json");
            String resp = IOUtils.toString(data, "UTF-8");
            return new MetadataGetResponse<T>(resp, 200, objectNamePlural, dhis2Type);
        } else if (objectNamePlural.equals(DHIS2Objects.ATTRIBUTES)) {
            InputStream data = Thread.currentThread().getContextClassLoader().getResourceAsStream("dhis2/2.31.9/attributes.json");
            String resp = IOUtils.toString(data, "UTF-8");
            return new MetadataGetResponse<T>(resp, 200, objectNamePlural, dhis2Type);
        } else if (objectNamePlural.equals(DHIS2Objects.ORGANISATION_UNIT_GROUPS)) {
            InputStream data = Thread.currentThread().getContextClassLoader().getResourceAsStream("dhis2/default/organisationUnitGroups.json");
            String resp = IOUtils.toString(data, "UTF-8");
            return new MetadataGetResponse<T>(resp, 200, objectNamePlural, dhis2Type);
        } else {
            JsonObject jo = new JsonObject();
            JsonObject system = new JsonObject();
            system.addProperty("id", "eed3d451-4ff5-4193-b951-ffcc68954299");
            system.addProperty("rev", "86fbbf7");
            system.addProperty("version", "2.31.9");
            system.addProperty("date", "2020-07-17T23:03:46.853");
            jo.add("system", system);
            jo.add(objectNamePlural, new JsonArray());
            return new MetadataGetResponse<T>(jo.toString(), 200, objectNamePlural, dhis2Type);
        }
    } catch (IOException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : JsonArray(com.google.gson.JsonArray) InputStream(java.io.InputStream) JsonObject(com.google.gson.JsonObject) MetadataGetResponse(net.geoprism.dhis2.dhis2adapter.response.MetadataGetResponse) IOException(java.io.IOException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Aggregations

ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)67 IOException (java.io.IOException)34 SimpleDateFormat (java.text.SimpleDateFormat)21 JsonObject (com.google.gson.JsonObject)18 File (java.io.File)16 ParseException (java.text.ParseException)16 InputStream (java.io.InputStream)13 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)13 MdAttributeConcreteDAOIF (com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF)12 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)12 MdBusinessDAOIF (com.runwaysdk.dataaccess.MdBusinessDAOIF)11 JSONException (org.json.JSONException)11 JsonArray (com.google.gson.JsonArray)10 List (java.util.List)10 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)9 ArrayList (java.util.ArrayList)9 Date (java.util.Date)9 HashMap (java.util.HashMap)8 Collectors (java.util.stream.Collectors)8 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)8