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