Search in sources :

Example 21 with ProcessDefinitionEntity

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project carbon-business-process by wso2.

the class AnalyticsConfigurationService method configureTaskLevelEvents.

@PUT
@Path("/processes/{process_id}/tasks/{task_id}")
@Consumes({ MediaType.APPLICATION_JSON })
public void configureTaskLevelEvents(@PathParam("process_id") String processDefinitionId, @PathParam("task_id") String taskId, DataPublisherConfig dataPublisherConfig) {
    try {
        RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
        ProcessDefinition process = repositoryService.getProcessDefinition(processDefinitionId);
        if (process != null && process instanceof ProcessDefinitionEntity) {
            ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) process;
            Map<String, TaskDefinition> taskDefinitions = processDefinitionEntity.getTaskDefinitions();
            TaskDefinition taskDefinition = taskDefinitions.get(taskId);
            if (taskDefinition != null) {
                if (dataPublisherConfig.isEnabled()) {
                    List<TaskListener> completionListeners = taskDefinition.getTaskListener(TaskListener.EVENTNAME_COMPLETE);
                    TaskListener taskCompletionListener = null;
                    for (TaskListener listener : completionListeners) {
                        if (listener instanceof TaskCompletionListener) {
                            taskCompletionListener = listener;
                            break;
                        }
                    }
                    if (taskCompletionListener == null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Adding task completion listener to task: " + taskId + " of process: " + processDefinitionId);
                        }
                        taskDefinition.addTaskListener(TaskListener.EVENTNAME_COMPLETE, new TaskCompletionListener());
                    }
                } else {
                    List<TaskListener> completionListeners = taskDefinition.getTaskListener(TaskListener.EVENTNAME_COMPLETE);
                    TaskListener taskCompletionListener = null;
                    for (TaskListener listener : completionListeners) {
                        if (listener instanceof TaskCompletionListener) {
                            taskCompletionListener = listener;
                            break;
                        }
                    }
                    if (taskCompletionListener != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Removing task completion listener from task: " + taskId + " of process: " + processDefinitionId);
                        }
                        completionListeners.remove(taskCompletionListener);
                    }
                }
            }
        }
    } catch (Exception e) {
        String msg = "Failed to configure events for task: " + taskId + " of process: " + processDefinitionId;
        log.error(msg, e);
        throw new BPMNRestException(msg, e);
    }
}
Also used : TaskCompletionListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.TaskCompletionListener) TaskDefinition(org.activiti.engine.impl.task.TaskDefinition) TaskListener(org.activiti.engine.delegate.TaskListener) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) RepositoryService(org.activiti.engine.RepositoryService)

Example 22 with ProcessDefinitionEntity

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project tutorials-java by Artister.

the class ActivityService method rejectTask.

/**
 * <p>流程跳转</p>
 *
 * @param processInstanceId 值为 processInstanceId
 * @param destinationTaskId 值为 xml中 userTask的id
 * @param rejectMessage
 */
public void rejectTask(String processInstanceId, String destinationTaskId, String rejectMessage, Map<String, Object> variables) {
    // 获得当前任务的对应实列
    Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
    // 当前任务key
    String currentTaskId = task.getTaskDefinitionKey();
    // 获得当前流程的定义模型
    ProcessDefinitionEntity processDefinition = ProcessDefinitionEntity.class.cast(RepositoryServiceImpl.class.cast(repositoryService).getDeployedProcessDefinition(task.getProcessDefinitionId()));
    // 获得当前流程定义模型的所有任务节点
    List<ActivityImpl> activities = processDefinition.getActivities();
    // 当前活动节点
    Optional<ActivityImpl> currentOptional = activities.stream().filter(activity -> Objects.equals(currentTaskId, activity.getId())).findFirst();
    // 驳回目标节点
    Optional<ActivityImpl> destinationOptional = activities.stream().filter(activity -> Objects.equals(destinationTaskId, activity.getId())).findFirst();
    // 保存当前活动节点的流程想参数
    List<PvmTransition> transitions = new ArrayList<>(0);
    if (currentOptional.isPresent() && destinationOptional.isPresent()) {
        ActivityImpl currentActivity = currentOptional.get();
        ActivityImpl destinationActivity = destinationOptional.get();
        transitions.addAll(currentActivity.getOutgoingTransitions());
        // 清空当前活动几点的所有流出项
        currentActivity.getOutgoingTransitions().clear();
        // 为当前节点动态创建新的流出项
        TransitionImpl newTransition = currentActivity.createOutgoingTransition();
        // 为当前活动节点新的流出目标指定流程目标
        newTransition.setDestination(destinationActivity);
        // 保存驳回意见
        // 设置驳回意见
        task.setDescription(rejectMessage);
        taskService.saveTask(task);
        // 添加批注
        Authentication.setAuthenticatedUserId("userId");
        taskService.addComment(task.getId(), processInstanceId, rejectMessage);
        // 执行当前任务驳回到目标任务draft
        taskService.complete(task.getId(), variables);
        // 清除目标节点的新流入项
        destinationActivity.getIncomingTransitions().remove(newTransition);
        // 清除原活动节点的临时流程项
        currentActivity.getOutgoingTransitions().clear();
        // 还原原活动节点流出项参数
        currentActivity.getOutgoingTransitions().addAll(transitions);
    }
}
Also used : org.activiti.engine(org.activiti.engine) Task(org.activiti.engine.task.Task) java.util(java.util) RepositoryServiceImpl(org.activiti.engine.impl.RepositoryServiceImpl) CancelEndEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.CancelEndEventActivityBehavior) Authentication(org.activiti.engine.impl.identity.Authentication) FlowNode(org.activiti.bpmn.model.FlowNode) Autowired(org.springframework.beans.factory.annotation.Autowired) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) IdentityLinkEntity(org.activiti.engine.impl.persistence.entity.IdentityLinkEntity) TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) FlowNodeActivityBehavior(org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior) Service(org.springframework.stereotype.Service) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) Transactional(org.springframework.transaction.annotation.Transactional) TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) Task(org.activiti.engine.task.Task) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Example 23 with ProcessDefinitionEntity

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

the class BpmnDeploymentHelper method setResourceNamesOnProcessDefinitions.

/**
 * Updates all the process definition entities to have the correct resource names.
 */
public void setResourceNamesOnProcessDefinitions(ParsedDeployment parsedDeployment) {
    for (ProcessDefinitionEntity processDefinition : parsedDeployment.getAllProcessDefinitions()) {
        String resourceName = parsedDeployment.getResourceForProcessDefinition(processDefinition).getName();
        processDefinition.setResourceName(resourceName);
    }
}
Also used : ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 24 with ProcessDefinitionEntity

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

the class BpmnDeploymentHelper method copyDeploymentValuesToProcessDefinitions.

/**
 * Updates all the process definition entities to match the deployment's values for tenant,
 * engine version, and deployment id.
 */
public void copyDeploymentValuesToProcessDefinitions(DeploymentEntity deployment, List<ProcessDefinitionEntity> processDefinitions) {
    String engineVersion = deployment.getEngineVersion();
    String tenantId = deployment.getTenantId();
    String deploymentId = deployment.getId();
    for (ProcessDefinitionEntity processDefinition : processDefinitions) {
        // Backwards compatibility
        if (engineVersion != null) {
            processDefinition.setEngineVersion(engineVersion);
        }
        // process definition inherits the tenant id
        if (tenantId != null) {
            processDefinition.setTenantId(tenantId);
        }
        processDefinition.setDeploymentId(deploymentId);
    }
}
Also used : ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 25 with ProcessDefinitionEntity

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

the class BpmnDeploymentHelper method getPersistedInstanceOfProcessDefinition.

/**
 * Gets the persisted version of the already-deployed process definition.  Note that this is
 * different from {@link #getMostRecentVersionOfProcessDefinition} as it looks specifically for
 * a process definition that is already persisted and attached to a particular deployment,
 * rather than the latest version across all deployments.
 */
public ProcessDefinitionEntity getPersistedInstanceOfProcessDefinition(ProcessDefinitionEntity processDefinition) {
    String deploymentId = processDefinition.getDeploymentId();
    if (StringUtils.isEmpty(processDefinition.getDeploymentId())) {
        throw new IllegalStateException("Provided process definition must have a deployment id.");
    }
    ProcessDefinitionEntityManager processDefinitionManager = Context.getCommandContext().getProcessEngineConfiguration().getProcessDefinitionEntityManager();
    ProcessDefinitionEntity persistedProcessDefinition = null;
    if (processDefinition.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinition.getTenantId())) {
        persistedProcessDefinition = processDefinitionManager.findProcessDefinitionByDeploymentAndKey(deploymentId, processDefinition.getKey());
    } else {
        persistedProcessDefinition = processDefinitionManager.findProcessDefinitionByDeploymentAndKeyAndTenantId(deploymentId, processDefinition.getKey(), processDefinition.getTenantId());
    }
    return persistedProcessDefinition;
}
Also used : ProcessDefinitionEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Aggregations

ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)64 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)12 ActivitiException (org.activiti.engine.ActivitiException)11 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)9 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)8 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)8 BpmnModel (org.activiti.bpmn.model.BpmnModel)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 RepositoryService (org.activiti.engine.RepositoryService)6 ProcessDefinitionEntityManager (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager)6 StreamResource (com.vaadin.terminal.StreamResource)5 HashMap (java.util.HashMap)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)4 Deployment (org.activiti.engine.test.Deployment)4 Embedded (com.vaadin.ui.Embedded)3 Label (com.vaadin.ui.Label)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2