/**
 * InitializeVariablesAction.java
 * Created on Aug 4, 2008
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.watchpoint.pmm.action.asset.distribution.mediapath;

import java.util.Date;

import org.apache.log4j.Logger;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

import com.tandbergtv.watchpoint.pmm.util.DateUtility;

/**
 * 
 * This Action class is used by two AssetDistribution templates: Schedule Pitch and Verify Pitch 
 * @author Vlada Jakobac
 * 
 */
public class InitializeVariablesAction implements ActionHandler {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1227050921846431590L;
	private static final String MEDIAPATH_DATE_FORMAT = "MediaPath.date.format";
	private static final Logger logger = Logger.getLogger(InitializeVariablesAction.class);
	
	/* (non-Javadoc)
	 * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
	 */
	public void execute(ExecutionContext context) throws Exception {
		// set the pitchIdVariableName for the Store Info message
		context.setVariable(AssetDistributionVariables.PITCH_ID_VARIABLE_NAME
				.toString(), AssetDistributionVariables.PITCH_ID_VARIABLE_NAME
				.toString());
		context.setVariable(AssetDistributionVariables.TARBALL_LOCATION
				.toString(), AssetDistributionVariables.TARBALL_LOCATION
				.toString());
		
		/* prepare the formated pitch date for the Schedule Pitch template */
		Date pitchDate = (Date) context.getVariable(AssetDistributionVariables.PITCH_DATE.toString());	
		if (pitchDate != null && !pitchDate.equals(""))
			context.setVariable(AssetDistributionVariables.FORMATTED_PITCH_DATE.toString(), DateUtility.formatDate(pitchDate, MEDIAPATH_DATE_FORMAT));
		logger.debug("pitchDate=" + pitchDate);
	}

	
}
