Search in sources :

Example 1 with UserTask

use of org.flowable.bpmn.model.UserTask in project syncope by apache.

the class SyncopeFormHandlerHelper method getTaskFormHandlder.

@Override
public TaskFormHandler getTaskFormHandlder(final String procDefId, final String taskId) {
    Process process = ProcessDefinitionUtil.getProcess(procDefId);
    FlowElement flowElement = process.getFlowElement(taskId, true);
    if (flowElement instanceof UserTask) {
        UserTask userTask = (UserTask) flowElement;
        ProcessDefinition processDefinitionEntity = ProcessDefinitionUtil.getProcessDefinition(procDefId);
        DeploymentEntity deploymentEntity = CommandContextUtil.getProcessEngineConfiguration().getDeploymentEntityManager().findById(processDefinitionEntity.getDeploymentId());
        TaskFormHandler taskFormHandler = new SyncopeTaskFormHandler();
        taskFormHandler.parseConfiguration(userTask.getFormProperties(), userTask.getFormKey(), deploymentEntity, processDefinitionEntity);
        return taskFormHandler;
    }
    return null;
}
Also used : DeploymentEntity(org.flowable.engine.impl.persistence.entity.DeploymentEntity) TaskFormHandler(org.flowable.engine.impl.form.TaskFormHandler) FlowElement(org.flowable.bpmn.model.FlowElement) UserTask(org.flowable.bpmn.model.UserTask) Process(org.flowable.bpmn.model.Process) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition)

Example 2 with UserTask

use of org.flowable.bpmn.model.UserTask in project syncope by apache.

the class DropdownAwareUserTaskJsonConverter method convertJsonToFormProperties.

@Override
protected void convertJsonToFormProperties(final JsonNode objectNode, final BaseElement element) {
    JsonNode formPropertiesNode = getProperty(PROPERTY_FORM_PROPERTIES, objectNode);
    if (formPropertiesNode != null) {
        formPropertiesNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(formPropertiesNode);
        JsonNode propertiesArray = formPropertiesNode.get("formProperties");
        if (propertiesArray != null) {
            for (JsonNode formNode : propertiesArray) {
                JsonNode formIdNode = formNode.get(PROPERTY_FORM_ID);
                if (formIdNode != null && StringUtils.isNotEmpty(formIdNode.asText())) {
                    FormProperty formProperty = new FormProperty();
                    formProperty.setId(formIdNode.asText());
                    formProperty.setName(getValueAsString(PROPERTY_FORM_NAME, formNode));
                    formProperty.setType(getValueAsString(PROPERTY_FORM_TYPE, formNode));
                    formProperty.setExpression(getValueAsString(PROPERTY_FORM_EXPRESSION, formNode));
                    formProperty.setVariable(getValueAsString(PROPERTY_FORM_VARIABLE, formNode));
                    if ("date".equalsIgnoreCase(formProperty.getType())) {
                        formProperty.setDatePattern(getValueAsString(PROPERTY_FORM_DATE_PATTERN, formNode));
                    } else if ("enum".equalsIgnoreCase(formProperty.getType()) || "dropdown".equalsIgnoreCase(formProperty.getType())) {
                        JsonNode enumValuesNode = formNode.get(PROPERTY_FORM_ENUM_VALUES);
                        if (enumValuesNode != null) {
                            List<FormValue> formValueList = new ArrayList<>();
                            for (JsonNode enumNode : enumValuesNode) {
                                if (enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID) != null && !enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID).isNull() && enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME) != null && !enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).isNull()) {
                                    FormValue formValue = new FormValue();
                                    formValue.setId(enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID).asText());
                                    formValue.setName(enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).asText());
                                    formValueList.add(formValue);
                                } else if (enumNode.get("value") != null && !enumNode.get("value").isNull()) {
                                    FormValue formValue = new FormValue();
                                    formValue.setId(enumNode.get("value").asText());
                                    formValue.setName(enumNode.get("value").asText());
                                    formValueList.add(formValue);
                                }
                            }
                            formProperty.setFormValues(formValueList);
                        }
                    }
                    formProperty.setRequired(getValueAsBoolean(PROPERTY_FORM_REQUIRED, formNode));
                    formProperty.setReadable(getValueAsBoolean(PROPERTY_FORM_READABLE, formNode));
                    formProperty.setWriteable(getValueAsBoolean(PROPERTY_FORM_WRITABLE, formNode));
                    if (element instanceof StartEvent) {
                        ((StartEvent) element).getFormProperties().add(formProperty);
                    } else if (element instanceof UserTask) {
                        ((UserTask) element).getFormProperties().add(formProperty);
                    }
                }
            }
        }
    }
}
Also used : FormValue(org.flowable.bpmn.model.FormValue) FormProperty(org.flowable.bpmn.model.FormProperty) StartEvent(org.flowable.bpmn.model.StartEvent) UserTask(org.flowable.bpmn.model.UserTask) JsonNode(com.fasterxml.jackson.databind.JsonNode) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with UserTask

use of org.flowable.bpmn.model.UserTask in project ruoyi-vue-pro by YunaiV.

the class BpmTaskAssignRuleServiceImpl method getTaskAssignRuleList.

@Override
public List<BpmTaskAssignRuleRespVO> getTaskAssignRuleList(String modelId, String processDefinitionId) {
    // 获得规则
    List<BpmTaskAssignRuleDO> rules = Collections.emptyList();
    BpmnModel model = null;
    if (StrUtil.isNotEmpty(modelId)) {
        rules = getTaskAssignRuleListByModelId(modelId);
        model = modelService.getBpmnModel(modelId);
    } else if (StrUtil.isNotEmpty(processDefinitionId)) {
        rules = getTaskAssignRuleListByProcessDefinitionId(processDefinitionId, null);
        model = processDefinitionService.getBpmnModel(processDefinitionId);
    }
    if (model == null) {
        return Collections.emptyList();
    }
    // 获得用户任务,只有用户任务才可以设置分配规则
    List<UserTask> userTasks = FlowableUtils.getBpmnModelElements(model, UserTask.class);
    if (CollUtil.isEmpty(userTasks)) {
        return Collections.emptyList();
    }
    // 转换数据
    return BpmTaskAssignRuleConvert.INSTANCE.convertList(userTasks, rules);
}
Also used : UserTask(org.flowable.bpmn.model.UserTask) BpmTaskAssignRuleDO(cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO) BpmnModel(org.flowable.bpmn.model.BpmnModel)

Example 4 with UserTask

use of org.flowable.bpmn.model.UserTask in project ox-data-cloud by ox-data.

the class BackUserTaskCmd method execute.

@Override
public String execute(CommandContext commandContext) {
    if (targetActivityId == null || targetActivityId.length() == 0) {
        throw new FlowableException("TargetActivityId cannot be empty");
    }
    // / TaskEntity task = CommandContextUtil.getTaskService().getTask(taskId);
    // / v6.5.1.28
    TaskEntity task = CommandContextUtil.getProcessEngineConfiguration().getTaskServiceConfiguration().getTaskService().getTask(taskId);
    if (task == null) {
        throw new FlowableObjectNotFoundException("task " + taskId + " doesn't exist", Task.class);
    }
    String sourceActivityId = task.getTaskDefinitionKey();
    String processInstanceId = task.getProcessInstanceId();
    String processDefinitionId = task.getProcessDefinitionId();
    Process process = ProcessDefinitionUtil.getProcess(processDefinitionId);
    FlowNode sourceFlowElement = (FlowNode) process.getFlowElement(sourceActivityId, true);
    // 只支持从用户任务退回
    if (!(sourceFlowElement instanceof UserTask)) {
        throw new FlowableException("Task with id:" + taskId + " is not a UserTask");
    }
    FlowNode targetFlowElement = (FlowNode) process.getFlowElement(targetActivityId, true);
    // 退回节点到当前节点不可达到,不允许退回
    if (!FlowableUtils.isReachable(process, targetFlowElement, sourceFlowElement)) {
        throw new FlowableException("Cannot back to [" + targetActivityId + "]");
    }
    // ps:目标节点如果相对当前节点是在子流程内部,则无法直接退回,目前处理是只能退回到子流程开始节点
    String[] sourceAndTargetRealActivityId = FlowableUtils.getSourceAndTargetRealActivityId(sourceFlowElement, targetFlowElement);
    // 实际应操作的当前节点ID
    String sourceRealActivityId = sourceAndTargetRealActivityId[0];
    // 实际应操作的目标节点ID
    String targetRealActivityId = sourceAndTargetRealActivityId[1];
    Map<String, Set<String>> specialGatewayNodes = FlowableUtils.getSpecialGatewayElements(process);
    // 当前节点处在的并行网关list
    List<String> sourceInSpecialGatewayList = new ArrayList<>();
    // 目标节点处在的并行网关list
    List<String> targetInSpecialGatewayList = new ArrayList<>();
    setSpecialGatewayList(sourceRealActivityId, targetRealActivityId, specialGatewayNodes, sourceInSpecialGatewayList, targetInSpecialGatewayList);
    // 实际应筛选的节点ID
    Set<String> sourceRealAcitivtyIds = null;
    // 若退回目标节点相对当前节点在并行网关中,则要找到相对当前节点最近的这个并行网关,后续做特殊处理
    String targetRealSpecialGateway = null;
    // 1.目标节点和当前节点都不在并行网关中
    if (targetInSpecialGatewayList.isEmpty() && sourceInSpecialGatewayList.isEmpty()) {
        sourceRealAcitivtyIds = Sets.newHashSet(sourceRealActivityId);
    } else // 2.目标节点不在并行网关中、当前节点在并行网关中
    if (targetInSpecialGatewayList.isEmpty() && !sourceInSpecialGatewayList.isEmpty()) {
        sourceRealAcitivtyIds = specialGatewayNodes.get(sourceInSpecialGatewayList.get(0));
    } else // 3.目标节点在并行网关中、当前节点不在并行网关中
    if (!targetInSpecialGatewayList.isEmpty() && sourceInSpecialGatewayList.isEmpty()) {
        sourceRealAcitivtyIds = Sets.newHashSet(sourceRealActivityId);
        targetRealSpecialGateway = targetInSpecialGatewayList.get(0);
    } else // 4.目标节点和当前节点都在并行网关中
    {
        int diffSpecialGatewayLevel = FlowableUtils.getDiffLevel(sourceInSpecialGatewayList, targetInSpecialGatewayList);
        // 在并行网关同一层且在同一分支
        if (diffSpecialGatewayLevel == -1) {
            sourceRealAcitivtyIds = Sets.newHashSet(sourceRealActivityId);
        } else {
            // 只筛选当前节点的execution
            if (sourceInSpecialGatewayList.size() == diffSpecialGatewayLevel) {
                sourceRealAcitivtyIds = Sets.newHashSet(sourceRealActivityId);
            } else // 当前节点相对目标节点在并行网关内,应筛选相对目标节点最近的并行网关的所有节点的execution
            {
                sourceRealAcitivtyIds = specialGatewayNodes.get(sourceInSpecialGatewayList.get(diffSpecialGatewayLevel));
            }
            // 不做处理
            if (targetInSpecialGatewayList.size() == diffSpecialGatewayLevel) {
            } else // 目标节点相对当前节点在并行网关内
            {
                targetRealSpecialGateway = targetInSpecialGatewayList.get(diffSpecialGatewayLevel);
            }
        }
    }
    // 筛选需要处理的execution
    List<ExecutionEntity> realExecutions = this.getRealExecutions(commandContext, processInstanceId, task.getExecutionId(), sourceRealActivityId, sourceRealAcitivtyIds);
    // 执行退回,直接跳转到实际的 targetRealActivityId
    List<String> realExecutionIds = realExecutions.stream().map(ExecutionEntity::getId).collect(Collectors.toList());
    runtimeService.createChangeActivityStateBuilder().processInstanceId(processInstanceId).moveExecutionsToSingleActivityId(realExecutionIds, targetRealActivityId).changeState();
    // 目标节点相对当前节点处于并行网关内,需要特殊处理,需要手动生成并行网关汇聚节点(_end)的execution数据
    if (targetRealSpecialGateway != null) {
        createTargetInSpecialGatewayEndExecutions(commandContext, realExecutions, process, targetInSpecialGatewayList, targetRealSpecialGateway);
    }
    return targetRealActivityId;
}
Also used : TaskEntity(org.flowable.task.service.impl.persistence.entity.TaskEntity) UserTask(org.flowable.bpmn.model.UserTask) Process(org.flowable.bpmn.model.Process) FlowableException(org.flowable.common.engine.api.FlowableException) FlowableObjectNotFoundException(org.flowable.common.engine.api.FlowableObjectNotFoundException) ExecutionEntity(org.flowable.engine.impl.persistence.entity.ExecutionEntity) FlowNode(org.flowable.bpmn.model.FlowNode)

Aggregations

UserTask (org.flowable.bpmn.model.UserTask)4 Process (org.flowable.bpmn.model.Process)2 BpmTaskAssignRuleDO (cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BpmnModel (org.flowable.bpmn.model.BpmnModel)1 FlowElement (org.flowable.bpmn.model.FlowElement)1 FlowNode (org.flowable.bpmn.model.FlowNode)1 FormProperty (org.flowable.bpmn.model.FormProperty)1 FormValue (org.flowable.bpmn.model.FormValue)1 StartEvent (org.flowable.bpmn.model.StartEvent)1 FlowableException (org.flowable.common.engine.api.FlowableException)1 FlowableObjectNotFoundException (org.flowable.common.engine.api.FlowableObjectNotFoundException)1 TaskFormHandler (org.flowable.engine.impl.form.TaskFormHandler)1 DeploymentEntity (org.flowable.engine.impl.persistence.entity.DeploymentEntity)1 ExecutionEntity (org.flowable.engine.impl.persistence.entity.ExecutionEntity)1 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)1 TaskEntity (org.flowable.task.service.impl.persistence.entity.TaskEntity)1