Search in sources :

Example 1 with HistoricVariableInstance

use of org.flowable.variable.api.history.HistoricVariableInstance in project zaakafhandelcomponent by NL-AMS-LOCGOV.

the class FlowableService method readTaakdata.

public Map<String, String> readTaakdata(final String taskId) {
    final Map<String, String> taakdata;
    if (isOpenTask(taskId)) {
        taakdata = (Map<String, String>) cmmnTaskService.getVariableLocal(taskId, VAR_TASK_TAAKDATA);
    } else {
        final HistoricVariableInstance historicVariableInstance = cmmnHistoryService.createHistoricVariableInstanceQuery().taskId(taskId).variableName(VAR_TASK_TAAKDATA).singleResult();
        taakdata = historicVariableInstance != null ? (Map<String, String>) historicVariableInstance.getValue() : null;
    }
    return taakdata != null ? taakdata : Collections.emptyMap();
}
Also used : HistoricVariableInstance(org.flowable.variable.api.history.HistoricVariableInstance) Map(java.util.Map)

Example 2 with HistoricVariableInstance

use of org.flowable.variable.api.history.HistoricVariableInstance in project plumdo-work by wengwh.

the class RestResponseFactory method createRestVariables.

public List<RestVariable> createRestVariables(List<HistoricVariableInstance> historicVariableInstances) {
    List<RestVariable> result = new ArrayList<>();
    RestVariableConverter converter = null;
    for (HistoricVariableInstance pair : historicVariableInstances) {
        for (RestVariableConverter c : variableConverters) {
            if (c.getRestTypeName().equals(pair.getVariableTypeName())) {
                converter = c;
                break;
            }
        }
        RestVariable restVariable = new RestVariable();
        restVariable.setName(pair.getVariableName());
        if (converter != null) {
            restVariable.setType(converter.getRestTypeName());
            converter.convertVariableValue(pair.getValue(), restVariable);
        } else {
            restVariable.setType(pair.getVariableTypeName());
            restVariable.setValue(pair.getValue());
        }
        result.add(restVariable);
    }
    return result;
}
Also used : RestVariable(com.plumdo.flow.rest.variable.RestVariable) StringRestVariableConverter(com.plumdo.flow.rest.variable.StringRestVariableConverter) BooleanRestVariableConverter(com.plumdo.flow.rest.variable.BooleanRestVariableConverter) IntegerRestVariableConverter(com.plumdo.flow.rest.variable.IntegerRestVariableConverter) DoubleRestVariableConverter(com.plumdo.flow.rest.variable.DoubleRestVariableConverter) LongRestVariableConverter(com.plumdo.flow.rest.variable.LongRestVariableConverter) ShortRestVariableConverter(com.plumdo.flow.rest.variable.ShortRestVariableConverter) RestVariableConverter(com.plumdo.flow.rest.variable.RestVariableConverter) ListRestVariableConverter(com.plumdo.flow.rest.variable.ListRestVariableConverter) DateRestVariableConverter(com.plumdo.flow.rest.variable.DateRestVariableConverter) ArrayList(java.util.ArrayList) HistoricVariableInstance(org.flowable.variable.api.history.HistoricVariableInstance)

Example 3 with HistoricVariableInstance

use of org.flowable.variable.api.history.HistoricVariableInstance in project syncope by apache.

the class FlowableUserRequestHandler method submitForm.

@Override
@SuppressWarnings("unchecked")
public UserWorkflowResult<UserUR> submitForm(final UserRequestForm form) {
    Pair<Task, TaskFormData> parsed = parseTask(form.getTaskId());
    String authUser = AuthContextUtils.getUsername();
    if (!parsed.getLeft().getAssignee().equals(authUser)) {
        throw new WorkflowException(new IllegalArgumentException("Task " + form.getTaskId() + " assigned to " + parsed.getLeft().getAssignee() + " but submitted by " + authUser));
    }
    String procInstID = parsed.getLeft().getProcessInstanceId();
    User user = userDAO.find(getUserKey(procInstID));
    if (user == null) {
        throw new NotFoundException("User with key " + getUserKey(procInstID));
    }
    Set<String> preTasks = FlowableRuntimeUtils.getPerformedTasks(engine, procInstID);
    engine.getRuntimeService().setVariable(procInstID, FlowableRuntimeUtils.TASK, "submit");
    engine.getRuntimeService().setVariable(procInstID, FlowableRuntimeUtils.FORM_SUBMITTER, authUser);
    engine.getRuntimeService().setVariable(procInstID, FlowableRuntimeUtils.USER, lazyLoad(user));
    try {
        engine.getFormService().submitTaskFormData(form.getTaskId(), getPropertiesForSubmit(form));
    } catch (FlowableException e) {
        FlowableRuntimeUtils.throwException(e, "While submitting form for task " + form.getTaskId());
    }
    Set<String> postTasks = FlowableRuntimeUtils.getPerformedTasks(engine, procInstID);
    postTasks.removeAll(preTasks);
    postTasks.add(form.getTaskId());
    if (procInstID.equals(FlowableRuntimeUtils.getWFProcInstID(engine, user.getKey()))) {
        FlowableRuntimeUtils.updateStatus(engine, procInstID, user);
    }
    user = userDAO.save(user);
    PropagationByResource<String> propByRes;
    PropagationByResource<Pair<String, String>> propByLinkedAccount;
    String clearPassword = null;
    UserUR userUR;
    if (engine.getRuntimeService().createProcessInstanceQuery().processInstanceId(procInstID).singleResult() == null) {
        List<HistoricVariableInstance> historicVariables = engine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(procInstID).list();
        // see if there is any propagation to be done
        propByRes = getHistoricVariable(historicVariables, FlowableRuntimeUtils.PROP_BY_RESOURCE, PropagationByResource.class);
        propByLinkedAccount = getHistoricVariable(historicVariables, FlowableRuntimeUtils.PROP_BY_LINKEDACCOUNT, PropagationByResource.class);
        // fetch - if available - the encrypted password
        String encryptedPwd = getHistoricVariable(historicVariables, FlowableRuntimeUtils.ENCRYPTED_PWD, String.class);
        if (StringUtils.isNotBlank(encryptedPwd)) {
            clearPassword = FlowableRuntimeUtils.decrypt(encryptedPwd);
        }
        userUR = getHistoricVariable(historicVariables, FlowableRuntimeUtils.USER_UR, UserUR.class);
    } else {
        engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.TASK);
        engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.FORM_SUBMITTER);
        engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.USER);
        engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.USER_TO);
        // see if there is any propagation to be done
        propByRes = engine.getRuntimeService().getVariable(procInstID, FlowableRuntimeUtils.PROP_BY_RESOURCE, PropagationByResource.class);
        engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.PROP_BY_RESOURCE);
        propByLinkedAccount = engine.getRuntimeService().getVariable(procInstID, FlowableRuntimeUtils.PROP_BY_LINKEDACCOUNT, PropagationByResource.class);
        engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.PROP_BY_LINKEDACCOUNT);
        // fetch - if available - the encrypted password
        String encryptedPwd = engine.getRuntimeService().getVariable(procInstID, FlowableRuntimeUtils.ENCRYPTED_PWD, String.class);
        engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.ENCRYPTED_PWD);
        if (StringUtils.isNotBlank(encryptedPwd)) {
            clearPassword = FlowableRuntimeUtils.decrypt(encryptedPwd);
        }
        Boolean enabled = engine.getRuntimeService().getVariable(procInstID, FlowableRuntimeUtils.ENABLED, Boolean.class);
        engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.ENABLED);
        // supports approval chains
        FlowableRuntimeUtils.saveForFormSubmit(engine, procInstID, dataBinder.getUserTO(user, true), clearPassword, enabled, propByRes, propByLinkedAccount);
        userUR = engine.getRuntimeService().getVariable(procInstID, FlowableRuntimeUtils.USER_UR, UserUR.class);
        engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.USER_UR);
    }
    if (userUR == null) {
        userUR = new UserUR();
        userUR.setKey(user.getKey());
        userUR.setPassword(new PasswordPatch.Builder().onSyncope(true).value(clearPassword).build());
        Set<String> pwdResources = new HashSet<>();
        if (propByRes != null) {
            pwdResources.addAll(propByRes.get(ResourceOperation.CREATE));
        }
        if (propByLinkedAccount != null) {
            pwdResources.addAll(propByLinkedAccount.get(ResourceOperation.CREATE).stream().map(Pair::getLeft).collect(Collectors.toList()));
        }
        userUR.getPassword().getResources().addAll(pwdResources);
    }
    return new UserWorkflowResult<>(userUR, propByRes, propByLinkedAccount, postTasks);
}
Also used : Task(org.flowable.task.api.Task) 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) FlowableException(org.flowable.common.engine.api.FlowableException) UserUR(org.apache.syncope.common.lib.request.UserUR) UserWorkflowResult(org.apache.syncope.core.provisioning.api.UserWorkflowResult) HistoricVariableInstance(org.flowable.variable.api.history.HistoricVariableInstance) FlowableIllegalArgumentException(org.flowable.common.engine.api.FlowableIllegalArgumentException) Pair(org.apache.commons.lang3.tuple.Pair) HashSet(java.util.HashSet)

Aggregations

HistoricVariableInstance (org.flowable.variable.api.history.HistoricVariableInstance)3 BooleanRestVariableConverter (com.plumdo.flow.rest.variable.BooleanRestVariableConverter)1 DateRestVariableConverter (com.plumdo.flow.rest.variable.DateRestVariableConverter)1 DoubleRestVariableConverter (com.plumdo.flow.rest.variable.DoubleRestVariableConverter)1 IntegerRestVariableConverter (com.plumdo.flow.rest.variable.IntegerRestVariableConverter)1 ListRestVariableConverter (com.plumdo.flow.rest.variable.ListRestVariableConverter)1 LongRestVariableConverter (com.plumdo.flow.rest.variable.LongRestVariableConverter)1 RestVariable (com.plumdo.flow.rest.variable.RestVariable)1 RestVariableConverter (com.plumdo.flow.rest.variable.RestVariableConverter)1 ShortRestVariableConverter (com.plumdo.flow.rest.variable.ShortRestVariableConverter)1 StringRestVariableConverter (com.plumdo.flow.rest.variable.StringRestVariableConverter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Pair (org.apache.commons.lang3.tuple.Pair)1 UserUR (org.apache.syncope.common.lib.request.UserUR)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 User (org.apache.syncope.core.persistence.api.entity.user.User)1 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)1 UserWorkflowResult (org.apache.syncope.core.provisioning.api.UserWorkflowResult)1