Search in sources :

Example 1 with TaskEntityManager

use of org.activiti.engine.impl.persistence.entity.TaskEntityManager 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 2 with TaskEntityManager

use of org.activiti.engine.impl.persistence.entity.TaskEntityManager in project Activiti by Activiti.

the class UserTaskActivityBehavior method trigger.

public void trigger(DelegateExecution execution, String signalName, Object signalData) {
    CommandContext commandContext = Context.getCommandContext();
    TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
    // Should be only one
    List<TaskEntity> taskEntities = taskEntityManager.findTasksByExecutionId(execution.getId());
    for (TaskEntity taskEntity : taskEntities) {
        if (!taskEntity.isDeleted()) {
            throw new ActivitiException("UserTask should not be signalled before complete");
        }
    }
    propagateVariablesToProcess(execution, commandContext);
    leave(execution);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) TaskEntityManager(org.activiti.engine.impl.persistence.entity.TaskEntityManager)

Example 3 with TaskEntityManager

use of org.activiti.engine.impl.persistence.entity.TaskEntityManager in project Activiti by Activiti.

the class UserTaskActivityBehavior method execute.

public void execute(DelegateExecution execution) {
    CommandContext commandContext = Context.getCommandContext();
    TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
    TaskEntity task = taskEntityManager.create();
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    task.setExecution(executionEntity);
    task.setTaskDefinitionKey(userTask.getId());
    task.setBusinessKey(executionEntity.getProcessInstanceBusinessKey());
    String activeTaskName = null;
    String activeTaskDescription = null;
    String activeTaskDueDate = null;
    String activeTaskPriority = null;
    String activeTaskCategory = null;
    String activeTaskFormKey = null;
    String activeTaskSkipExpression = null;
    String activeTaskAssignee = null;
    String activeTaskOwner = null;
    List<String> activeTaskCandidateUsers = null;
    List<String> activeTaskCandidateGroups = null;
    ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
    ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
    if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
        ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(userTask.getId(), execution.getProcessDefinitionId());
        activeTaskName = getActiveValue(userTask.getName(), DynamicBpmnConstants.USER_TASK_NAME, taskElementProperties);
        activeTaskDescription = getActiveValue(userTask.getDocumentation(), DynamicBpmnConstants.USER_TASK_DESCRIPTION, taskElementProperties);
        activeTaskDueDate = getActiveValue(userTask.getDueDate(), DynamicBpmnConstants.USER_TASK_DUEDATE, taskElementProperties);
        activeTaskPriority = getActiveValue(userTask.getPriority(), DynamicBpmnConstants.USER_TASK_PRIORITY, taskElementProperties);
        activeTaskCategory = getActiveValue(userTask.getCategory(), DynamicBpmnConstants.USER_TASK_CATEGORY, taskElementProperties);
        activeTaskFormKey = getActiveValue(userTask.getFormKey(), DynamicBpmnConstants.USER_TASK_FORM_KEY, taskElementProperties);
        activeTaskSkipExpression = getActiveValue(userTask.getSkipExpression(), DynamicBpmnConstants.TASK_SKIP_EXPRESSION, taskElementProperties);
        activeTaskAssignee = getActiveValue(userTask.getAssignee(), DynamicBpmnConstants.USER_TASK_ASSIGNEE, taskElementProperties);
        activeTaskOwner = getActiveValue(userTask.getOwner(), DynamicBpmnConstants.USER_TASK_OWNER, taskElementProperties);
        activeTaskCandidateUsers = getActiveValueList(userTask.getCandidateUsers(), DynamicBpmnConstants.USER_TASK_CANDIDATE_USERS, taskElementProperties);
        activeTaskCandidateGroups = getActiveValueList(userTask.getCandidateGroups(), DynamicBpmnConstants.USER_TASK_CANDIDATE_GROUPS, taskElementProperties);
    } else {
        activeTaskName = userTask.getName();
        activeTaskDescription = userTask.getDocumentation();
        activeTaskDueDate = userTask.getDueDate();
        activeTaskPriority = userTask.getPriority();
        activeTaskCategory = userTask.getCategory();
        activeTaskFormKey = userTask.getFormKey();
        activeTaskSkipExpression = userTask.getSkipExpression();
        activeTaskAssignee = userTask.getAssignee();
        activeTaskOwner = userTask.getOwner();
        activeTaskCandidateUsers = userTask.getCandidateUsers();
        activeTaskCandidateGroups = userTask.getCandidateGroups();
    }
    if (StringUtils.isNotEmpty(activeTaskName)) {
        String name = null;
        try {
            name = (String) expressionManager.createExpression(activeTaskName).getValue(execution);
        } catch (ActivitiException e) {
            name = activeTaskName;
            LOGGER.warn("property not found in task name expression " + e.getMessage());
        }
        task.setName(name);
    }
    if (StringUtils.isNotEmpty(activeTaskDescription)) {
        String description = null;
        try {
            description = (String) expressionManager.createExpression(activeTaskDescription).getValue(execution);
        } catch (ActivitiException e) {
            description = activeTaskDescription;
            LOGGER.warn("property not found in task description expression " + e.getMessage());
        }
        task.setDescription(description);
    }
    if (StringUtils.isNotEmpty(activeTaskDueDate)) {
        Object dueDate = expressionManager.createExpression(activeTaskDueDate).getValue(execution);
        if (dueDate != null) {
            if (dueDate instanceof Date) {
                task.setDueDate((Date) dueDate);
            } else if (dueDate instanceof String) {
                String businessCalendarName = null;
                if (StringUtils.isNotEmpty(userTask.getBusinessCalendarName())) {
                    businessCalendarName = expressionManager.createExpression(userTask.getBusinessCalendarName()).getValue(execution).toString();
                } else {
                    businessCalendarName = DueDateBusinessCalendar.NAME;
                }
                BusinessCalendar businessCalendar = Context.getProcessEngineConfiguration().getBusinessCalendarManager().getBusinessCalendar(businessCalendarName);
                task.setDueDate(businessCalendar.resolveDuedate((String) dueDate));
            } else {
                throw new ActivitiIllegalArgumentException("Due date expression does not resolve to a Date or Date string: " + activeTaskDueDate);
            }
        }
    }
    if (StringUtils.isNotEmpty(activeTaskPriority)) {
        final Object priority = expressionManager.createExpression(activeTaskPriority).getValue(execution);
        if (priority != null) {
            if (priority instanceof String) {
                try {
                    task.setPriority(Integer.valueOf((String) priority));
                } catch (NumberFormatException e) {
                    throw new ActivitiIllegalArgumentException("Priority does not resolve to a number: " + priority, e);
                }
            } else if (priority instanceof Number) {
                task.setPriority(((Number) priority).intValue());
            } else {
                throw new ActivitiIllegalArgumentException("Priority expression does not resolve to a number: " + activeTaskPriority);
            }
        }
    }
    if (StringUtils.isNotEmpty(activeTaskCategory)) {
        final Object category = expressionManager.createExpression(activeTaskCategory).getValue(execution);
        if (category != null) {
            if (category instanceof String) {
                task.setCategory((String) category);
            } else {
                throw new ActivitiIllegalArgumentException("Category expression does not resolve to a string: " + activeTaskCategory);
            }
        }
    }
    if (StringUtils.isNotEmpty(activeTaskFormKey)) {
        final Object formKey = expressionManager.createExpression(activeTaskFormKey).getValue(execution);
        if (formKey != null) {
            if (formKey instanceof String) {
                task.setFormKey((String) formKey);
            } else {
                throw new ActivitiIllegalArgumentException("FormKey expression does not resolve to a string: " + activeTaskFormKey);
            }
        }
    }
    task.setAppVersion(executionEntity.getProcessInstance().getAppVersion());
    taskEntityManager.insert(task, executionEntity);
    task.setVariablesLocal(calculateInputVariables(execution));
    boolean skipUserTask = false;
    if (StringUtils.isNotEmpty(activeTaskSkipExpression)) {
        Expression skipExpression = expressionManager.createExpression(activeTaskSkipExpression);
        skipUserTask = SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpression) && SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression);
    }
    // Handling assignments need to be done after the task is inserted, to have an id
    if (!skipUserTask) {
        handleAssignments(taskEntityManager, activeTaskAssignee, activeTaskOwner, activeTaskCandidateUsers, activeTaskCandidateGroups, task, expressionManager, execution);
    }
    processEngineConfiguration.getListenerNotificationHelper().executeTaskListeners(task, TaskListener.EVENTNAME_CREATE);
    // All properties set, now fire events
    if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher();
        eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_CREATED, task));
        if (task.getAssignee() != null) {
            eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_ASSIGNED, task));
        }
    }
    if (skipUserTask) {
        taskEntityManager.deleteTask(task, null, false, false);
        leave(execution);
    }
}
Also used : ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Date(java.util.Date) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Expression(org.activiti.engine.delegate.Expression) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) DueDateBusinessCalendar(org.activiti.engine.impl.calendar.DueDateBusinessCalendar) BusinessCalendar(org.activiti.engine.impl.calendar.BusinessCalendar) TaskEntityManager(org.activiti.engine.impl.persistence.entity.TaskEntityManager) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ActivitiEventDispatcher(org.activiti.engine.delegate.event.ActivitiEventDispatcher)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)3 TaskEntityManager (org.activiti.engine.impl.persistence.entity.TaskEntityManager)3 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)2 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)2 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Date (java.util.Date)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 Expression (org.activiti.engine.delegate.Expression)1 ActivitiEventDispatcher (org.activiti.engine.delegate.event.ActivitiEventDispatcher)1 BusinessCalendar (org.activiti.engine.impl.calendar.BusinessCalendar)1 DueDateBusinessCalendar (org.activiti.engine.impl.calendar.DueDateBusinessCalendar)1 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)1 ExpressionManager (org.activiti.engine.impl.el.ExpressionManager)1 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)1 TimerJobEntityManager (org.activiti.engine.impl.persistence.entity.TimerJobEntityManager)1 VariableInstanceEntityManager (org.activiti.engine.impl.persistence.entity.VariableInstanceEntityManager)1