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

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

package com.xlrit.gears.engine.facade;

import java.util.Objects;

import org.flowable.common.engine.api.FlowableIllegalStateException;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.runtime.Clock;
import org.flowable.common.engine.api.FlowableTaskAlreadyClaimedException;
import org.flowable.engine.impl.cmd.NeedsActiveTaskCmd;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.TaskHelper;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

public class TransferTaskCmd extends NeedsActiveTaskCmd {

	private final String currentAssignee;
	private final String newAssignee;

	public TransferTaskCmd(String taskId, String currentAssignee, String newAssignee) {
		super(taskId);
		this.currentAssignee = Objects.requireNonNull(currentAssignee);
		this.newAssignee = Objects.requireNonNull(newAssignee);
	}

	@Override
	protected Void execute(CommandContext commandContext, TaskEntity task) {
		if (task.getAssignee() == null) {
			throw new FlowableIllegalStateException("Task " + task.getId() + " is not currently assigned");
		}
		if (!task.getAssignee().equals(currentAssignee)) {
			// When the task is claimed by an unexpected user, throw exception.
			throw new FlowableTaskAlreadyClaimedException(task.getId(), task.getAssignee());
		}

		Clock clock = CommandContextUtil.getProcessEngineConfiguration(commandContext).getClock();
		task.setClaimTime(clock.getCurrentTime());

		TaskHelper.changeTaskAssignee(task, newAssignee);

		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy