Search in sources :

Example 16 with ProgrammingErrorException

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

the class ExcelImporter method extract.

private static void extract(InputStream iStream, File directory) {
    // create a buffer to improve copy performance later.
    byte[] buffer = new byte[2048];
    try {
        ZipInputStream zstream = new ZipInputStream(iStream);
        ZipEntry entry;
        while ((entry = zstream.getNextEntry()) != null) {
            File file = new File(directory, entry.getName());
            try (FileOutputStream output = new FileOutputStream(file)) {
                int len = 0;
                while ((len = zstream.read(buffer)) > 0) {
                    output.write(buffer, 0, len);
                }
            }
        }
    } catch (IOException e1) {
        throw new ProgrammingErrorException(e1);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) CloseableFile(com.runwaysdk.resource.CloseableFile) File(java.io.File) CloseableDelegateFile(net.geoprism.registry.etl.CloseableDelegateFile) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 17 with ProgrammingErrorException

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

the class ShapefileImporter method getShapefileFromResource.

public static CloseableFile getShapefileFromResource(ApplicationResource res, String extension) {
    try {
        if (res.getNameExtension().equals("zip")) {
            try (InputStream is = res.openNewStream()) {
                File dir = Files.createTempDirectory(res.getBaseName()).toFile();
                extract(is, dir);
                File[] dbfs = dir.listFiles(new FilenameFilter() {

                    @Override
                    public boolean accept(File dir, String name) {
                        return name.endsWith("." + extension);
                    }
                });
                if (dbfs.length > 0) {
                    return new CloseableDelegateFile(dbfs[0], dir);
                } else {
                    throw new ImportFileFormatException();
                }
            }
        }
    } catch (IOException e) {
        throw new ProgrammingErrorException(e);
    }
    throw new ImportFileFormatException();
}
Also used : FilenameFilter(java.io.FilenameFilter) CloseableDelegateFile(net.geoprism.registry.etl.CloseableDelegateFile) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) LineString(com.vividsolutions.jts.geom.LineString) IOException(java.io.IOException) CloseableFile(com.runwaysdk.resource.CloseableFile) File(java.io.File) CloseableDelegateFile(net.geoprism.registry.etl.CloseableDelegateFile) ImportFileFormatException(net.geoprism.registry.etl.ImportFileFormatException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 18 with ProgrammingErrorException

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

the class ShapefileImporter method extract.

private static void extract(InputStream iStream, File directory) {
    // create a buffer to improve copy performance later.
    byte[] buffer = new byte[2048];
    try {
        ZipInputStream zstream = new ZipInputStream(iStream);
        ZipEntry entry;
        while ((entry = zstream.getNextEntry()) != null) {
            File file = new File(directory, entry.getName());
            try (FileOutputStream output = new FileOutputStream(file)) {
                int len = 0;
                while ((len = zstream.read(buffer)) > 0) {
                    output.write(buffer, 0, len);
                }
            }
        }
    } catch (IOException e1) {
        throw new ProgrammingErrorException(e1);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) CloseableFile(com.runwaysdk.resource.CloseableFile) File(java.io.File) CloseableDelegateFile(net.geoprism.registry.etl.CloseableDelegateFile) Point(com.vividsolutions.jts.geom.Point) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Example 19 with ProgrammingErrorException

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

the class GeoObjectImportConfiguration method fromJSON.

@Request
public GeoObjectImportConfiguration fromJSON(String json, boolean includeCoordinates) {
    super.fromJSON(json);
    SimpleDateFormat format = new SimpleDateFormat(GeoObjectImportConfiguration.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);
    ServerGeoObjectType got = ServerGeoObjectType.get(code);
    this.setType(got);
    this.setIncludeCoordinates(includeCoordinates);
    this.setPostalCode(config.has(POSTAL_CODE) && config.getBoolean(POSTAL_CODE));
    if (config.has(REVEAL_GEOMETRY_COLUMN)) {
        this.setRevealGeometryColumn(config.getString(REVEAL_GEOMETRY_COLUMN));
    }
    try {
        if (config.has(GeoObjectImportConfiguration.START_DATE)) {
            this.setStartDate(format.parse(config.getString(GeoObjectImportConfiguration.START_DATE)));
        }
        if (config.has(GeoObjectImportConfiguration.END_DATE)) {
            this.setEndDate(format.parse(config.getString(GeoObjectImportConfiguration.END_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);
            List<GeoObjectType> ancestors = got.getTypeAncestors(hierarchyType, true);
            this.setHierarchy(hierarchyType);
            if (ancestors.size() > 0) {
                this.setRoot(null);
            }
        }
    }
    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);
            ServerHierarchyType pHierarchy = got.findHierarchy(this.hierarchy, pType);
            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.addParent(new Location(pType, pHierarchy, new ConstantShapefileFunction(target), matchStrategy));
            } else {
                this.addParent(new Location(pType, pHierarchy, new BasicColumnFunction(target), matchStrategy));
            }
        }
    }
    // If the hierarchy is inherited, we need to resolve the hierarchy
    // inheritance chain and set them properly on the Location objects
    // To do this, we must start from the bottom and resolve upwards
    ServerHierarchyType ht = this.hierarchy;
    for (int i = this.locations.size() - 1; i >= 0; --i) {
        Location loc = this.locations.get(i);
        ht = got.findHierarchy(ht, loc.getType());
        loc.setHierarchy(ht);
    }
    return this;
}
Also used : ServerHierarchyType(net.geoprism.registry.model.ServerHierarchyType) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) BasicColumnFunction(net.geoprism.data.importer.BasicColumnFunction) JSONArray(org.json.JSONArray) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) JSONObject(org.json.JSONObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Request(com.runwaysdk.session.Request)

Example 20 with ProgrammingErrorException

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

the class GraphValidationService method getValidators.

/**
 * Retrieve all implementations of GraphValidator.
 */
public static List<GraphValidator> getValidators() {
    List<GraphValidator> configurations = new ArrayList<GraphValidator>();
    ServiceLoader<GraphValidator> loader = ServiceLoader.load(GraphValidator.class, Thread.currentThread().getContextClassLoader());
    try {
        Iterator<GraphValidator> it = loader.iterator();
        while (it.hasNext()) {
            configurations.add(it.next());
        }
    } catch (ServiceConfigurationError serviceError) {
        throw new ProgrammingErrorException(serviceError);
    }
    return configurations;
}
Also used : ArrayList(java.util.ArrayList) ServiceConfigurationError(java.util.ServiceConfigurationError) 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