use of org.apache.syncope.core.persistence.api.dao.NotFoundException 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);
}
use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.
the class FlowableUserWorkflowAdapter method getForms.
@Transactional(readOnly = true)
@Override
public List<WorkflowFormTO> getForms() {
List<WorkflowFormTO> forms = new ArrayList<>();
String authUser = AuthContextUtils.getUsername();
if (adminUser.equals(authUser)) {
forms.addAll(getForms(engine.getTaskService().createTaskQuery().taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE)));
} else {
User user = userDAO.findByUsername(authUser);
if (user == null) {
throw new NotFoundException("Syncope User " + authUser);
}
forms.addAll(getForms(engine.getTaskService().createTaskQuery().taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE).taskCandidateOrAssigned(user.getKey())));
List<String> candidateGroups = new ArrayList<>();
userDAO.findAllGroupNames(user).forEach(group -> {
candidateGroups.add(group);
});
if (!candidateGroups.isEmpty()) {
forms.addAll(getForms(engine.getTaskService().createTaskQuery().taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE).taskCandidateGroupIn(candidateGroups)));
}
}
return forms;
}
use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.
the class FlowableUserWorkflowAdapter method getFormTO.
@SuppressWarnings("unchecked")
protected WorkflowFormTO getFormTO(final String processInstanceId, final String taskId, final String formKey, final List<FormProperty> properties) {
WorkflowFormTO formTO = new WorkflowFormTO();
User user = userDAO.findByWorkflowId(processInstanceId);
if (user == null) {
throw new NotFoundException("User with workflow id " + processInstanceId);
}
formTO.setUsername(user.getUsername());
formTO.setTaskId(taskId);
formTO.setKey(formKey);
formTO.setUserTO(engine.getRuntimeService().getVariable(processInstanceId, USER_TO, UserTO.class));
formTO.setUserPatch(engine.getRuntimeService().getVariable(processInstanceId, USER_PATCH, UserPatch.class));
properties.stream().map(fProp -> {
WorkflowFormPropertyTO propertyTO = new WorkflowFormPropertyTO();
BeanUtils.copyProperties(fProp, propertyTO, PROPERTY_IGNORE_PROPS);
propertyTO.setType(fromFlowableFormType(fProp.getType()));
if (propertyTO.getType() == WorkflowFormPropertyType.Date) {
propertyTO.setDatePattern((String) fProp.getType().getInformation("datePattern"));
}
if (propertyTO.getType() == WorkflowFormPropertyType.Enum) {
propertyTO.getEnumValues().putAll((Map<String, String>) fProp.getType().getInformation("values"));
}
return propertyTO;
}).forEachOrdered(propertyTO -> {
formTO.getProperties().add(propertyTO);
});
return formTO;
}
use of org.apache.syncope.core.persistence.api.dao.NotFoundException 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.persistence.api.dao.NotFoundException in project syncope by apache.
the class RemediationServiceImpl method check.
private void check(final String key, final String anyKey) {
RemediationTO remediation = logic.read(key);
AnyDAO<?> anyDAO;
switch(remediation.getAnyType()) {
case "USER":
anyDAO = userDAO;
break;
case "GROUP":
anyDAO = groupDAO;
break;
default:
anyDAO = anyObjectDAO;
}
Date etagDate = anyDAO.findLastChange(anyKey);
if (etagDate == null) {
throw new NotFoundException(remediation.getAnyType() + " for " + key);
}
checkETag(String.valueOf(etagDate.getTime()));
}
Aggregations