All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xlrit.gears.engine.facade.LockTaskCmd Maven / Gradle / Ivy

package com.xlrit.gears.engine.facade;

import com.fasterxml.jackson.databind.JsonNode;
import com.xlrit.gears.base.exception.AuthException;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.cmd.NeedsActiveTaskCmd;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

class LockTaskCmd extends NeedsActiveTaskCmd {
    private static final Logger LOG = LoggerFactory.getLogger(LockTaskCmd.class);

    private final String userId;
    private final JsonNode formValues;

    public LockTaskCmd(String taskId, String userId, JsonNode formValues) {
        super(taskId);
        this.userId = Objects.requireNonNull(userId);
        this.formValues = formValues;
    }

    @Override
    protected String execute(CommandContext commandContext, TaskEntity task) {
        LOG.debug("Attempting to lock task {} for user {}", taskId, userId);
        if (task.getAssignee() != null && !task.getAssignee().equals(userId)) {
            throw new AuthException("Task is assigned to another user: " + task.getAssignee()); // TODO wel toestaan als user admin is?
        }
        if (task.getOwner() != null) {
            throw new AuthException("Task is already locked for " + task.getOwner());
        }
        task.setOwner(userId);
        task.setVariableLocal(EngineFacade.TASK_VAR_SAVED_VALUES, formValues);
        task.setVariableLocal(EngineFacade.TASK_VAR_ERROR, null); // clear previous error
        return task.getProcessInstanceId();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy