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);
}
}
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();
}
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;
}
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;
}
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);
}
}
Aggregations