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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations