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