Search in sources :

Example 71 with NotFoundException

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

Example 72 with NotFoundException

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;
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) ArrayList(java.util.ArrayList) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 73 with NotFoundException

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;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) Pair(org.apache.commons.lang3.tuple.Pair) DomainProcessEngine(org.apache.syncope.core.workflow.flowable.spring.DomainProcessEngine) Map(java.util.Map) AbstractUserWorkflowAdapter(org.apache.syncope.core.workflow.java.AbstractUserWorkflowAdapter) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) JsonNode(com.fasterxml.jackson.databind.JsonNode) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) FormType(org.flowable.engine.form.FormType) Resource(javax.annotation.Resource) Set(java.util.Set) Model(org.flowable.engine.repository.Model) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Deployment(org.flowable.engine.repository.Deployment) Task(org.flowable.task.api.Task) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Query(org.flowable.engine.common.api.query.Query) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) WorkflowFormPropertyType(org.apache.syncope.common.lib.types.WorkflowFormPropertyType) FormProperty(org.flowable.engine.form.FormProperty) WorkflowFormPropertyTO(org.apache.syncope.common.lib.to.WorkflowFormPropertyTO) WorkflowDefinitionFormat(org.apache.syncope.core.workflow.api.WorkflowDefinitionFormat) TaskFormData(org.flowable.engine.form.TaskFormData) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter) HashMap(java.util.HashMap) BeanUtils(org.apache.syncope.core.spring.BeanUtils) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FlowableException(org.flowable.engine.common.api.FlowableException) BpmnModel(org.flowable.bpmn.model.BpmnModel) ModelDataJsonConstants(org.flowable.editor.constants.ModelDataJsonConstants) OutputStream(java.io.OutputStream) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance) WorkflowDefinitionTO(org.apache.syncope.common.lib.to.WorkflowDefinitionTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) User(org.apache.syncope.core.persistence.api.entity.user.User) IOException(java.io.IOException) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) Collections(java.util.Collections) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) InputStream(java.io.InputStream) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) HistoricFormPropertyEntity(org.flowable.engine.impl.persistence.entity.HistoricFormPropertyEntity) Transactional(org.springframework.transaction.annotation.Transactional) User(org.apache.syncope.core.persistence.api.entity.user.User) UserTO(org.apache.syncope.common.lib.to.UserTO) WorkflowFormPropertyTO(org.apache.syncope.common.lib.to.WorkflowFormPropertyTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Map(java.util.Map) HashMap(java.util.HashMap) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 74 with NotFoundException

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;
}
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) HashMap(java.util.HashMap) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException)

Example 75 with NotFoundException

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()));
}
Also used : RemediationTO(org.apache.syncope.common.lib.to.RemediationTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Date(java.util.Date)

Aggregations

NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)110 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)87 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)41 Transactional (org.springframework.transaction.annotation.Transactional)21 Date (java.util.Date)12 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)10 SchedulerException (org.quartz.SchedulerException)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)8 Report (org.apache.syncope.core.persistence.api.entity.Report)8 SchedTask (org.apache.syncope.core.persistence.api.entity.task.SchedTask)8 User (org.apache.syncope.core.persistence.api.entity.user.User)8 HashMap (java.util.HashMap)7 Collectors (java.util.stream.Collectors)7 Pair (org.apache.commons.lang3.tuple.Pair)7 ExecTO (org.apache.syncope.common.lib.to.ExecTO)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 StringUtils (org.apache.commons.lang3.StringUtils)6 DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)6