/**
 * Copyright 1996-2014 FoxBPM ORG.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * @author kenshin
 */
package org.foxbpm.engine.impl.task.cmd;
import org.foxbpm.engine.impl.Context;
import org.foxbpm.engine.impl.entity.TaskEntity;
import org.foxbpm.engine.impl.identity.Authentication;
import org.foxbpm.engine.impl.interceptor.CommandContext;
import org.foxbpm.engine.impl.task.command.TransferTaskCommand;
import org.foxbpm.engine.impl.util.ClockUtil;
import org.foxbpm.engine.impl.util.GuidUtil;
import org.foxbpm.engine.task.TaskCommand;
import org.foxbpm.kernel.runtime.FlowNodeExecutionContext;

/**
 * @author kenshin
 *
 */
public class TransferTaskCmd extends AbstractExpandTaskCmd<TransferTaskCommand, Void> {

	private static final long serialVersionUID = 1L;

	/**
	 * 转发的用户编号
	 */
	protected String transferUserId;

	public TransferTaskCmd(TransferTaskCommand transferTaskCommand) {

		super(transferTaskCommand);
		this.transferUserId = transferTaskCommand.getTransferUserId();

	}

	@Override
	protected Void execute(CommandContext commandContext, TaskEntity task) {
		

		
		/** 放置流程实例级别的瞬态变量 */
		task.setProcessInstanceTransientVariables(this.transientVariables);
		/** 获取任务命令 */
		TaskCommand taskCommand = getTaskCommand(task);
		/** 获取流程内容执行器 */
		FlowNodeExecutionContext executionContext = getExecutionContext(task);
		/** 任务命令的执行表达式变量 */
		taskCommand.getExpressionValue(executionContext);
		/** 设置任务处理者 */
		task.setAssignee(Authentication.getAuthenticatedUserId());
		/** 设置任务的处理命令 commandId commandName commandType */
		task.setTaskCommand(taskCommand);		
		/** 处理意见 */
		task.setTaskComment(taskComment);
		/** 结束任务,但是并不驱动流程向下。 */
		task.end(taskCommand, taskComment);
		
		/** 创建新任务 */
		
		/** 克隆一个任务 */
		TaskEntity newTask=(TaskEntity) task.clone();
		/** 重置任务字段 */
		newTask.setId(GuidUtil.CreateGuid());
		newTask.setAssignee(transferUserId);
		newTask.setCreateTime(ClockUtil.getCurrentTime());
		newTask.setEndTime(null);
		newTask.setCommandId(null);
		newTask.setCommandType(null);
		newTask.setCommandMessage(null);
		newTask.setTaskComment(null);
		newTask.setAgent(null);
		newTask.setAdmin(null);
		newTask.setDraft(false);
		newTask.setOpen(false);
		newTask.setSuspended(false);
		/** 插入任务 */
		Context.getCommandContext().getTaskManager().insert(newTask);
		
		
		return null;
	}

}

@@ -2221,20 +2221,192 @@
 ;%0A%09%09
-%0A%09%09
 /** 
+%E5%88%9B%E5%BB%BA%E6%96%B0%E4%BB%BB%E5%8A%A1 */%09%0A%09%09cloneAndInsertTask(task);%0A%09%09%0A%09%09return null;%0A%09%7D%0A%09%0A%09%0A%09private void cloneAndInsertTask(TaskEntity task)%7B%0A%09%09%0A%09%09/** %E8%BF%99%E9%87%8C%E5%8F%AF%E4%BB%A5%E9%87%87%E7%94%A8%E6%B5%85%E5%85%8B%E9%9A%86%E7%9A%84%E6%96%B9%E5%BC%8F%E5%85%8B%E9%9A%86%E5%87%BA%E4%B8%80%E4%B8%AA%E5%8D%95%E7%AE%80%E5%8D%95%E5%AD%97%E6%AE%B5%E7%9A%84%E4%BB%BB%E5%8A%A1,%E4%B9%9F%E5%8F%AF%E4%BB%A5%E8%87%AA%E5%B7%B1%E9%87%8D%E6%96%B0
 %E5%88%9B%E5%BB%BA
-%E6%96%B0
 %E4%BB%BB%E5%8A%A1
+,%E4%BD%86%E6%98%AF%E9%9C%80%E8%A6%81%E8%B5%8B%E5%80%BC%E4%BB%A4%E7%89%8C%E3%80%81%E6%B5%81%E7%A8%8B%E5%AE%9E%E4%BE%8B%E3%80%81%E5%AE%9A%E4%B9%89%E7%AD%89%E4%BF%A1%E6%81%AF
  */%0A
@@ -2524,24 +2524,46 @@
 ateGuid());%0A
+%09%09/** %E8%AE%BE%E7%BD%AE%E6%96%B0%E7%9A%84%E5%A4%84%E7%90%86%E8%80%85%E4%B8%BA%E8%A2%AB%E8%BD%AC%E5%8F%91%E4%BA%BA */%0A
 %09%09newTask.se
@@ -2589,16 +2589,32 @@
 serId);%0A
+%09%09/** %E9%87%8D%E7%BD%AE%E5%88%9B%E5%BB%BA%E6%97%B6%E9%97%B4 */%0A
 %09%09newTas
@@ -3033,29 +3033,8 @@
 k);%0A
-%09%09%0A%09%09%0A%09%09return null;%0A
 %09%7D%0A%0A

优化了 退回-重置 任务命令的 cmd