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