Search in sources :

Example 21 with ProgrammingErrorException

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

the class VertexServerGeoObject method bbox.

@Override
public String bbox(Date date) {
    Geometry geometry = (Geometry) this.getValue(getGeometryAttributeName(), date);
    if (geometry != null) {
        try {
            Envelope e = geometry.getEnvelopeInternal();
            JSONArray bboxArr = new JSONArray();
            bboxArr.put(e.getMinX());
            bboxArr.put(e.getMinY());
            bboxArr.put(e.getMaxX());
            bboxArr.put(e.getMaxY());
            return bboxArr.toString();
        } catch (JSONException ex) {
            throw new ProgrammingErrorException(ex);
        }
    }
    return null;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Envelope(com.vividsolutions.jts.geom.Envelope) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 22 with ProgrammingErrorException

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

the class ExcelService method getExcelConfiguration.

public JSONObject getExcelConfiguration(String type, Date startDate, Date endDate, String fileName, InputStream fileStream, ImportStrategy strategy, Boolean copyBlank) {
    // Save the file to the file system
    try {
        ServerGeoObjectType geoObjectType = ServerGeoObjectType.get(type);
        VaultFile vf = VaultFile.createAndApply(fileName, fileStream);
        try (InputStream is = vf.openNewStream()) {
            SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
            format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
            ExcelFieldContentsHandler handler = new ExcelFieldContentsHandler();
            ExcelDataFormatter formatter = new ExcelDataFormatter();
            ExcelSheetReader reader = new ExcelSheetReader(handler, formatter);
            reader.process(is);
            JSONObject object = new JSONObject();
            object.put(GeoObjectImportConfiguration.TYPE, this.getType(geoObjectType));
            object.put(GeoObjectImportConfiguration.SHEET, handler.getSheets().getJSONObject(0));
            object.put(ImportConfiguration.VAULT_FILE_ID, vf.getOid());
            object.put(ImportConfiguration.FILE_NAME, fileName);
            object.put(GeoObjectImportConfiguration.HAS_POSTAL_CODE, PostalCodeFactory.isAvailable(geoObjectType));
            object.put(ImportConfiguration.IMPORT_STRATEGY, strategy.name());
            object.put(ImportConfiguration.FORMAT_TYPE, FormatImporterType.EXCEL.name());
            object.put(ImportConfiguration.OBJECT_TYPE, ObjectImporterFactory.ObjectImportType.GEO_OBJECT.name());
            object.put(ImportConfiguration.COPY_BLANK, copyBlank);
            if (startDate != null) {
                object.put(GeoObjectImportConfiguration.START_DATE, format.format(startDate));
            }
            if (endDate != null) {
                object.put(GeoObjectImportConfiguration.END_DATE, format.format(endDate));
            }
            return object;
        }
    } catch (InvalidFormatException e) {
        InvalidExcelFileException ex = new InvalidExcelFileException(e);
        ex.setFileName(fileName);
        throw ex;
    } catch (RunwayException | SmartException e) {
        throw e;
    } catch (Exception e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : SmartException(com.runwaysdk.business.SmartException) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) InputStream(java.io.InputStream) InvalidExcelFileException(net.geoprism.data.etl.excel.InvalidExcelFileException) ExcelSheetReader(net.geoprism.data.etl.excel.ExcelSheetReader) ExcelFieldContentsHandler(net.geoprism.registry.excel.ExcelFieldContentsHandler) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) RunwayException(com.runwaysdk.RunwayException) SmartException(com.runwaysdk.business.SmartException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) RunwayException(com.runwaysdk.RunwayException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) InvalidExcelFileException(net.geoprism.data.etl.excel.InvalidExcelFileException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) ExcelDataFormatter(net.geoprism.data.etl.excel.ExcelDataFormatter) JSONObject(org.json.JSONObject) VaultFile(com.runwaysdk.system.VaultFile) SimpleDateFormat(java.text.SimpleDateFormat)

Example 23 with ProgrammingErrorException

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

the class ShapefileService method getShapefileConfiguration.

@Request(RequestType.SESSION)
public JSONObject getShapefileConfiguration(String sessionId, String type, Date startDate, Date endDate, String fileName, InputStream fileStream, ImportStrategy strategy, Boolean copyBlank) {
    // Save the file to the file system
    try {
        ServerGeoObjectType geoObjectType = ServerGeoObjectType.get(type);
        VaultFile vf = VaultFile.createAndApply(fileName, fileStream);
        try (CloseableFile dbf = ShapefileImporter.getShapefileFromResource(vf, "dbf")) {
            SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.DATE_FORMAT);
            format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
            JSONObject object = new JSONObject();
            object.put(GeoObjectImportConfiguration.TYPE, this.getType(geoObjectType));
            object.put(GeoObjectImportConfiguration.SHEET, this.getSheetInformation(dbf));
            object.put(ImportConfiguration.VAULT_FILE_ID, vf.getOid());
            object.put(ImportConfiguration.FILE_NAME, fileName);
            object.put(GeoObjectImportConfiguration.HAS_POSTAL_CODE, PostalCodeFactory.isAvailable(geoObjectType));
            object.put(ImportConfiguration.IMPORT_STRATEGY, strategy.name());
            object.put(ImportConfiguration.FORMAT_TYPE, FormatImporterType.SHAPEFILE.name());
            object.put(ImportConfiguration.OBJECT_TYPE, ObjectImporterFactory.ObjectImportType.GEO_OBJECT.name());
            object.put(ImportConfiguration.COPY_BLANK, copyBlank);
            if (startDate != null) {
                object.put(GeoObjectImportConfiguration.START_DATE, format.format(startDate));
            }
            if (endDate != null) {
                object.put(GeoObjectImportConfiguration.END_DATE, format.format(endDate));
            }
            return object;
        }
    } catch (RunwayException | SmartException e) {
        throw e;
    } catch (Exception e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : JSONObject(org.json.JSONObject) SmartException(com.runwaysdk.business.SmartException) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) VaultFile(com.runwaysdk.system.VaultFile) CloseableFile(com.runwaysdk.resource.CloseableFile) SimpleDateFormat(java.text.SimpleDateFormat) RunwayException(com.runwaysdk.RunwayException) SmartException(com.runwaysdk.business.SmartException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) RunwayException(com.runwaysdk.RunwayException) ShapefileFormatException(net.geoprism.registry.etl.ShapefileFormatException) IOException(java.io.IOException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Request(com.runwaysdk.session.Request)

Example 24 with ProgrammingErrorException

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

the class MasterListShapefileExporter method writeDictionaryFile.

/**
 * Writes an additional "data dictionary" / metadata excel spreadsheet to the directory, which is intended to be
 * part of the final Shapfile. This is useful for downstream developers trying to make sense of the GIS data.
 *
 * See also:
 * - https://github.com/terraframe/geoprism-registry/issues/628
 */
private void writeDictionaryFile(File directory) {
    MdBusinessDAOIF mdBusiness = MdBusinessDAO.get(this.version.getMdBusinessOid());
    List<? extends MdAttributeConcreteDAOIF> mdAttributes = mdBusiness.definesAttributesOrdered().stream().filter(mdAttribute -> this.version.isValid(mdAttribute)).collect(Collectors.toList());
    mdAttributes = mdAttributes.stream().filter(mdAttribute -> !mdAttribute.definesAttribute().equals("invalid")).collect(Collectors.toList());
    String excelFilter;
    if (filterJson == null) {
        excelFilter = "[{attribute:invalid,value:false}]";
    } else {
        excelFilter = new String(filterJson);
    }
    try {
        File file = new File(directory, "metadata.xlsx");
        FileOutputStream fos = new FileOutputStream(file);
        MasterListExcelExporter exporter = new MasterListExcelExporter(this.version, mdBusiness, mdAttributes, excelFilter, this.columnNames, new MasterListExcelExporterSheet[] { MasterListExcelExporterSheet.DICTIONARY, MasterListExcelExporterSheet.METADATA });
        Workbook wb = exporter.createWorkbook();
        wb.write(fos);
    } catch (IOException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : MdAttributeMultiPointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributeMultiPointDAOIF) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) Transaction(org.geotools.data.Transaction) Date(java.util.Date) MdAttributeBooleanDAOIF(com.runwaysdk.dataaccess.MdAttributeBooleanDAOIF) LoggerFactory(org.slf4j.LoggerFactory) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) PipedInputStream(java.io.PipedInputStream) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Map(java.util.Map) MdAttributeCharacterDAOIF(com.runwaysdk.dataaccess.MdAttributeCharacterDAOIF) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) ZipEntry(java.util.zip.ZipEntry) MdAttributeGeometryDAOIF(com.runwaysdk.gis.dataaccess.MdAttributeGeometryDAOIF) MdAttributeTextDAOIF(com.runwaysdk.dataaccess.MdAttributeTextDAOIF) MasterList(net.geoprism.registry.MasterList) BusinessQuery(com.runwaysdk.business.BusinessQuery) MasterListVersion(net.geoprism.registry.MasterListVersion) UnsupportedOperationException(com.amazonaws.services.kms.model.UnsupportedOperationException) DefaultGeographicCRS(org.geotools.referencing.crs.DefaultGeographicCRS) MdAttributeLongDAOIF(com.runwaysdk.dataaccess.MdAttributeLongDAOIF) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) MdAttributeLineStringDAOIF(com.runwaysdk.gis.dataaccess.MdAttributeLineStringDAOIF) MdAttributeDateDAOIF(com.runwaysdk.dataaccess.MdAttributeDateDAOIF) ZipOutputStream(java.util.zip.ZipOutputStream) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) MdAttributeMultiPolygonDAOIF(com.runwaysdk.gis.dataaccess.MdAttributeMultiPolygonDAOIF) HashMap(java.util.HashMap) ShapefileDataStoreFactory(org.geotools.data.shapefile.ShapefileDataStoreFactory) FeatureCollection(org.geotools.feature.FeatureCollection) MdAttributeDoubleDAOIF(com.runwaysdk.dataaccess.MdAttributeDoubleDAOIF) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) LineString(com.vividsolutions.jts.geom.LineString) Point(com.vividsolutions.jts.geom.Point) ArrayList(java.util.ArrayList) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) MdAttributeMultiLineStringDAOIF(com.runwaysdk.gis.dataaccess.MdAttributeMultiLineStringDAOIF) MdAttributeConcreteDAOIF(com.runwaysdk.dataaccess.MdAttributeConcreteDAOIF) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) Charset(java.nio.charset.Charset) SessionPredicate(net.geoprism.gis.geoserver.SessionPredicate) MasterListExcelExporter(net.geoprism.registry.excel.MasterListExcelExporter) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) VaultProperties(com.runwaysdk.constants.VaultProperties) Logger(org.slf4j.Logger) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) MdAttributeDateTimeDAOIF(com.runwaysdk.dataaccess.MdAttributeDateTimeDAOIF) FileInputStream(java.io.FileInputStream) PipedOutputStream(java.io.PipedOutputStream) RegistryConstants(net.geoprism.registry.RegistryConstants) File(java.io.File) OIterator(com.runwaysdk.query.OIterator) Workbook(org.apache.poi.ss.usermodel.Workbook) MdAttributePolygonDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePolygonDAOIF) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Business(com.runwaysdk.business.Business) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) DefaultTransaction(org.geotools.data.DefaultTransaction) MdAttributePointDAOIF(com.runwaysdk.gis.dataaccess.MdAttributePointDAOIF) MasterListExcelExporterSheet(net.geoprism.registry.excel.MasterListExcelExporter.MasterListExcelExporterSheet) InputStream(java.io.InputStream) Polygon(com.vividsolutions.jts.geom.Polygon) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) FileOutputStream(java.io.FileOutputStream) MasterListExcelExporter(net.geoprism.registry.excel.MasterListExcelExporter) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) IOException(java.io.IOException) File(java.io.File) Workbook(org.apache.poi.ss.usermodel.Workbook) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 25 with ProgrammingErrorException

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

the class MasterListShapefileExporter method writeToFile.

public File writeToFile() throws IOException {
    SimpleFeatureType featureType = createFeatureType();
    FeatureCollection<SimpleFeatureType, SimpleFeature> collection = features(featureType);
    String name = SessionPredicate.generateId();
    File root = new File(new File(VaultProperties.getPath("vault.default"), "files"), name);
    root.mkdirs();
    File directory = new File(root, this.getList().getCode());
    directory.mkdirs();
    File file = new File(directory, this.getList().getCode() + ".shp");
    /*
     * Get an output file name and create the new shapefile
     */
    ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
    Map<String, Serializable> params = new HashMap<String, Serializable>();
    params.put("url", file.toURI().toURL());
    params.put("create spatial index", Boolean.TRUE);
    params.put("charset", "UTF-8");
    ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
    dataStore.setCharset(Charset.forName("UTF-8"));
    dataStore.createSchema(featureType);
    /*
     * Write the features to the shapefile
     */
    try (Transaction transaction = new DefaultTransaction()) {
        String typeName = dataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
        if (featureSource instanceof SimpleFeatureStore) {
            SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
            featureStore.setTransaction(transaction);
            try {
                featureStore.addFeatures(collection);
                transaction.commit();
            } catch (Exception problem) {
                transaction.rollback();
                throw new ProgrammingErrorException(problem);
            }
        } else {
            throw new ProgrammingErrorException(typeName + " does not support read/write access");
        }
    }
    dataStore.dispose();
    this.writeEncodingFile(directory);
    this.writeDictionaryFile(directory);
    return directory;
}
Also used : Serializable(java.io.Serializable) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) UnsupportedOperationException(com.amazonaws.services.kms.model.UnsupportedOperationException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) IOException(java.io.IOException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) ShapefileDataStoreFactory(org.geotools.data.shapefile.ShapefileDataStoreFactory) File(java.io.File)

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