Search in sources :

Example 96 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DefaultJobManager method scheduleTimerJob.

@Override
public void scheduleTimerJob(TimerJobEntity timerJob) {
    if (timerJob == null) {
        throw new ActivitiException("Empty timer job can not be scheduled");
    }
    processEngineConfiguration.getTimerJobEntityManager().insert(timerJob);
    CommandContext commandContext = Context.getCommandContext();
    ActivitiEventDispatcher eventDispatcher = commandContext.getEventDispatcher();
    if (eventDispatcher.isEnabled()) {
        eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TIMER_SCHEDULED, timerJob));
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ActivitiEventDispatcher(org.activiti.engine.delegate.event.ActivitiEventDispatcher)

Example 97 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DefaultJobManager method restoreExtraData.

protected void restoreExtraData(JobEntity timerEntity, VariableScope variableScope) {
    String activityId = timerEntity.getJobHandlerConfiguration();
    if (timerEntity.getJobHandlerType().equalsIgnoreCase(TimerStartEventJobHandler.TYPE) || timerEntity.getJobHandlerType().equalsIgnoreCase(TriggerTimerEventJobHandler.TYPE)) {
        activityId = TimerEventHandler.getActivityIdFromConfiguration(timerEntity.getJobHandlerConfiguration());
        String endDateExpressionString = TimerEventHandler.getEndDateFromConfiguration(timerEntity.getJobHandlerConfiguration());
        if (endDateExpressionString != null) {
            Expression endDateExpression = processEngineConfiguration.getExpressionManager().createExpression(endDateExpressionString);
            String endDateString = null;
            BusinessCalendar businessCalendar = processEngineConfiguration.getBusinessCalendarManager().getBusinessCalendar(getBusinessCalendarName(TimerEventHandler.geCalendarNameFromConfiguration(timerEntity.getJobHandlerConfiguration()), variableScope));
            if (endDateExpression != null) {
                Object endDateValue = endDateExpression.getValue(variableScope);
                if (endDateValue instanceof String) {
                    endDateString = (String) endDateValue;
                } else if (endDateValue instanceof Date) {
                    timerEntity.setEndDate((Date) endDateValue);
                } else {
                    throw new ActivitiException("Timer '" + ((ExecutionEntity) variableScope).getActivityId() + "' was not configured with a valid duration/time, either hand in a java.util.Date or a String in format 'yyyy-MM-dd'T'hh:mm:ss'");
                }
                if (timerEntity.getEndDate() == null) {
                    timerEntity.setEndDate(businessCalendar.resolveEndDate(endDateString));
                }
            }
        }
    }
    int maxIterations = 1;
    if (timerEntity.getProcessDefinitionId() != null) {
        org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(timerEntity.getProcessDefinitionId());
        maxIterations = getMaxIterations(process, activityId);
        if (maxIterations <= 1) {
            maxIterations = getMaxIterations(process, activityId);
        }
    }
    timerEntity.setMaxIterations(maxIterations);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Expression(org.activiti.engine.delegate.Expression) CycleBusinessCalendar(org.activiti.engine.impl.calendar.CycleBusinessCalendar) BusinessCalendar(org.activiti.engine.impl.calendar.BusinessCalendar) Date(java.util.Date)

Example 98 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DestroyScopeOperation method run.

@Override
public void run() {
    // Find the actual scope that needs to be destroyed.
    // This could be the incoming execution, or the first parent execution where isScope = true
    // Find parent scope execution
    ExecutionEntity scopeExecution = execution.isScope() ? execution : findFirstParentScopeExecution(execution);
    if (scopeExecution == null) {
        throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
    }
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    deleteAllChildExecutions(executionEntityManager, scopeExecution);
    // Delete all scope tasks
    TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
    deleteAllScopeTasks(scopeExecution, taskEntityManager);
    // Delete all scope jobs
    TimerJobEntityManager timerJobEntityManager = commandContext.getTimerJobEntityManager();
    deleteAllScopeJobs(scopeExecution, timerJobEntityManager);
    // Remove variables associated with this scope
    VariableInstanceEntityManager variableInstanceEntityManager = commandContext.getVariableInstanceEntityManager();
    removeAllVariablesFromScope(scopeExecution, variableInstanceEntityManager);
    commandContext.getHistoryManager().recordActivityEnd(scopeExecution, scopeExecution.getDeleteReason());
    executionEntityManager.delete(scopeExecution);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) TaskEntityManager(org.activiti.engine.impl.persistence.entity.TaskEntityManager) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager) TimerJobEntityManager(org.activiti.engine.impl.persistence.entity.TimerJobEntityManager) VariableInstanceEntityManager(org.activiti.engine.impl.persistence.entity.VariableInstanceEntityManager)

Example 99 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class BoundaryEventActivityBehavior method executeInterruptingBehavior.

protected void executeInterruptingBehavior(ExecutionEntity executionEntity, CommandContext commandContext) {
    // The destroy scope operation will look for the parent execution and
    // destroy the whole scope, and leave the boundary event using this parent execution.
    // 
    // The take outgoing seq flows operation below (the non-interrupting else clause) on the other hand uses the
    // child execution to leave, which keeps the scope alive.
    // Which is what we need here.
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    ExecutionEntity attachedRefScopeExecution = executionEntityManager.findById(executionEntity.getParentId());
    ExecutionEntity parentScopeExecution = null;
    ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(attachedRefScopeExecution.getParentId());
    while (currentlyExaminedExecution != null && parentScopeExecution == null) {
        if (currentlyExaminedExecution.isScope()) {
            parentScopeExecution = currentlyExaminedExecution;
        } else {
            currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
        }
    }
    if (parentScopeExecution == null) {
        throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
    }
    deleteChildExecutions(attachedRefScopeExecution, executionEntity, commandContext);
    // set new parent for boundary event execution
    executionEntity.setParent(parentScopeExecution);
    Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionEntity, true);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)

Example 100 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DbSqlSession method flushUpdates.

protected void flushUpdates() {
    for (Entity updatedObject : updatedObjects) {
        String updateStatement = dbSqlSessionFactory.getUpdateStatement(updatedObject);
        updateStatement = dbSqlSessionFactory.mapStatement(updateStatement);
        if (updateStatement == null) {
            throw new ActivitiException("no update statement for " + updatedObject.getClass() + " in the ibatis mapping files");
        }
        log.debug("updating: {}", updatedObject);
        int updatedRecords = sqlSession.update(updateStatement, updatedObject);
        if (updatedRecords == 0) {
            throw new ActivitiOptimisticLockingException(updatedObject + " was updated by another transaction concurrently");
        }
        // See https://activiti.atlassian.net/browse/ACT-1290
        if (updatedObject instanceof HasRevision) {
            ((HasRevision) updatedObject).setRevision(((HasRevision) updatedObject).getRevisionNext());
        }
    }
    updatedObjects.clear();
}
Also used : CachedEntity(org.activiti.engine.impl.persistence.cache.CachedEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Entity(org.activiti.engine.impl.persistence.entity.Entity) PropertyEntity(org.activiti.engine.impl.persistence.entity.PropertyEntity) ActivitiException(org.activiti.engine.ActivitiException) ActivitiOptimisticLockingException(org.activiti.engine.ActivitiOptimisticLockingException)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)289 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)45 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)44 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)38 IOException (java.io.IOException)35 ArrayList (java.util.ArrayList)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 FlowElement (org.activiti.bpmn.model.FlowElement)19 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Expression (org.activiti.engine.delegate.Expression)17 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)17 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 ObjectOutputStream (java.io.ObjectOutputStream)15 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)15 HashMap (java.util.HashMap)12 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)11 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)11 InputStream (java.io.InputStream)10