Search in sources :

Example 61 with ProgrammingErrorException

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

the class ShapefileService method getSheetInformation.

private JSONObject getSheetInformation(File dbf) {
    try {
        ShapefileDataStore store = new ShapefileDataStore(dbf.toURI().toURL());
        try {
            String[] typeNames = store.getTypeNames();
            if (typeNames.length > 0) {
                String typeName = typeNames[0];
                FeatureSource<SimpleFeatureType, SimpleFeature> source = store.getFeatureSource(typeName);
                SimpleFeatureType schema = source.getSchema();
                List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors();
                JSONObject attributes = new JSONObject();
                attributes.put(AttributeBooleanType.TYPE, new JSONArray());
                attributes.put(GeoObjectImportConfiguration.TEXT, new JSONArray());
                attributes.put(GeoObjectImportConfiguration.NUMERIC, new JSONArray());
                attributes.put(AttributeDateType.TYPE, new JSONArray());
                for (AttributeDescriptor descriptor : descriptors) {
                    if (!(descriptor instanceof GeometryDescriptor)) {
                        String name = descriptor.getName().getLocalPart();
                        String baseType = GeoObjectImportConfiguration.getBaseType(descriptor.getType());
                        attributes.getJSONArray(baseType).put(name);
                        if (baseType.equals(GeoObjectImportConfiguration.NUMERIC)) {
                            attributes.getJSONArray(GeoObjectImportConfiguration.TEXT).put(name);
                        }
                    }
                }
                JSONObject sheet = new JSONObject();
                sheet.put("name", typeName);
                sheet.put("attributes", attributes);
                return sheet;
            } else {
                // TODO Change exception type
                throw new ProgrammingErrorException("Shapefile does not contain any types");
            }
        } finally {
            store.dispose();
        }
    } catch (RuntimeException e) {
        Throwable cause = e.getCause();
        if (cause instanceof IOException) {
            throw new ShapefileFormatException(e);
        }
        throw e;
    } catch (Exception e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) ShapefileFormatException(net.geoprism.registry.etl.ShapefileFormatException) JSONArray(org.json.JSONArray) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) SmartException(com.runwaysdk.business.SmartException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) RunwayException(com.runwaysdk.RunwayException) ShapefileFormatException(net.geoprism.registry.etl.ShapefileFormatException) IOException(java.io.IOException) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) JSONObject(org.json.JSONObject)

Example 62 with ProgrammingErrorException

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

the class SynchronizationConfigService method generateFile.

@Request(RequestType.SESSION)
public InputStream generateFile(String sessionId, String oid) {
    SynchronizationConfig synchorinzation = SynchronizationConfig.get(oid);
    ServiceFactory.getRolePermissionService().enforceRA(synchorinzation.getOrganization().getCode());
    ExternalSystemSyncConfig config = synchorinzation.buildConfiguration();
    if (config instanceof FhirSyncExportConfig) {
        try {
            FhirExportSynchronizationManager manager = new FhirExportSynchronizationManager((FhirSyncExportConfig) config, null);
            return manager.generateZipFile();
        } catch (IOException e) {
            throw new ProgrammingErrorException(e);
        }
    }
    throw new UnsupportedOperationException();
}
Also used : FhirExportSynchronizationManager(net.geoprism.registry.etl.fhir.FhirExportSynchronizationManager) ExternalSystemSyncConfig(net.geoprism.registry.etl.ExternalSystemSyncConfig) FhirSyncExportConfig(net.geoprism.registry.etl.FhirSyncExportConfig) SynchronizationConfig(net.geoprism.registry.SynchronizationConfig) IOException(java.io.IOException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Request(com.runwaysdk.session.Request)

Example 63 with ProgrammingErrorException

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

the class GeoObjectAtTimeShapefileExporter 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.getType().getCode());
    directory.mkdirs();
    File file = new File(directory, this.getType().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);
    ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
    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();
    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)

Example 64 with ProgrammingErrorException

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

the class ListTypeShapefileExporter 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)

Example 65 with ProgrammingErrorException

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

the class ListTypeShapefileExporter 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());
    try {
        File file = new File(directory, "metadata.xlsx");
        FileOutputStream fos = new FileOutputStream(file);
        ListTypeExcelExporter exporter = new ListTypeExcelExporter(this.version, mdBusiness, mdAttributes, new ListTypeExcelExporterSheet[] { ListTypeExcelExporterSheet.DICTIONARY, ListTypeExcelExporterSheet.METADATA }, criteria);
        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) JsonObject(com.google.gson.JsonObject) 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) MdAttributeFloatDAOIF(com.runwaysdk.dataaccess.MdAttributeFloatDAOIF) 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) BusinessQuery(com.runwaysdk.business.BusinessQuery) UnsupportedOperationException(com.amazonaws.services.kms.model.UnsupportedOperationException) ListTypeExcelExporter(net.geoprism.registry.excel.ListTypeExcelExporter) 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) ListTypeExcelExporterSheet(net.geoprism.registry.excel.ListTypeExcelExporter.ListTypeExcelExporterSheet) 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) 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) ListType(net.geoprism.registry.ListType) ListTypeVersion(net.geoprism.registry.ListTypeVersion) OIterator(com.runwaysdk.query.OIterator) MdAttributeIntegerDAOIF(com.runwaysdk.dataaccess.MdAttributeIntegerDAOIF) 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) InputStream(java.io.InputStream) Polygon(com.vividsolutions.jts.geom.Polygon) MdBusinessDAOIF(com.runwaysdk.dataaccess.MdBusinessDAOIF) FileOutputStream(java.io.FileOutputStream) ListTypeExcelExporter(net.geoprism.registry.excel.ListTypeExcelExporter) IOException(java.io.IOException) File(java.io.File) Workbook(org.apache.poi.ss.usermodel.Workbook) 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