use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class ListTypeFhirExporter method write.
public void write(Bundle bundle, Writer writer) {
FhirContext ctx = this.connection.getFhirContext();
IParser parser = ctx.newJsonParser();
// Serialize it
try {
parser.encodeResourceToWriter(bundle, writer);
} catch (DataFormatException | IOException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class BusinessObjectImportConfiguration method fromJSON.
@Request
public BusinessObjectImportConfiguration fromJSON(String json, boolean includeCoordinates) {
super.fromJSON(json);
SimpleDateFormat format = new SimpleDateFormat(BusinessObjectImportConfiguration.DATE_FORMAT);
format.setTimeZone(GeoRegistryUtil.SYSTEM_TIMEZONE);
JSONObject config = new JSONObject(json);
JSONObject type = config.getJSONObject(TYPE);
JSONArray locations = config.has(LOCATIONS) ? config.getJSONArray(LOCATIONS) : new JSONArray();
JSONArray attributes = type.getJSONArray(GeoObjectType.JSON_ATTRIBUTES);
String code = type.getString(GeoObjectType.JSON_CODE);
BusinessType businessType = BusinessType.getByCode(code);
this.setType(businessType);
try {
if (config.has(BusinessObjectImportConfiguration.DATE)) {
this.setDate(format.parse(config.getString(BusinessObjectImportConfiguration.DATE)));
}
} catch (ParseException e) {
throw new ProgrammingErrorException(e);
}
if (config.has(HIERARCHY)) {
String hCode = config.getString(HIERARCHY);
if (hCode.length() > 0) {
ServerHierarchyType hierarchyType = ServerHierarchyType.get(hCode);
this.setHierarchy(hierarchyType);
}
}
if (config.has(EXCLUSIONS)) {
JSONArray exclusions = config.getJSONArray(EXCLUSIONS);
for (int i = 0; i < exclusions.length(); i++) {
JSONObject exclusion = exclusions.getJSONObject(i);
String attributeName = exclusion.getString(AttributeType.JSON_CODE);
String value = exclusion.getString(VALUE);
this.addExclusion(attributeName, value);
}
}
for (int i = 0; i < attributes.length(); i++) {
JSONObject attribute = attributes.getJSONObject(i);
if (attribute.has(TARGET)) {
String attributeName = attribute.getString(AttributeType.JSON_CODE);
// In the case of a spreadsheet, this ends up being the column header
String target = attribute.getString(TARGET);
if (attribute.has("locale")) {
String locale = attribute.getString("locale");
if (this.getFunction(attributeName) == null) {
this.setFunction(attributeName, new LocalizedValueFunction());
}
LocalizedValueFunction function = (LocalizedValueFunction) this.getFunction(attributeName);
function.add(locale, new BasicColumnFunction(target));
} else {
this.setFunction(attributeName, new BasicColumnFunction(target));
}
}
}
for (int i = 0; i < locations.length(); i++) {
JSONObject location = locations.getJSONObject(i);
if (location.has(TARGET) && location.getString(TARGET).length() > 0 && location.has(MATCH_STRATEGY) && location.getString(MATCH_STRATEGY).length() > 0) {
String pCode = location.getString(AttributeType.JSON_CODE);
ServerGeoObjectType pType = ServerGeoObjectType.get(pCode);
String target = location.getString(TARGET);
ParentMatchStrategy matchStrategy = ParentMatchStrategy.valueOf(location.getString(MATCH_STRATEGY));
// coming in with use BasicColumnFunctions
if (location.has("type") && location.getString("type").equals(ConstantShapefileFunction.class.getName())) {
this.addLocation(new Location(pType, this.hierarchy, new ConstantShapefileFunction(target), matchStrategy));
} else {
this.addLocation(new Location(pType, this.hierarchy, new BasicColumnFunction(target), matchStrategy));
}
}
}
return this;
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class ExcelImporter method process.
@Request
private void process(ImportStage stage, File file) throws InvocationTargetException, IOException {
try {
/*
* Check permissions
*/
ImportConfiguration config = this.getObjectImporter().getConfiguration();
config.enforceCreatePermissions();
// TODO Determine permissions for
this.progressListener.setWorkTotal(this.getWorkTotal(file));
if (this.config.isExternalImport() && this.config.getExternalSystem() instanceof RevealExternalSystem && this.config instanceof GeoObjectImportConfiguration) {
this.excelHandler = new RevealExcelContentHandler(this.objectImporter, stage, this.getStartIndex(), ((GeoObjectImportConfiguration) this.config).getRevealGeometryColumn());
} else {
this.excelHandler = new ExcelContentHandler(this.objectImporter, stage, this.getStartIndex());
}
ExcelDataFormatter formatter = new ExcelDataFormatter();
ExcelSheetReader reader = new ExcelSheetReader(excelHandler, formatter);
reader.process(new FileInputStream(file));
} catch (Exception e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class ExcelFieldContentsHandler method endSheet.
@Override
public void endSheet() {
try {
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());
Set<Integer> keys = this.map.keySet();
for (Integer key : keys) {
Field field = this.map.get(key);
validateField(field, key);
String name = field.getName();
String baseType = field.getBaseType();
attributes.getJSONArray(baseType).put(name);
if (baseType.equals(GeoObjectImportConfiguration.NUMERIC)) {
attributes.getJSONArray(GeoObjectImportConfiguration.TEXT).put(name);
}
}
JSONObject sheet = new JSONObject();
sheet.put("name", this.sheetName);
sheet.put("attributes", attributes);
this.sheets.put(sheet);
} catch (JSONException e) {
throw new ProgrammingErrorException(e);
}
}
use of com.runwaysdk.dataaccess.ProgrammingErrorException in project geoprism-registry by terraframe.
the class ExcelService method getBusinessTypeConfiguration.
public JSONObject getBusinessTypeConfiguration(String type, Date date, String fileName, InputStream fileStream, ImportStrategy strategy, Boolean copyBlank) {
// Save the file to the file system
try {
BusinessType businessType = BusinessType.getByCode(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(BusinessObjectImportConfiguration.TYPE, this.getType(businessType));
object.put(BusinessObjectImportConfiguration.SHEET, handler.getSheets().getJSONObject(0));
object.put(BusinessObjectImportConfiguration.VAULT_FILE_ID, vf.getOid());
object.put(BusinessObjectImportConfiguration.FILE_NAME, fileName);
object.put(BusinessObjectImportConfiguration.IMPORT_STRATEGY, strategy.name());
object.put(BusinessObjectImportConfiguration.FORMAT_TYPE, FormatImporterType.EXCEL.name());
object.put(BusinessObjectImportConfiguration.OBJECT_TYPE, ObjectImporterFactory.ObjectImportType.BUSINESS_OBJECT.name());
object.put(BusinessObjectImportConfiguration.COPY_BLANK, copyBlank);
if (date != null) {
object.put(BusinessObjectImportConfiguration.DATE, format.format(date));
}
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);
}
}
Aggregations