Search in sources :

Example 1 with ProcessInstance

use of org.flowable.engine.runtime.ProcessInstance in project syncope by apache.

the class FlowableUserWorkflowAdapter method doCreate.

@Override
protected WorkflowResult<Pair<String, Boolean>> doCreate(final UserTO userTO, final boolean disablePwdPolicyCheck, final Boolean enabled, final boolean storePassword) {
    Map<String, Object> variables = new HashMap<>();
    variables.put(WF_EXECUTOR, AuthContextUtils.getUsername());
    variables.put(USER_TO, userTO);
    variables.put(ENABLED, enabled);
    variables.put(STORE_PASSWORD, storePassword);
    ProcessInstance processInstance = null;
    try {
        processInstance = engine.getRuntimeService().startProcessInstanceByKey(WF_PROCESS_ID, variables);
    } catch (FlowableException e) {
        throwException(e, "While starting " + WF_PROCESS_ID + " instance");
    }
    User user = engine.getRuntimeService().getVariable(processInstance.getProcessInstanceId(), USER, User.class);
    Boolean updatedEnabled = engine.getRuntimeService().getVariable(processInstance.getProcessInstanceId(), ENABLED, Boolean.class);
    if (updatedEnabled != null) {
        user.setSuspended(!updatedEnabled);
    }
    // this will make UserValidator not to consider password policies at all
    if (disablePwdPolicyCheck) {
        user.removeClearPassword();
    }
    updateStatus(user);
    user = userDAO.save(user);
    Boolean propagateEnable = engine.getRuntimeService().getVariable(processInstance.getProcessInstanceId(), PROPAGATE_ENABLE, Boolean.class);
    if (propagateEnable == null) {
        propagateEnable = enabled;
    }
    PropagationByResource propByRes = new PropagationByResource();
    propByRes.set(ResourceOperation.CREATE, userDAO.findAllResourceKeys(user.getKey()));
    saveForFormSubmit(user, userTO.getPassword(), propByRes);
    Set<String> tasks = getPerformedTasks(user);
    return new WorkflowResult<>(Pair.of(user.getKey(), propagateEnable), propByRes, tasks);
}
Also used : FlowableException(org.flowable.engine.common.api.FlowableException) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) User(org.apache.syncope.core.persistence.api.entity.user.User) HashMap(java.util.HashMap) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ProcessInstance(org.flowable.engine.runtime.ProcessInstance)

Example 2 with ProcessInstance

use of org.flowable.engine.runtime.ProcessInstance in project hello-world by haoziapple.

the class HolidayRequest method startCLIProcess.

// 通过命令行参数启动一个流程
private static void startCLIProcess(ProcessEngine processEngine) {
    // 申请请假
    Scanner scanner = new Scanner(System.in);
    System.out.println("Who are you?");
    String employee = scanner.nextLine();
    System.out.println("How many holidays do you want to request?");
    Integer nrOfHolidays = Integer.valueOf(scanner.nextLine());
    System.out.println("Why do you need them?");
    String description = scanner.nextLine();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    Map<String, Object> variables = new HashMap<String, Object>(16);
    variables.put("employee", employee);
    variables.put("nrOfHolidays", nrOfHolidays);
    variables.put("description", description);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayRequest", variables);
    // 经理查看请假列表
    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("managers").list();
    System.out.println("You have " + tasks.size() + " tasks:");
    for (int i = 0; i < tasks.size(); i++) {
        System.out.println((i + 1) + ") " + tasks.get(i).getName());
    }
    // 同意或拒绝申请
    System.out.println("Which task would you like to complete?");
    int taskIndex = Integer.valueOf(scanner.nextLine());
    Task task = tasks.get(taskIndex - 1);
    Map<String, Object> processVariables = taskService.getVariables(task.getId());
    System.out.println(processVariables.get("employee") + " wants " + processVariables.get("nrOfHolidays") + " of holidays. Do you approve this?");
    boolean approved = scanner.nextLine().toLowerCase().equals("y");
    variables = new HashMap<String, Object>();
    variables.put("approved", approved);
    taskService.complete(task.getId(), variables);
}
Also used : Scanner(java.util.Scanner) Task(org.flowable.task.api.Task) HashMap(java.util.HashMap) ProcessInstance(org.flowable.engine.runtime.ProcessInstance)

Example 3 with ProcessInstance

use of org.flowable.engine.runtime.ProcessInstance in project plumdo-work by wengwh.

the class ProcessInstanceActivateResource method activateProcessInstance.

@PutMapping(value = "/process-instances/{processInstanceId}/activate", name = "流程实例激活")
@ResponseStatus(value = HttpStatus.OK)
public void activateProcessInstance(@PathVariable String processInstanceId) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    if (!processInstance.isSuspended()) {
        exceptionFactory.throwConflict(ErrorConstant.INSTANCE_ALREADY_ACTIVE, processInstance.getId());
    }
    runtimeService.activateProcessInstanceById(processInstance.getId());
}
Also used : ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 4 with ProcessInstance

use of org.flowable.engine.runtime.ProcessInstance in project plumdo-work by wengwh.

the class ProcessInstanceResource method startProcessInstance.

@PostMapping(value = "/process-instances", name = "流程实例创建")
@ResponseStatus(value = HttpStatus.CREATED)
@Transactional(propagation = Propagation.REQUIRED)
public ProcessInstanceStartResponse startProcessInstance(@RequestBody ProcessInstanceStartRequest request) {
    if (request.getProcessDefinitionId() == null && request.getProcessDefinitionKey() == null) {
        exceptionFactory.throwIllegalArgument(ErrorConstant.PARAM_NOT_FOUND, "processDefinitionId或者processDefinitionKey");
    }
    int paramsSet = ((request.getProcessDefinitionId() != null) ? 1 : 0) + ((request.getProcessDefinitionKey() != null) ? 1 : 0);
    if (paramsSet > 1) {
        exceptionFactory.throwIllegalArgument(ErrorConstant.INSTANCE_START_PARAM_TO_MANY);
    }
    if (request.isCustomTenantSet()) {
        if (request.getProcessDefinitionId() != null) {
            exceptionFactory.throwIllegalArgument(ErrorConstant.INSTANCE_START_TENANT_ERROR);
        }
    }
    Map<String, Object> startVariables = null;
    if (request.getVariables() != null) {
        startVariables = new HashMap<>();
        for (RestVariable variable : request.getVariables()) {
            if (variable.getName() == null) {
                exceptionFactory.throwIllegalArgument(ErrorConstant.PARAM_NOT_FOUND, "Variable name");
            }
            startVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
        }
    }
    org.flowable.engine.common.impl.identity.Authentication.setAuthenticatedUserId(Authentication.getUserId());
    ProcessInstance instance = null;
    if (request.getProcessDefinitionId() != null) {
        instance = runtimeService.startProcessInstanceById(request.getProcessDefinitionId(), request.getBusinessKey(), startVariables);
    } else if (request.getProcessDefinitionKey() != null) {
        if (request.isCustomTenantSet()) {
            instance = runtimeService.startProcessInstanceByKeyAndTenantId(request.getProcessDefinitionKey(), request.getBusinessKey(), startVariables, request.getTenantId());
        } else {
            instance = runtimeService.startProcessInstanceByKey(request.getProcessDefinitionKey(), request.getBusinessKey(), startVariables);
        }
    }
    if (request.isAutoCommitTask()) {
        List<Task> tasks = taskService.createTaskQuery().processInstanceId(instance.getProcessInstanceId()).list();
        for (Task task : tasks) {
            if (ObjectUtils.isEmpty(task.getAssignee())) {
                taskService.setAssignee(task.getId(), Authentication.getUserId());
            }
            taskService.complete(task.getId());
        }
    }
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(instance.getProcessInstanceId()).list();
    return restResponseFactory.createProcessInstanceStartResponse(instance, tasks);
}
Also used : RestVariable(com.plumdo.flow.rest.variable.RestVariable) Task(org.flowable.task.api.Task) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with ProcessInstance

use of org.flowable.engine.runtime.ProcessInstance in project plumdo-work by wengwh.

the class ProcessInstanceResource method getProcessDefinition.

@GetMapping(value = "/process-instances/{processInstanceId}", name = "根据ID获取流程实例")
public ProcessInstanceDetailResponse getProcessDefinition(@PathVariable String processInstanceId) {
    ProcessInstance processInstance = null;
    HistoricProcessInstance historicProcessInstance = getHistoricProcessInstanceFromRequest(processInstanceId);
    if (historicProcessInstance.getEndTime() == null) {
        processInstance = getProcessInstanceFromRequest(processInstanceId);
    }
    return restResponseFactory.createProcessInstanceDetailResponse(historicProcessInstance, processInstance);
}
Also used : HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ProcessInstance (org.flowable.engine.runtime.ProcessInstance)11 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 HistoricProcessInstance (org.flowable.engine.history.HistoricProcessInstance)4 Task (org.flowable.task.api.Task)3 FlowableConflictException (com.plumdo.flow.exception.FlowableConflictException)2 HashMap (java.util.HashMap)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 PutMapping (org.springframework.web.bind.annotation.PutMapping)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 RestVariable (com.plumdo.flow.rest.variable.RestVariable)1 LinkedHashMap (java.util.LinkedHashMap)1 Scanner (java.util.Scanner)1 User (org.apache.syncope.core.persistence.api.entity.user.User)1 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)1 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)1 HistoryService (org.flowable.engine.HistoryService)1 ProcessEngine (org.flowable.engine.ProcessEngine)1 ProcessEngineConfiguration (org.flowable.engine.ProcessEngineConfiguration)1 RepositoryService (org.flowable.engine.RepositoryService)1 RuntimeService (org.flowable.engine.RuntimeService)1