Search in sources :

Example 1 with WorkflowException

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;
}
Also used : Task(org.flowable.task.api.Task) FlowableException(org.flowable.engine.common.api.FlowableException) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) TaskFormData(org.flowable.engine.form.TaskFormData) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO)

Example 2 with WorkflowException

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());
}
Also used : Task(org.flowable.task.api.Task) FlowableException(org.flowable.engine.common.api.FlowableException) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) TaskFormData(org.flowable.engine.form.TaskFormData)

Example 3 with WorkflowException

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);
}
Also used : WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) Deployment(org.flowable.engine.repository.Deployment) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) FlowableException(org.flowable.engine.common.api.FlowableException) IOException(java.io.IOException) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter)

Example 4 with WorkflowException

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);
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 5 with WorkflowException

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

Aggregations

WorkflowException (org.apache.syncope.core.workflow.api.WorkflowException)9 FlowableException (org.flowable.engine.common.api.FlowableException)6 User (org.apache.syncope.core.persistence.api.entity.user.User)4 Task (org.flowable.task.api.Task)4 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)3 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 TaskFormData (org.flowable.engine.form.TaskFormData)3 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)2 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)2 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)2 BpmnXMLConverter (org.flowable.bpmn.converter.BpmnXMLConverter)2 BpmnModel (org.flowable.bpmn.model.BpmnModel)2 BpmnJsonConverter (org.flowable.editor.language.json.converter.BpmnJsonConverter)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1