Search in sources :

Example 6 with WorkflowException

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;
}
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 7 with WorkflowException

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

Example 8 with WorkflowException

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");
}
Also used : 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)

Example 9 with WorkflowException

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
            }
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) Model(org.flowable.engine.repository.Model) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) FlowableException(org.flowable.engine.common.api.FlowableException) XMLStreamException(javax.xml.stream.XMLStreamException) BpmnModel(org.flowable.bpmn.model.BpmnModel) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter)

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