Search in sources :

Example 26 with Transaction

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

the class ETLService method submitImportErrorResolutionInTrans.

@Transaction
private void submitImportErrorResolutionInTrans(String sessionId, String json) {
    JsonObject config = JsonParser.parseString(json).getAsJsonObject();
    ImportHistory hist = ImportHistory.get(config.get("historyId").getAsString());
    hist.getConfig().enforceExecutePermissions();
    ImportError err = ImportError.get(config.get("importErrorId").getAsString());
    String resolution = config.get("resolution").getAsString();
    if (resolution.equals(ErrorResolution.APPLY_GEO_OBJECT.name())) {
        String parentTreeNode = config.get("parentTreeNode").toString();
        String geoObject = config.get("geoObject").toString();
        Boolean isNew = config.get("isNew").getAsBoolean();
        GeoObjectOverTime go = GeoObjectOverTime.fromJSON(ServiceFactory.getAdapter(), geoObject);
        if (isNew) {
            go.setUid(RegistryIdService.getInstance().next());
            geoObject = go.toJSON().toString();
            new ServerGeoObjectService().createGeoObject(sessionId, parentTreeNode, geoObject, null, null);
        } else {
            ServerGeoObjectService service = new ServerGeoObjectService();
            ServerGeoObjectIF serverGO = service.apply(go, isNew, false);
            final ServerGeoObjectType type = serverGO.getType();
            ServerParentTreeNodeOverTime ptnOt = ServerParentTreeNodeOverTime.fromJSON(type, parentTreeNode);
            serverGO.setParents(ptnOt);
        }
        err.appLock();
        err.setResolution(resolution);
        err.apply();
        hist.appLock();
        hist.setErrorResolvedCount(hist.getErrorResolvedCount() + 1);
        hist.setImportedRecords(hist.getImportedRecords() + 1);
        hist.apply();
    } else if (resolution.equals(ErrorResolution.IGNORE.name())) {
        err.appLock();
        err.setResolution(resolution);
        err.apply();
    } else {
        throw new UnsupportedOperationException("Invalid import resolution [" + resolution + "].");
    }
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) JsonObject(com.google.gson.JsonObject) GeoObjectOverTime(org.commongeoregistry.adapter.dataaccess.GeoObjectOverTime) ServerParentTreeNodeOverTime(net.geoprism.registry.view.ServerParentTreeNodeOverTime) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 27 with Transaction

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

the class ETLService method reImportInTrans.

@Transaction
public void reImportInTrans(MultipartFileParameter file, String json) {
    ImportConfiguration config = ImportConfiguration.build(json);
    ImportHistory hist = ImportHistory.get(config.getHistoryId());
    hist.getConfig().enforceExecutePermissions();
    VaultFile vf = VaultFile.get(config.getVaultFileId());
    vf.delete();
    VaultFile vf2 = null;
    try (InputStream is = file.getInputStream()) {
        vf2 = VaultFile.createAndApply(file.getFilename(), is);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    config.setVaultFileId(vf2.getOid());
    config.setFileName(file.getFilename());
    hist = ImportHistory.lock(config.getHistoryId());
    hist.setImportFile(vf2);
    hist.setConfigJson(config.toJSON().toString());
    hist.apply();
}
Also used : InputStream(java.io.InputStream) VaultFile(com.runwaysdk.system.VaultFile) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ImportConfiguration(net.geoprism.registry.etl.upload.ImportConfiguration) IOException(java.io.IOException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 28 with Transaction

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

the class ETLService method submitValidationProblemResolutionInTrans.

@Transaction
private JsonObject submitValidationProblemResolutionInTrans(String sessionId, String json) {
    JsonObject response = new JsonObject();
    JsonObject config = JsonParser.parseString(json).getAsJsonObject();
    ValidationProblem problem = ValidationProblem.get(config.get("validationProblemId").getAsString());
    ImportHistory hist = problem.getHistory();
    hist.getConfig().enforceExecutePermissions();
    String resolution = config.get("resolution").getAsString();
    if (resolution.equals(ValidationResolution.SYNONYM.name())) {
        if (problem instanceof TermReferenceProblem) {
            String classifierId = config.get("classifierId").getAsString();
            String label = config.get("label").getAsString();
            response = JsonParser.parseString(DataUploader.createClassifierSynonym(classifierId, label)).getAsJsonObject();
        } else if (problem instanceof ParentReferenceProblem) {
            String code = config.get("code").getAsString();
            String typeCode = config.get("typeCode").getAsString();
            String label = config.get("label").getAsString();
            ServerGeoObjectIF go = new ServerGeoObjectService().getGeoObjectByCode(code, typeCode);
            response = JsonParser.parseString(new GeoSynonymService().createGeoEntitySynonym(sessionId, typeCode, go.getCode(), label).toString()).getAsJsonObject();
        }
        problem.appLock();
        problem.setResolution(resolution);
        problem.apply();
    // hist.appLock();
    // hist.setErrorResolvedCount(hist.getErrorResolvedCount() + 1);
    // hist.apply();
    } else if (resolution.equals(ValidationResolution.IGNORE.name())) {
        problem.appLock();
        problem.setResolution(resolution);
        problem.apply();
    } else if (resolution.equals(ValidationResolution.CREATE.name())) {
        if (problem instanceof TermReferenceProblem) {
            String parentTermCode = config.get("parentTermCode").getAsString();
            String termJSON = config.get("termJSON").toString();
            response = RegistryService.getInstance().createTerm(sessionId, parentTermCode, termJSON).toJSON();
        } else if (problem instanceof ParentReferenceProblem) {
        // TODO
        }
        problem.appLock();
        problem.setResolution(resolution);
        problem.apply();
    } else {
        throw new UnsupportedOperationException("Invalid import resolution [" + resolution + "].");
    }
    return response;
}
Also used : ServerGeoObjectService(net.geoprism.registry.geoobject.ServerGeoObjectService) ServerGeoObjectIF(net.geoprism.registry.model.ServerGeoObjectIF) JsonObject(com.google.gson.JsonObject) GeoSynonymService(net.geoprism.registry.service.GeoSynonymService) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 29 with Transaction

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

the class GeoVertexSynonym method createSynonym.

@Transaction
public static JSONObject createSynonym(String typeCode, String code, String label) {
    ServerGeoObjectType type = ServerGeoObjectType.get(typeCode);
    VertexGeoObjectStrategy strategy = new VertexGeoObjectStrategy(type);
    VertexServerGeoObject object = strategy.getGeoObjectByCode(code);
    final String oid = object.addSynonym(label);
    JSONObject jObject = new JSONObject();
    jObject.put("synonymId", oid);
    jObject.put("label", object.getDisplayLabel().getValue());
    // jObject.put("ancestors", object.getA new
    // JSONArray(GeoEntityUtil.getAncestorsAsJSON(code)));
    JSONObject response = new JSONObject(jObject);
    response.put("vOid", oid);
    return response;
}
Also used : VertexGeoObjectStrategy(net.geoprism.registry.conversion.VertexGeoObjectStrategy) JSONObject(org.json.JSONObject) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 30 with Transaction

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

the class TransitionEvent method removeAll.

@Transaction
public static void removeAll(ServerGeoObjectType type) {
    MdVertexDAOIF mdVertex = MdVertexDAO.getMdVertexDAO(TransitionEvent.CLASS);
    MdAttributeDAOIF beforeTypeCode = mdVertex.definesAttribute(TransitionEvent.BEFORETYPECODE);
    MdAttributeDAOIF afterTypeCode = mdVertex.definesAttribute(TransitionEvent.AFTERTYPECODE);
    StringBuilder statement = new StringBuilder();
    statement.append("SELECT FROM " + mdVertex.getDBClassName());
    statement.append(" WHERE " + beforeTypeCode.getColumnName() + " = :typeCode OR " + afterTypeCode.getColumnName() + " = :typeCode");
    GraphQuery<TransitionEvent> query = new GraphQuery<TransitionEvent>(statement.toString());
    query.setParameter("typeCode", type.getCode());
    List<TransitionEvent> results = query.getResults();
    results.forEach(event -> event.delete());
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) MdAttributeDAOIF(com.runwaysdk.dataaccess.MdAttributeDAOIF) GraphQuery(com.runwaysdk.business.graph.GraphQuery) 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