Search in sources :

Example 1 with RemoveLockCommand

use of edu.harvard.iq.dataverse.engine.command.impl.RemoveLockCommand in project dataverse by IQSS.

the class WorkflowServiceBean method rollback.

@Asynchronous
private void rollback(Workflow wf, WorkflowContext ctxt, Failure failure, int lastCompletedStepIdx) {
    ctxt = refresh(ctxt);
    final List<WorkflowStepData> steps = wf.getSteps();
    for (int stepIdx = lastCompletedStepIdx; stepIdx >= 0; --stepIdx) {
        WorkflowStepData wsd = steps.get(stepIdx);
        WorkflowStep step = createStep(wsd);
        try {
            logger.log(Level.INFO, "Workflow {0} step {1}: Rollback", new Object[] { ctxt.getInvocationId(), stepIdx });
            rollbackStep(step, ctxt, failure);
        } catch (Exception e) {
            logger.log(Level.WARNING, "Workflow " + ctxt.getInvocationId() + " step " + stepIdx + ": Rollback error: " + e.getMessage(), e);
        }
    }
    logger.log(Level.INFO, "Removing workflow lock");
    try {
        engine.submit(new RemoveLockCommand(ctxt.getRequest(), ctxt.getDataset(), DatasetLock.Reason.Workflow));
        // Corner case - delete locks generated within this same transaction.
        Query deleteQuery = em.createQuery("DELETE from DatasetLock l WHERE l.dataset.id=:id AND l.reason=:reason");
        deleteQuery.setParameter("id", ctxt.getDataset().getId());
        deleteQuery.setParameter("reason", DatasetLock.Reason.Workflow);
        deleteQuery.executeUpdate();
    } catch (CommandException ex) {
        logger.log(Level.SEVERE, "Error restoring dataset locks state after rollback: " + ex.getMessage(), ex);
    }
}
Also used : Query(javax.persistence.Query) WorkflowStepData(edu.harvard.iq.dataverse.workflow.step.WorkflowStepData) WorkflowStep(edu.harvard.iq.dataverse.workflow.step.WorkflowStep) RemoveLockCommand(edu.harvard.iq.dataverse.engine.command.impl.RemoveLockCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Asynchronous(javax.ejb.Asynchronous)

Aggregations

CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)1 RemoveLockCommand (edu.harvard.iq.dataverse.engine.command.impl.RemoveLockCommand)1 WorkflowStep (edu.harvard.iq.dataverse.workflow.step.WorkflowStep)1 WorkflowStepData (edu.harvard.iq.dataverse.workflow.step.WorkflowStepData)1 Asynchronous (javax.ejb.Asynchronous)1 Query (javax.persistence.Query)1