/*
 * Created on Jun 25, 2008 (C) Copyright TANDBERG Television Ltd.
 */

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;

/**
 * @author Sathiya Dhanapal
 */
public class SetUser implements ActionHandler {

	/* Serialization Id */
	private static final long serialVersionUID = -8283045339910414982L;

	/* The Property for the variable name to use when assigning a specific resource */
	private static final String ASSIGNED_RESOURCE_VARIABLE = "General.AssignResourceVariable";

	/**
	 * Set the Resource Host variable
	 * 
	 * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
	 */
	public void execute(ExecutionContext context) throws ActionException
	{
		/* Check the variable first, and then check the constant value */
		Object value = context.getVariable("metadataMapUser");

		if (value != null)
		{
			String resourceHost = value.toString();
			if(resourceHost.trim().length() != 0)
			{
				String variableName = TemplateProperties.getString(ASSIGNED_RESOURCE_VARIABLE);
				variableName += context.getToken().getId();
				context.setVariable(variableName, resourceHost);				
			}
		}
	}
}
