use of org.apache.syncope.core.workflow.api.WorkflowException in project syncope by apache.
the class FlowableUserWorkflowAdapter method doExecuteTask.
protected Set<String> doExecuteTask(final User user, final String task, final Map<String, Object> moreVariables) {
Set<String> preTasks = getPerformedTasks(user);
Map<String, Object> variables = new HashMap<>();
variables.put(WF_EXECUTOR, AuthContextUtils.getUsername());
variables.put(TASK, task);
// using BeanUtils to access all user's properties and trigger lazy loading - we are about to
// serialize a User instance for availability within workflow tasks, and this breaks transactions
BeanUtils.copyProperties(user, entityFactory.newEntity(User.class));
variables.put(USER, user);
if (moreVariables != null && !moreVariables.isEmpty()) {
variables.putAll(moreVariables);
}
if (StringUtils.isBlank(user.getWorkflowId())) {
throw new WorkflowException(new NotFoundException("Empty workflow id for " + user));
}
List<Task> tasks = engine.getTaskService().createTaskQuery().processInstanceId(user.getWorkflowId()).list();
if (tasks.size() == 1) {
try {
engine.getTaskService().complete(tasks.get(0).getId(), variables);
} catch (FlowableException e) {
throwException(e, "While completing task '" + tasks.get(0).getName() + "' for " + user);
}
} else {
LOG.warn("Expected a single task, found {}", tasks.size());
}
Set<String> postTasks = getPerformedTasks(user);
postTasks.removeAll(preTasks);
postTasks.add(task);
return postTasks;
}
use of org.apache.syncope.core.workflow.api.WorkflowException in project syncope by apache.
the class PasswordReset method doExecute.
@Override
protected void doExecute(final String executionId) {
User user = engine.getRuntimeService().getVariable(executionId, FlowableUserWorkflowAdapter.USER, User.class);
String token = engine.getRuntimeService().getVariable(executionId, FlowableUserWorkflowAdapter.TOKEN, String.class);
String password = engine.getRuntimeService().getVariable(executionId, FlowableUserWorkflowAdapter.PASSWORD, String.class);
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());
PropagationByResource propByRes = dataBinder.update(user, userPatch);
// report updated user and propagation by resource as result
engine.getRuntimeService().setVariable(executionId, FlowableUserWorkflowAdapter.USER, user);
engine.getRuntimeService().setVariable(executionId, FlowableUserWorkflowAdapter.USER_PATCH, userPatch);
engine.getRuntimeService().setVariable(executionId, FlowableUserWorkflowAdapter.PROP_BY_RESOURCE, propByRes);
}
use of org.apache.syncope.core.workflow.api.WorkflowException in project syncope by apache.
the class DefaultUserWorkflowAdapter method doActivate.
@Override
protected WorkflowResult<String> doActivate(final User user, final String token) {
if (!user.checkToken(token)) {
throw new WorkflowException(new IllegalArgumentException("Wrong token: " + token + " for " + user));
}
user.removeToken();
user.setStatus("active");
User updated = userDAO.save(user);
return new WorkflowResult<>(updated.getKey(), null, "activate");
}
use of org.apache.syncope.core.workflow.api.WorkflowException in project syncope by apache.
the class FlowableDeployUtils method deployModel.
public static void deployModel(final ProcessEngine engine, final ProcessDefinition procDef) {
XMLStreamReader xtr = null;
try (InputStream bpmnStream = engine.getRepositoryService().getResourceAsStream(procDef.getDeploymentId(), procDef.getResourceName());
InputStreamReader isr = new InputStreamReader(bpmnStream)) {
xtr = XMLInputFactory.newInstance().createXMLStreamReader(isr);
BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
Model model = engine.getRepositoryService().newModel();
ObjectNode modelObjectNode = OBJECT_MAPPER.createObjectNode();
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, procDef.getName());
model.setMetaInfo(modelObjectNode.toString());
model.setName(procDef.getName());
model.setDeploymentId(procDef.getDeploymentId());
model.setVersion(procDef.getVersion());
engine.getRepositoryService().saveModel(model);
engine.getRepositoryService().addModelEditorSource(model.getId(), new BpmnJsonConverter().convertToJson(bpmnModel).toString().getBytes());
} catch (Exception e) {
throw new WorkflowException("While importing " + procDef.getResourceName(), e);
} finally {
if (xtr != null) {
try {
xtr.close();
} catch (XMLStreamException e) {
// ignore
}
}
}
}
Aggregations