/**
 * 
 */
package com.tandbergtv.watchpoint.cms.action;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

import com.tandbergtv.watchpoint.cms.util.TemplateProperties;

/**
 * Persists the value of the variable containing the Allocated Resource for the current Token to a
 * different variable for the Token.
 * 
 * @author esatdha
 */
public class GetUser implements ActionHandler {

	/* Serialization UID */
	private static final long serialVersionUID = 7471577048158647411L;

	/* Property containing the allocated resource variable name */
	private static final String ALLOCATED_RESOURCE_VARIABLE = "General.AllocatedResourceVariable";

	/**
	 * Get the value of the '_allocated_resource' variable persisted by the framework and store in a
	 * specified process variable
	 * 
	 * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
	 */
	public void execute(ExecutionContext context) throws ActionException
	{
		String resourceVariableName = TemplateProperties.getString(ALLOCATED_RESOURCE_VARIABLE);
		resourceVariableName += context.getToken().getId();
		Object value = context.getVariable(resourceVariableName);
		context.setVariable("metadataMapUser", value);
	}
}