use of org.apache.syncope.core.workflow.api.WorkflowException 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.apache.syncope.core.workflow.api.WorkflowException 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.apache.syncope.core.workflow.api.WorkflowException in project syncope by apache.
the class FlowableUserWorkflowAdapter method importDefinition.
@Override
public void importDefinition(final String key, final WorkflowDefinitionFormat format, final String definition) {
ProcessDefinition procDef = getProcessDefinitionByKey(key);
String resourceName = procDef == null ? key + ".bpmn20.xml" : procDef.getResourceName();
Deployment deployment;
switch(format) {
case JSON:
JsonNode definitionNode;
try {
definitionNode = OBJECT_MAPPER.readTree(definition);
if (definitionNode.has(MODEL_DATA_JSON_MODEL)) {
definitionNode = definitionNode.get(MODEL_DATA_JSON_MODEL);
}
if (!definitionNode.has(BpmnJsonConverter.EDITOR_CHILD_SHAPES)) {
throw new IllegalArgumentException("Could not find JSON node " + BpmnJsonConverter.EDITOR_CHILD_SHAPES);
}
BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(definitionNode);
deployment = FlowableDeployUtils.deployDefinition(engine, resourceName, new BpmnXMLConverter().convertToXML(bpmnModel));
} catch (Exception e) {
throw new WorkflowException("While creating or updating process " + key, e);
}
break;
case XML:
default:
deployment = FlowableDeployUtils.deployDefinition(engine, resourceName, definition.getBytes());
}
procDef = getProcessDefinitionByDeploymentId(deployment.getId());
if (!key.equals(procDef.getKey())) {
throw new WorkflowException("Mismatching key: expected " + key + ", found " + procDef.getKey());
}
FlowableDeployUtils.deployModel(engine, procDef);
}
use of org.apache.syncope.core.workflow.api.WorkflowException in project syncope by apache.
the class DefaultUserWorkflowAdapter method doConfirmPasswordReset.
@Override
protected WorkflowResult<Pair<UserPatch, Boolean>> doConfirmPasswordReset(final User user, final String token, final String password) {
if (!user.checkToken(token)) {
throw new WorkflowException(new IllegalArgumentException("Wrong token: " + token + " for " + user));
}
user.removeToken();
UserPatch userPatch = new UserPatch();
userPatch.setKey(user.getKey());
userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).resources(userDAO.findAllResourceKeys(user.getKey())).value(password).build());
return doUpdate(user, userPatch);
}
use of org.apache.syncope.core.workflow.api.WorkflowException 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