Search in sources :

Example 61 with ActivityImpl

use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.

the class TimerExecuteNestedActivityJobHandler method dispatchActivityTimeoutIfNeeded.

protected void dispatchActivityTimeoutIfNeeded(JobEntity timerEntity, ExecutionEntity execution, CommandContext commandContext) {
    String nestedActivityId = TimerEventHandler.getActivityIdFromConfiguration(timerEntity.getJobHandlerConfiguration());
    ActivityImpl boundaryEventActivity = execution.getProcessDefinition().findActivity(nestedActivityId);
    ActivityBehavior boundaryActivityBehavior = boundaryEventActivity.getActivityBehavior();
    if (boundaryActivityBehavior instanceof BoundaryEventActivityBehavior) {
        BoundaryEventActivityBehavior boundaryEventActivityBehavior = (BoundaryEventActivityBehavior) boundaryActivityBehavior;
        if (boundaryEventActivityBehavior.isInterrupting()) {
            dispatchExecutionTimeOut(timerEntity, execution, commandContext);
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) ActivityBehavior(org.activiti.engine.impl.pvm.delegate.ActivityBehavior)

Example 62 with ActivityImpl

use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.

the class TimerCatchIntermediateEventJobHandler method execute.

public void execute(JobEntity job, String configuration, ExecutionEntity execution, CommandContext commandContext) {
    String nestedActivityId = TimerEventHandler.getActivityIdFromConfiguration(configuration);
    ActivityImpl intermediateEventActivity = execution.getProcessDefinition().findActivity(nestedActivityId);
    if (intermediateEventActivity == null) {
        throw new ActivitiException("Error while firing timer: intermediate event activity " + nestedActivityId + " not found");
    }
    try {
        if (commandContext.getEventDispatcher().isEnabled()) {
            commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TIMER_FIRED, job));
        }
        if (!execution.getActivity().getId().equals(intermediateEventActivity.getId())) {
            execution.setActivity(intermediateEventActivity);
        }
        execution.signal(null, null);
    } catch (RuntimeException e) {
        LogMDC.putMDCExecution(execution);
        log.error("exception during timer execution", e);
        LogMDC.clear();
        throw e;
    } catch (Exception e) {
        LogMDC.putMDCExecution(execution);
        log.error("exception during timer execution", e);
        LogMDC.clear();
        throw new ActivitiException("exception during timer execution: " + e.getMessage(), e);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ActivitiException(org.activiti.engine.ActivitiException)

Example 63 with ActivityImpl

use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.

the class DefaultHistoryManager method recordSubProcessInstanceStart.

/* (non-Javadoc)
   * @see org.activiti.engine.impl.history.HistoryManagerInterface#recordSubProcessInstanceStart(org.activiti.engine.impl.persistence.entity.ExecutionEntity, org.activiti.engine.impl.persistence.entity.ExecutionEntity)
   */
@Override
public void recordSubProcessInstanceStart(ExecutionEntity parentExecution, ExecutionEntity subProcessInstance) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity((ExecutionEntity) subProcessInstance);
        ActivityImpl initialActivity = subProcessInstance.getActivity();
        // Fix for ACT-1728: startActivityId not initialized with subprocess-instance
        if (historicProcessInstance.getStartActivityId() == null) {
            historicProcessInstance.setStartActivityId(subProcessInstance.getProcessDefinition().getInitial().getId());
            initialActivity = subProcessInstance.getProcessDefinition().getInitial();
        }
        getDbSqlSession().insert(historicProcessInstance);
        // Fire event
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
        }
        HistoricActivityInstanceEntity activitiyInstance = findActivityInstance(parentExecution);
        if (activitiyInstance != null) {
            activitiyInstance.setCalledProcessInstanceId(subProcessInstance.getProcessInstanceId());
        }
        // Fix for ACT-1728: start-event not recorded for subprocesses
        IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();
        // Also record the start-event manually, as there is no "start" activity history listener for this
        HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
        historicActivityInstance.setId(idGenerator.getNextId());
        historicActivityInstance.setProcessDefinitionId(subProcessInstance.getProcessDefinitionId());
        historicActivityInstance.setProcessInstanceId(subProcessInstance.getProcessInstanceId());
        historicActivityInstance.setExecutionId(subProcessInstance.getId());
        historicActivityInstance.setActivityId(initialActivity.getId());
        historicActivityInstance.setActivityName((String) initialActivity.getProperty("name"));
        historicActivityInstance.setActivityType((String) initialActivity.getProperty("type"));
        Date now = Context.getProcessEngineConfiguration().getClock().getCurrentTime();
        historicActivityInstance.setStartTime(now);
        getDbSqlSession().insert(historicActivityInstance);
        // Fire event
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance));
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) IdGenerator(org.activiti.engine.impl.cfg.IdGenerator) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) Date(java.util.Date)

Example 64 with ActivityImpl

use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.

the class JobRetryCmd method getCurrentActivity.

private ActivityImpl getCurrentActivity(CommandContext commandContext, JobEntity job) {
    String type = job.getJobHandlerType();
    ActivityImpl activity = null;
    if (TimerExecuteNestedActivityJobHandler.TYPE.equals(type) || TimerCatchIntermediateEventJobHandler.TYPE.equals(type)) {
        ExecutionEntity execution = fetchExecutionEntity(commandContext, job.getExecutionId());
        if (execution != null) {
            activity = execution.getProcessDefinition().findActivity(job.getJobHandlerConfiguration());
        }
    } else if (TimerStartEventJobHandler.TYPE.equals(type)) {
        DeploymentManager deploymentManager = commandContext.getProcessEngineConfiguration().getDeploymentManager();
        if (TimerEventHandler.hasRealActivityId(job.getJobHandlerConfiguration())) {
            ProcessDefinitionEntity processDefinition = deploymentManager.findDeployedProcessDefinitionById(job.getProcessDefinitionId());
            String activityId = TimerEventHandler.getActivityIdFromConfiguration(job.getJobHandlerConfiguration());
            activity = processDefinition.findActivity(activityId);
        } else {
            String processId = job.getJobHandlerConfiguration();
            if (job instanceof TimerEntity) {
                processId = TimerEventHandler.getActivityIdFromConfiguration(job.getJobHandlerConfiguration());
            }
            ProcessDefinitionEntity processDefinition = null;
            if (job.getTenantId() != null && job.getTenantId().length() > 0) {
                processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKeyAndTenantId(processId, job.getTenantId());
            } else {
                processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKey(processId);
            }
            if (processDefinition != null) {
                activity = processDefinition.getInitial();
            }
        }
    } else if (AsyncContinuationJobHandler.TYPE.equals(type)) {
        ExecutionEntity execution = fetchExecutionEntity(commandContext, job.getExecutionId());
        if (execution != null) {
            activity = execution.getActivity();
        }
    } else {
    // nop, because activity type is not supported
    }
    return activity;
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) DeploymentManager(org.activiti.engine.impl.persistence.deploy.DeploymentManager) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 65 with ActivityImpl

use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.

the class AbstractEventHandler method dispatchExecutionCancelled.

protected void dispatchExecutionCancelled(EventSubscriptionEntity eventSubscription, ExecutionEntity execution, CommandContext commandContext) {
    // subprocesses
    for (ExecutionEntity subExecution : execution.getExecutions()) {
        dispatchExecutionCancelled(eventSubscription, subExecution, commandContext);
    }
    // call activities
    ExecutionEntity subProcessInstance = commandContext.getExecutionEntityManager().findSubProcessInstanceBySuperExecutionId(execution.getId());
    if (subProcessInstance != null) {
        dispatchExecutionCancelled(eventSubscription, subProcessInstance, commandContext);
    }
    // activity with message/signal boundary events
    ActivityImpl activity = execution.getActivity();
    if (activity != null && activity.getActivityBehavior() != null) {
        dispatchActivityCancelled(eventSubscription, execution, activity, commandContext);
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl)

Aggregations

ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)70 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)12 ActivitiException (org.activiti.engine.ActivitiException)9 TransitionImpl (org.activiti.engine.impl.pvm.process.TransitionImpl)9 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)8 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)7 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)6 ProcessDefinitionImpl (org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl)6 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)6 ArrayList (java.util.ArrayList)5 IOSpecification (org.activiti.engine.impl.bpmn.data.IOSpecification)4 ActivityBehavior (org.activiti.engine.impl.pvm.delegate.ActivityBehavior)4 HashMap (java.util.HashMap)3 PvmProcessDefinition (org.activiti.engine.impl.pvm.PvmProcessDefinition)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 List (java.util.List)2 DataAssociation (org.activiti.bpmn.model.DataAssociation)2 EventDefinition (org.activiti.bpmn.model.EventDefinition)2