Search in sources :

Example 46 with Transaction

use of com.runwaysdk.dataaccess.transaction.Transaction 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 47 with Transaction

use of com.runwaysdk.dataaccess.transaction.Transaction 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 48 with Transaction

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

the class ServerGeoObjectService method updateChangeRequest.

@Transaction
public ChangeRequest updateChangeRequest(ChangeRequest request, String notes, final JsonArray jaActions) {
    Instant base = Instant.now();
    int sequence = 0;
    // Delete all existing actions
    try (OIterator<? extends AbstractAction> actions = request.getAllAction()) {
        while (actions.hasNext()) {
            AbstractAction action = actions.next();
            action.delete();
        }
    }
    // Create the new actions
    for (int i = 0; i < jaActions.size(); ++i) {
        JsonObject joAction = jaActions.get(i).getAsJsonObject();
        String actionType = joAction.get("actionType").getAsString();
        if (actionType.equals(CreateGeoObjectAction.class.getSimpleName())) {
            CreateGeoObjectAction action = new CreateGeoObjectAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.setContributorNotes(notes);
            if (joAction.has(CreateGeoObjectAction.GEOOBJECTJSON) && !joAction.get(CreateGeoObjectAction.GEOOBJECTJSON).isJsonNull()) {
                action.setGeoObjectJson(joAction.get(CreateGeoObjectAction.GEOOBJECTJSON).getAsJsonObject().toString());
            }
            if (joAction.has(CreateGeoObjectAction.PARENTJSON) && !joAction.get(CreateGeoObjectAction.PARENTJSON).isJsonNull()) {
                action.setParentJson(joAction.get(CreateGeoObjectAction.PARENTJSON).getAsJsonArray().toString());
            }
            action.apply();
            request.addAction(action).apply();
        } else {
            String attributeName = joAction.get("attributeName").getAsString();
            JsonObject attributeDiff = joAction.get("attributeDiff").getAsJsonObject();
            UpdateAttributeAction action = new UpdateAttributeAction();
            action.addApprovalStatus(AllGovernanceStatus.PENDING);
            action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
            action.setAttributeName(attributeName);
            action.setJson(attributeDiff.toString());
            action.setApiVersion(CGRAdapterProperties.getApiVersion());
            action.setContributorNotes(notes);
            action.apply();
            request.addAction(action).apply();
        }
    }
    request.appLock();
    request.setContributorNotes(notes);
    request.apply();
    return request;
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) Instant(java.time.Instant) JsonObject(com.google.gson.JsonObject) AbstractAction(net.geoprism.registry.action.AbstractAction) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 49 with Transaction

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

the class ServerGeoObjectService method createGeoObjectInTrans.

@Transaction
public JsonObject createGeoObjectInTrans(String sPtn, String sTimeGo, String masterListId, String notes) {
    GeoObjectOverTime timeGO = GeoObjectOverTime.fromJSON(ServiceFactory.getAdapter(), sTimeGo);
    ServerGeoObjectType serverGOT = ServerGeoObjectType.get(timeGO.getType());
    RolePermissionService perms = ServiceFactory.getRolePermissionService();
    final String orgCode = serverGOT.getOrganization().getCode();
    if (perms.isSRA() || perms.isRA(orgCode) || perms.isRM(orgCode, serverGOT)) {
        ServerGeoObjectService service = new ServerGeoObjectService();
        ServerGeoObjectIF serverGO = service.apply(timeGO, true, false);
        final ServerGeoObjectType type = serverGO.getType();
        if (sPtn != null) {
            ServerParentTreeNodeOverTime ptnOt = ServerParentTreeNodeOverTime.fromJSON(type, sPtn);
            serverGO.setParents(ptnOt);
        }
        // Update the master list record
        if (masterListId != null) {
            ListTypeVersion.get(masterListId).publishRecord(serverGO);
        }
        JsonObject resp = new JsonObject();
        resp.addProperty("isChangeRequest", false);
        resp.add("geoObject", serverGO.toGeoObjectOverTime().toJSON(ServiceFactory.getRegistryService().serializer(Session.getCurrentSession().getOid())));
        return resp;
    } else if (ServiceFactory.getRolePermissionService().isRC(orgCode, serverGOT)) {
        Instant base = Instant.now();
        int sequence = 0;
        ChangeRequest request = new ChangeRequest();
        request.addApprovalStatus(AllGovernanceStatus.PENDING);
        request.setContributorNotes(notes);
        request.setGeoObjectCode(timeGO.getCode());
        request.setGeoObjectTypeCode(timeGO.getType().getCode());
        request.setOrganizationCode(orgCode);
        request.apply();
        CreateGeoObjectAction action = new CreateGeoObjectAction();
        action.addApprovalStatus(AllGovernanceStatus.PENDING);
        action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
        action.setGeoObjectJson(sTimeGo);
        action.setParentJson(sPtn);
        action.setApiVersion(CGRAdapterProperties.getApiVersion());
        action.setContributorNotes(notes);
        action.apply();
        request.addAction(action).apply();
        JsonObject resp = new JsonObject();
        resp.addProperty("isChangeRequest", true);
        resp.addProperty("changeRequestId", request.getOid());
        return resp;
    } else {
        throw new CGRPermissionException();
    }
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) CGRPermissionException(net.geoprism.registry.CGRPermissionException) CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) Instant(java.time.Instant) JsonObject(com.google.gson.JsonObject) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) ChangeRequest(net.geoprism.registry.action.ChangeRequest) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 50 with Transaction

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

the class ServerGeoObjectService method apply.

@Transaction
public ServerGeoObjectIF apply(GeoObject object, Date startDate, Date endDate, boolean isNew, boolean isImport) {
    ServerGeoObjectType type = ServerGeoObjectType.get(object.getType());
    ServerGeoObjectStrategyIF strategy = this.getStrategy(type);
    if (isNew) {
        permissionService.enforceCanCreate(type.getOrganization().getCode(), type);
    } else {
        permissionService.enforceCanWrite(type.getOrganization().getCode(), type);
    }
    ServerGeoObjectIF geoObject = strategy.constructFromGeoObject(object, isNew);
    geoObject.setDate(startDate);
    if (!isNew) {
        geoObject.lock();
    }
    geoObject.populate(object, startDate, endDate);
    try {
        geoObject.apply(isImport);
        // Return the refreshed copy of the geoObject
        return this.build(type, geoObject.getRunwayId());
    } catch (DuplicateDataException e) {
        VertexServerGeoObject.handleDuplicateDataException(type, e);
        throw e;
    }
}
Also used : DuplicateDataException(com.runwaysdk.dataaccess.DuplicateDataException) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) ServerGeoObjectStrategyIF(net.geoprism.registry.conversion.ServerGeoObjectStrategyIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

Transaction (com.runwaysdk.dataaccess.transaction.Transaction)131 QueryFactory (com.runwaysdk.query.QueryFactory)29 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)27 JsonObject (com.google.gson.JsonObject)17 Date (java.util.Date)15 ServerHierarchyType (net.geoprism.registry.model.ServerHierarchyType)15 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)14 ServerGeoObjectIF (net.geoprism.registry.model.ServerGeoObjectIF)13 LinkedList (java.util.LinkedList)11 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)11 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)10 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)10 MdBusiness (com.runwaysdk.system.metadata.MdBusiness)10 List (java.util.List)10 ChangeRequest (net.geoprism.registry.action.ChangeRequest)10 VertexObject (com.runwaysdk.business.graph.VertexObject)8 IOException (java.io.IOException)8 GeoObjectImportConfiguration (net.geoprism.registry.io.GeoObjectImportConfiguration)8 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)8 JSONObject (org.json.JSONObject)8