Search in sources :

Example 81 with Transaction

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

the class ChangeRequest method execute.

@Transaction
public void execute(String maintainerNotes, String additionalNotes) {
    if (this.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
        List<AbstractAction> actions = this.getOrderedActions();
        Set<AllGovernanceStatus> statuses = new TreeSet<AllGovernanceStatus>();
        for (AbstractAction action : actions) {
            if (action instanceof UpdateAttributeAction && action.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
                throw new ActionExecuteException("Unable to execute an action with the pending status");
            } else if (action instanceof CreateGeoObjectAction && action.getApprovalStatus().contains(AllGovernanceStatus.PENDING)) {
                action.appLock();
                action.clearApprovalStatus();
                action.addApprovalStatus(AllGovernanceStatus.ACCEPTED);
                action.apply();
                action.execute();
                statuses.add(AllGovernanceStatus.ACCEPTED);
            } else if (action.getApprovalStatus().contains(AllGovernanceStatus.ACCEPTED)) {
                action.execute();
                statuses.add(AllGovernanceStatus.ACCEPTED);
            } else if (action.getApprovalStatus().contains(AllGovernanceStatus.REJECTED) || action.getApprovalStatus().contains(AllGovernanceStatus.INVALID)) {
                statuses.add(AllGovernanceStatus.REJECTED);
            }
        }
        AllGovernanceStatus status = AllGovernanceStatus.REJECTED;
        if (statuses.size() > 0) {
            status = statuses.size() == 1 ? statuses.iterator().next() : AllGovernanceStatus.PARTIAL;
        }
        this.appLock();
        this.setMaintainerNotes(maintainerNotes);
        this.setAdditionalNotes(additionalNotes);
        this.clearApprovalStatus();
        this.addApprovalStatus(status);
        this.apply();
        // Email the contributor
        try {
            SingleActor actor = this.getCreatedBy();
            if (actor instanceof GeoprismUser) {
                String email = ((GeoprismUser) actor).getEmail();
                if (email != null && email.length() > 0 && !email.contains("@noreply")) {
                    final String statusLabel = status.getDisplayLabel().toLowerCase(Session.getCurrentLocale());
                    String subject = LocalizationFacade.getFromBundles("change.request.email.implement.subject");
                    subject = subject.replaceAll("\\{status\\}", StringUtils.capitalize(statusLabel));
                    String body = LocalizationFacade.getFromBundles("change.request.email.implement.body");
                    body = body.replaceAll("\\\\n", "\n");
                    body = body.replaceAll("\\{status\\}", statusLabel);
                    body = body.replaceAll("\\{geoobject\\}", this.getGeoObject().getDisplayLabel().getValue());
                    String link = GeoregistryProperties.getRemoteServerUrl() + "cgr/manage#/registry/change-requests/" + this.getOid();
                    body = body.replaceAll("\\{link\\}", link);
                    EmailSetting.sendEmail(subject, body, new String[] { email });
                }
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
Also used : CreateGeoObjectAction(net.geoprism.registry.action.geoobject.CreateGeoObjectAction) TreeSet(java.util.TreeSet) GeoprismUser(net.geoprism.GeoprismUser) UpdateAttributeAction(net.geoprism.registry.action.geoobject.UpdateAttributeAction) SingleActor(com.runwaysdk.system.SingleActor) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 82 with Transaction

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

the class DataImportJob method startInTrans.

@Transaction
private JobHistoryRecord startInTrans(ImportConfiguration configuration) {
    configuration.enforceCreatePermissions();
    ImportHistory history = (ImportHistory) this.createNewHistory();
    configuration.setHistoryId(history.getOid());
    configuration.setJobId(this.getOid());
    history.appLock();
    history.setConfigJson(configuration.toJSON().toString());
    history.setImportFileId(configuration.getVaultFileId());
    configuration.populate(history);
    history.apply();
    JobHistoryRecord record = new JobHistoryRecord(this, history);
    record.apply();
    return record;
}
Also used : JobHistoryRecord(com.runwaysdk.system.scheduler.JobHistoryRecord) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 83 with Transaction

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

the class DataImportJob method resumeInTrans.

@Transaction
private void resumeInTrans(JobHistoryRecord jhr) {
    ImportHistory hist = (ImportHistory) jhr.getChild();
    ImportStage stage = hist.getStage().get(0);
    if (hist.getStatus().get(0).equals(AllJobStatus.RUNNING)) {
    // This code block happens when the server restarts after a job was
    // running when it died.
    // Do nothing. Allow the job to resume as normal.
    } else {
        if (stage.equals(ImportStage.VALIDATION_RESOLVE)) {
            DataImportJob.deleteValidationProblems(hist);
            hist.appLock();
            hist.clearStage();
            hist.addStage(ImportStage.VALIDATE);
            hist.setWorkProgress(0L);
            hist.setImportedRecords(0L);
            hist.apply();
        } else // else if (stage.equals(ImportStage.IMPORT_RESOLVE))
        // {
        // hist.appLock();
        // hist.clearStage();
        // hist.setWorkProgress(0);
        // hist.addStage(ImportStage.RESUME_IMPORT);
        // hist.apply();
        // }
        {
            logger.error("Resuming job with unexpected initial stage [" + stage + "].");
            hist.appLock();
            hist.clearStage();
            hist.addStage(ImportStage.VALIDATE);
            hist.apply();
        }
    }
    NotificationFacade.queue(new GlobalNotificationMessage(MessageType.IMPORT_JOB_CHANGE, null));
}
Also used : GlobalNotificationMessage(net.geoprism.registry.ws.GlobalNotificationMessage) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 84 with Transaction

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

the class ETLService method cancelImportInTrans.

@Transaction
private void cancelImportInTrans(String sessionId, String json) {
    ImportConfiguration config = ImportConfiguration.build(json);
    String id = config.getVaultFileId();
    VaultFile.get(id).delete();
    if (config.getHistoryId() != null && config.getHistoryId().length() > 0) {
        String historyId = config.getHistoryId();
        ImportHistory hist = ImportHistory.get(historyId);
        hist.getConfig().enforceExecutePermissions();
        if (!hist.getStage().get(0).equals(ImportStage.VALIDATION_RESOLVE)) {
            throw new ProgrammingErrorException("Import jobs can only be canceled if they are in " + ImportStage.VALIDATION_RESOLVE.name() + " stage.");
        }
        ValidationProblemQuery vpq = new ValidationProblemQuery(new QueryFactory());
        vpq.WHERE(vpq.getHistory().EQ(historyId));
        OIterator<? extends ValidationProblem> it = vpq.getIterator();
        try {
            while (it.hasNext()) {
                it.next().delete();
            }
        } finally {
            it.close();
        }
        hist = ImportHistory.lock(historyId);
        hist.clearStage();
        hist.addStage(ImportStage.COMPLETE);
        hist.clearStatus();
        hist.addStatus(AllJobStatus.CANCELED);
        hist.setImportedRecords(0L);
        hist.apply();
    }
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) GeoObjectImportConfiguration(net.geoprism.registry.io.GeoObjectImportConfiguration) ImportConfiguration(net.geoprism.registry.etl.upload.ImportConfiguration) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 85 with Transaction

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

the class ETLService method resolveImportInTrans.

@Transaction
private void resolveImportInTrans(String historyId, ImportHistory hist) {
    hist.appLock();
    ImportErrorQuery ieq = new ImportErrorQuery(new QueryFactory());
    ieq.WHERE(ieq.getHistory().EQ(historyId));
    OIterator<? extends ImportError> it = ieq.getIterator();
    try {
        ImportError err = it.next();
        err.delete();
    } finally {
        it.close();
    }
    hist.clearStatus();
    hist.addStatus(AllJobStatus.SUCCESS);
    hist.clearStage();
    hist.addStage(ImportStage.COMPLETE);
    hist.apply();
    VaultFile file = hist.getImportFile();
    file.delete();
}
Also used : QueryFactory(com.runwaysdk.query.QueryFactory) VaultFile(com.runwaysdk.system.VaultFile) 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