package com.tandbergtv.watchpoint.pmm.action.asset.creation;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

public class SetXportPackagerURLAction implements ActionHandler {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7061330866290897021L;

	public void execute(ExecutionContext context) throws Exception {
		
		long tokenId = context.getProcessInstance().getRootToken().getId();
		
		/* set variable for allocating specific resource */
		String name = "_resource_host_"+ new Long(tokenId).toString();
		String resourceIP = getStringValue(context, AssetCreationVariables.RESOURCE_IP.toString());
		context.setVariable(name, resourceIP);

	}
	
	/* Return the value of a process variable as a string, irrespective of the variable type */
	private String getStringValue(ExecutionContext context, String variableName) {
		Object value = context.getVariable(variableName);
		return (value == null) ? null : value.toString();
	}
}
