Search in sources :

Example 56 with ProgrammingErrorException

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);
    }
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) DataFormatException(ca.uhn.fhir.parser.DataFormatException) IOException(java.io.IOException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) IParser(ca.uhn.fhir.parser.IParser)

Example 57 with ProgrammingErrorException

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;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ConstantShapefileFunction(net.geoprism.registry.io.ConstantShapefileFunction) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JSONArray(org.json.JSONArray) BusinessType(net.geoprism.registry.BusinessType) LocalizedValueFunction(net.geoprism.registry.io.LocalizedValueFunction) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JSONObject(org.json.JSONObject) ParseException(java.text.ParseException) ParentMatchStrategy(net.geoprism.registry.io.ParentMatchStrategy) SimpleDateFormat(java.text.SimpleDateFormat) Location(net.geoprism.registry.io.Location) Request(com.runwaysdk.session.Request)

Example 58 with ProgrammingErrorException

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);
    }
}
Also used : GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ExcelDataFormatter(net.geoprism.data.etl.excel.ExcelDataFormatter) RevealExternalSystem(net.geoprism.registry.graph.RevealExternalSystem) ExcelSheetReader(net.geoprism.data.etl.excel.ExcelSheetReader) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) FileInputStream(java.io.FileInputStream) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) ImportFileFormatException(net.geoprism.registry.etl.ImportFileFormatException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LatLonException(net.geoprism.registry.io.LatLonException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Request(com.runwaysdk.session.Request)

Example 59 with ProgrammingErrorException

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);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 60 with ProgrammingErrorException

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);
    }
}
Also used : SmartException(com.runwaysdk.business.SmartException) InputStream(java.io.InputStream) InvalidExcelFileException(net.geoprism.data.etl.excel.InvalidExcelFileException) BusinessType(net.geoprism.registry.BusinessType) 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)

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