Search in sources :

Example 1 with TaskFormData

use of org.flowable.engine.form.TaskFormData in project syncope by apache.

the class FlowableUserWorkflowAdapter method getForm.

@Override
public WorkflowFormTO getForm(final String workflowId) {
    Task task;
    try {
        task = engine.getTaskService().createTaskQuery().processInstanceId(workflowId).singleResult();
    } catch (FlowableException e) {
        throw new WorkflowException("While reading form for workflow instance " + workflowId, e);
    }
    TaskFormData formData;
    try {
        formData = engine.getFormService().getTaskFormData(task.getId());
    } catch (FlowableException e) {
        LOG.debug("No form found for task {}", task.getId(), e);
        formData = null;
    }
    WorkflowFormTO result = null;
    if (formData != null && !formData.getFormProperties().isEmpty()) {
        result = getFormTO(task);
    }
    return result;
}
Also used : Task(org.flowable.task.api.Task) FlowableException(org.flowable.engine.common.api.FlowableException) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) TaskFormData(org.flowable.engine.form.TaskFormData) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO)

Example 2 with TaskFormData

use of org.flowable.engine.form.TaskFormData in project syncope by apache.

the class FlowableUserWorkflowAdapter method checkTask.

protected Pair<Task, TaskFormData> checkTask(final String taskId, final String authUser) {
    Task task;
    try {
        task = engine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
        if (task == null) {
            throw new FlowableException("NULL result");
        }
    } catch (FlowableException e) {
        throw new NotFoundException("Flowable Task " + taskId, e);
    }
    TaskFormData formData;
    try {
        formData = engine.getFormService().getTaskFormData(task.getId());
    } catch (FlowableException e) {
        throw new NotFoundException("Form for Flowable Task " + taskId, e);
    }
    if (!adminUser.equals(authUser)) {
        User user = userDAO.findByUsername(authUser);
        if (user == null) {
            throw new NotFoundException("Syncope User " + authUser);
        }
    }
    return Pair.of(task, formData);
}
Also used : Task(org.flowable.task.api.Task) FlowableException(org.flowable.engine.common.api.FlowableException) User(org.apache.syncope.core.persistence.api.entity.user.User) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) TaskFormData(org.flowable.engine.form.TaskFormData)

Example 3 with TaskFormData

use of org.flowable.engine.form.TaskFormData in project syncope by apache.

the class FlowableUserWorkflowAdapter method claimForm.

@Override
public WorkflowFormTO claimForm(final String taskId) {
    String authUser = AuthContextUtils.getUsername();
    Pair<Task, TaskFormData> checked = checkTask(taskId, authUser);
    if (!adminUser.equals(authUser)) {
        List<Task> tasksForUser = engine.getTaskService().createTaskQuery().taskId(taskId).taskCandidateUser(authUser).list();
        if (tasksForUser.isEmpty()) {
            throw new WorkflowException(new IllegalArgumentException(authUser + " is not candidate for task " + taskId));
        }
    }
    Task task;
    try {
        engine.getTaskService().setOwner(taskId, authUser);
        task = engine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
    } catch (FlowableException e) {
        throw new WorkflowException("While reading task " + taskId, e);
    }
    return getFormTO(task, checked.getValue());
}
Also used : Task(org.flowable.task.api.Task) FlowableException(org.flowable.engine.common.api.FlowableException) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) TaskFormData(org.flowable.engine.form.TaskFormData)

Example 4 with TaskFormData

use of org.flowable.engine.form.TaskFormData in project syncope by apache.

the class FlowableUserWorkflowAdapter method getFormTask.

protected String getFormTask(final User user) {
    String result = null;
    List<Task> tasks = engine.getTaskService().createTaskQuery().processInstanceId(user.getWorkflowId()).list();
    if (tasks.isEmpty() || tasks.size() > 1) {
        LOG.debug("While checking if form task: unexpected task number ({})", tasks.size());
    } else {
        try {
            TaskFormData formData = engine.getFormService().getTaskFormData(tasks.get(0).getId());
            if (formData != null && !formData.getFormProperties().isEmpty()) {
                result = tasks.get(0).getId();
            }
        } catch (FlowableException e) {
            LOG.warn("Could not get task form data", e);
        }
    }
    return result;
}
Also used : Task(org.flowable.task.api.Task) FlowableException(org.flowable.engine.common.api.FlowableException) TaskFormData(org.flowable.engine.form.TaskFormData)

Example 5 with TaskFormData

use of org.flowable.engine.form.TaskFormData in project syncope by apache.

the class FlowableUserWorkflowAdapter method submitForm.

@Override
public WorkflowResult<UserPatch> submitForm(final WorkflowFormTO form) {
    String authUser = AuthContextUtils.getUsername();
    Pair<Task, TaskFormData> checked = checkTask(form.getTaskId(), authUser);
    if (!checked.getKey().getOwner().equals(authUser)) {
        throw new WorkflowException(new IllegalArgumentException("Task " + form.getTaskId() + " assigned to " + checked.getKey().getOwner() + " but submitted by " + authUser));
    }
    User user = userDAO.findByWorkflowId(checked.getKey().getProcessInstanceId());
    if (user == null) {
        throw new NotFoundException("User with workflow id " + checked.getKey().getProcessInstanceId());
    }
    Set<String> preTasks = getPerformedTasks(user);
    try {
        engine.getFormService().submitTaskFormData(form.getTaskId(), getPropertiesForSubmit(form));
        engine.getRuntimeService().setVariable(user.getWorkflowId(), FORM_SUBMITTER, authUser);
    } catch (FlowableException e) {
        throwException(e, "While submitting form for task " + form.getTaskId());
    }
    Set<String> postTasks = getPerformedTasks(user);
    postTasks.removeAll(preTasks);
    postTasks.add(form.getTaskId());
    updateStatus(user);
    User updated = userDAO.save(user);
    // see if there is any propagation to be done
    PropagationByResource propByRes = engine.getRuntimeService().getVariable(user.getWorkflowId(), PROP_BY_RESOURCE, PropagationByResource.class);
    // fetch - if available - the encrypted password
    String clearPassword = null;
    String encryptedPwd = engine.getRuntimeService().getVariable(user.getWorkflowId(), ENCRYPTED_PWD, String.class);
    if (StringUtils.isNotBlank(encryptedPwd)) {
        clearPassword = decrypt(encryptedPwd);
    }
    // supports approval chains
    saveForFormSubmit(user, clearPassword, propByRes);
    UserPatch userPatch = engine.getRuntimeService().getVariable(user.getWorkflowId(), USER_PATCH, UserPatch.class);
    if (userPatch == null) {
        userPatch = new UserPatch();
        userPatch.setKey(updated.getKey());
        userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).value(clearPassword).build());
        if (propByRes != null) {
            userPatch.getPassword().getResources().addAll(propByRes.get(ResourceOperation.CREATE));
        }
    }
    return new WorkflowResult<>(userPatch, propByRes, postTasks);
}
Also used : Task(org.flowable.task.api.Task) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) User(org.apache.syncope.core.persistence.api.entity.user.User) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) TaskFormData(org.flowable.engine.form.TaskFormData) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) FlowableException(org.flowable.engine.common.api.FlowableException)

Aggregations

FlowableException (org.flowable.engine.common.api.FlowableException)5 TaskFormData (org.flowable.engine.form.TaskFormData)5 Task (org.flowable.task.api.Task)5 WorkflowException (org.apache.syncope.core.workflow.api.WorkflowException)3 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)2 User (org.apache.syncope.core.persistence.api.entity.user.User)2 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)1 WorkflowFormTO (org.apache.syncope.common.lib.to.WorkflowFormTO)1 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)1 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)1