Search in sources :

Example 1 with ShapefileFunction

use of net.geoprism.data.importer.ShapefileFunction in project geoprism-registry by terraframe.

the class BusinessObjectImporter method validateRow.

@Transaction
public void validateRow(FeatureRow row) throws InterruptedException {
    try {
        // Refresh the session because it might expire on long imports
        final long curWorkProgress = this.progressListener.getWorkProgress();
        if ((this.lastValidateSessionRefresh + BusinessObjectImporter.refreshSessionRecordCount) < curWorkProgress) {
            SessionFacade.renewSession(Session.getCurrentSession().getOid());
            this.lastValidateSessionRefresh = curWorkProgress;
        }
        try {
            if (this.configuration.getHierarchy() != null && this.configuration.getLocations().size() > 0) {
                this.getGeoObject(row);
            }
            /*
         * 2. Check for serialization and term problems
         */
            String code = this.getCode(row);
            if (code == null || code.length() <= 0) {
                RequiredMappingException ex = new RequiredMappingException();
                ex.setAttributeLabel(GeoObjectTypeMetadata.getAttributeDisplayLabel(DefaultAttribute.CODE.getName()));
                throw ex;
            }
            BusinessObject entity;
            entity = BusinessObject.newInstance(this.configuration.getType());
            Map<String, AttributeType> attributes = this.getConfiguration().getType().getAttributeMap();
            Set<Entry<String, AttributeType>> entries = attributes.entrySet();
            for (Entry<String, AttributeType> entry : entries) {
                String attributeName = entry.getKey();
                if (!attributeName.equals(GeoObject.CODE)) {
                    ShapefileFunction function = this.configuration.getFunction(attributeName);
                    if (function != null) {
                        Object value = function.getValue(row);
                        if (value != null && !this.isEmptyString(value)) {
                            AttributeType attributeType = entry.getValue();
                            this.setValue(entity, attributeType, attributeName, value);
                        }
                    }
                }
            }
        } catch (IgnoreRowException e) {
        // Do nothing
        } catch (Throwable t) {
            RowValidationProblem problem = new RowValidationProblem(t);
            problem.addAffectedRowNumber(curWorkProgress + 1);
            problem.setHistoryId(this.configuration.historyId);
            this.progressListener.addRowValidationProblem(problem);
        }
        this.progressListener.setWorkProgress(curWorkProgress + 1);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Thread.yield();
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : IgnoreRowException(net.geoprism.registry.io.IgnoreRowException) BusinessObject(net.geoprism.registry.model.BusinessObject) Entry(java.util.Map.Entry) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) RequiredMappingException(net.geoprism.registry.io.RequiredMappingException) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) JSONObject(org.json.JSONObject) BusinessObject(net.geoprism.registry.model.BusinessObject) VertexObject(com.runwaysdk.business.graph.VertexObject) RowValidationProblem(net.geoprism.registry.etl.RowValidationProblem) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 2 with ShapefileFunction

use of net.geoprism.data.importer.ShapefileFunction in project geoprism-registry by terraframe.

the class GeoObjectImporter method getName.

/**
 * @param feature
 * @return The entityName as defined by the 'name' attribute of the feature
 */
private LocalizedValue getName(FeatureRow row) {
    ShapefileFunction function = this.configuration.getFunction(GeoObject.DISPLAY_LABEL);
    if (function == null) {
        return null;
    }
    Object attribute = function.getValue(row);
    if (attribute != null) {
        return (LocalizedValue) attribute;
    }
    return null;
}
Also used : LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) JSONObject(org.json.JSONObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject)

Example 3 with ShapefileFunction

use of net.geoprism.data.importer.ShapefileFunction in project geoprism-registry by terraframe.

the class GeoObjectImporter method validateRow.

@Transaction
public void validateRow(FeatureRow row) throws InterruptedException {
    try {
        // Refresh the session because it might expire on long imports
        final long curWorkProgress = this.progressListener.getWorkProgress();
        if ((this.lastValidateSessionRefresh + GeoObjectImporter.refreshSessionRecordCount) < curWorkProgress) {
            SessionFacade.renewSession(Session.getCurrentSession().getOid());
            this.lastValidateSessionRefresh = curWorkProgress;
        }
        try {
            /*
         * 1. Check for location problems
         */
            if (this.configuration.isPostalCode() && PostalCodeFactory.isAvailable(this.configuration.getType())) {
            // Skip location synonym check
            } else if (this.configuration.getHierarchy() != null && this.configuration.getLocations().size() > 0) {
                this.getParent(row);
            }
            /*
         * 2. Check for serialization and term problems
         */
            String code = this.getCode(row);
            ServerGeoObjectIF entity;
            if (code == null || code.length() <= 0) {
                RequiredMappingException ex = new RequiredMappingException();
                ex.setAttributeLabel(GeoObjectTypeMetadata.getAttributeDisplayLabel(DefaultAttribute.CODE.getName()));
                throw ex;
            }
            entity = service.newInstance(this.configuration.getType());
            entity.setCode(code);
            entity.setInvalid(false);
            try {
                LocalizedValue entityName = this.getName(row);
                if (entityName != null && this.hasValue(entityName)) {
                    entity.setDisplayLabel(entityName, this.configuration.getStartDate(), this.configuration.getEndDate());
                }
                Geometry geometry = (Geometry) this.getFormatSpecificImporter().getGeometry(row);
                if (geometry != null) {
                    // geometry.getSRID().
                    if (geometry.isValid()) {
                        entity.setGeometry(geometry, this.configuration.getStartDate(), this.configuration.getEndDate());
                    } else {
                        InvalidGeometryException geomEx = new InvalidGeometryException();
                        throw geomEx;
                    }
                }
                Map<String, AttributeType> attributes = this.configuration.getType().getAttributeMap();
                Set<Entry<String, AttributeType>> entries = attributes.entrySet();
                for (Entry<String, AttributeType> entry : entries) {
                    String attributeName = entry.getKey();
                    if (!attributeName.equals(GeoObject.CODE)) {
                        ShapefileFunction function = this.configuration.getFunction(attributeName);
                        if (function != null) {
                            Object value = function.getValue(row);
                            if (value != null && !this.isEmptyString(value)) {
                                AttributeType attributeType = entry.getValue();
                                this.setValue(entity, attributeType, attributeName, value);
                            }
                        }
                    }
                }
                GeoObjectOverTime go = entity.toGeoObjectOverTime(false);
                go.toJSON().toString();
                if (this.configuration.isExternalImport()) {
                    ShapefileFunction function = this.configuration.getExternalIdFunction();
                    Object value = function.getValue(row);
                    if (value == null || !(value instanceof String || value instanceof Integer || value instanceof Long) || (value instanceof String && ((String) value).length() == 0)) {
                        throw new InvalidExternalIdException();
                    }
                }
            } finally {
                entity.unlock();
            }
        } catch (IgnoreRowException e) {
        // Do nothing
        } catch (Throwable t) {
            RowValidationProblem problem = new RowValidationProblem(t);
            problem.addAffectedRowNumber(curWorkProgress + 1);
            problem.setHistoryId(this.configuration.historyId);
            this.progressListener.addRowValidationProblem(problem);
        }
        this.progressListener.setWorkProgress(curWorkProgress + 1);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        Thread.yield();
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : InvalidExternalIdException(net.geoprism.registry.etl.InvalidExternalIdException) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) IgnoreRowException(net.geoprism.registry.io.IgnoreRowException) Geometry(com.vividsolutions.jts.geom.Geometry) Entry(java.util.Map.Entry) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) RequiredMappingException(net.geoprism.registry.io.RequiredMappingException) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) JSONObject(org.json.JSONObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject) RowValidationProblem(net.geoprism.registry.etl.RowValidationProblem) InvalidGeometryException(net.geoprism.registry.io.InvalidGeometryException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 4 with ShapefileFunction

use of net.geoprism.data.importer.ShapefileFunction in project geoprism-registry by terraframe.

the class GeoObjectImporter method getCode.

/**
 * @param feature
 *          Shapefile feature
 *
 * @return The geoId as defined by the 'oid' attribute on the feature. If the
 *         geoId is null then a blank geoId is returned.
 */
protected String getCode(FeatureRow row) {
    ShapefileFunction function = this.configuration.getFunction(GeoObject.CODE);
    if (function == null) {
        RequiredMappingException ex = new RequiredMappingException();
        ex.setAttributeLabel(this.configuration.getType().getAttribute(GeoObject.CODE).get().getLabel().getValue());
        throw ex;
    }
    Object code = function.getValue(row);
    if (code != null) {
        return code.toString();
    }
    return null;
}
Also used : RequiredMappingException(net.geoprism.registry.io.RequiredMappingException) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) JSONObject(org.json.JSONObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) VertexObject(com.runwaysdk.business.graph.VertexObject)

Example 5 with ShapefileFunction

use of net.geoprism.data.importer.ShapefileFunction in project geoprism-registry by terraframe.

the class GeoObjectImporter method parsePostalCode.

private ServerGeoObjectIF parsePostalCode(FeatureRow feature) {
    LocationBuilder builder = PostalCodeFactory.get(this.configuration.getType());
    Location location = builder.build(this.configuration.getFunction(GeoObject.CODE));
    ShapefileFunction function = location.getFunction();
    String code = (String) function.getValue(feature);
    if (code != null) {
        // Search
        ServerGeoObjectQuery query = new ServerGeoObjectService().createQuery(location.getType(), this.configuration.getStartDate());
        query.setRestriction(new ServerCodeRestriction(code));
        // Assert.assertNull(query.getSingleResult());
        ServerGeoObjectIF result = query.getSingleResult();
        if (result != null) {
            return result;
        } else {
            PostalCodeLocationException e = new PostalCodeLocationException();
            e.setCode(code);
            e.setTypeLabel(location.getType().getLabel().getValue());
            throw e;
        }
    }
    return null;
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) LocationBuilder(net.geoprism.registry.io.LocationBuilder) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) PostalCodeLocationException(net.geoprism.registry.io.PostalCodeLocationException) ShapefileFunction(net.geoprism.data.importer.ShapefileFunction) ServerGeoObjectQuery(net.geoprism.registry.query.ServerGeoObjectQuery) ServerCodeRestriction(net.geoprism.registry.query.ServerCodeRestriction) Location(net.geoprism.registry.io.Location)

Aggregations

ShapefileFunction (net.geoprism.data.importer.ShapefileFunction)14 JSONObject (org.json.JSONObject)10 VertexObject (com.runwaysdk.business.graph.VertexObject)7 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)7 RequiredMappingException (net.geoprism.registry.io.RequiredMappingException)6 Entry (java.util.Map.Entry)5 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)4 Request (com.runwaysdk.session.Request)4 IgnoreRowException (net.geoprism.registry.io.IgnoreRowException)4 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)4 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)4 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)4 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)4 Location (net.geoprism.registry.io.Location)3 BusinessObject (net.geoprism.registry.model.BusinessObject)3 ProblemException (com.runwaysdk.ProblemException)2 ProblemIF (com.runwaysdk.ProblemIF)2 Geometry (com.vividsolutions.jts.geom.Geometry)2 SimpleDateFormat (java.text.SimpleDateFormat)2 RowValidationProblem (net.geoprism.registry.etl.RowValidationProblem)2