/**
 * SetPitchScheduledStatusAction.java
 * Created on Jul 31, 2008
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.watchpoint.pmm.action.asset.distribution.mediapath;

import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

/**
 * @author Vlada Jakobac
 * 
 */
public class SetPitchScheduledStatusAction implements ActionHandler {

	private static final long serialVersionUID = 1L;

	public static String STATUS_NAME = "statusName";
	public static String STATUS_VALUE = "statusValue";
	public static String SUCCESS_VALUE = "successValue";

	public static String ASSET_DISTRIBUTION_PROPERTIES = "/template-actions/assetDistribution.properties";
	public static String DISTRIBUTION_STATUS_NAME = "asset.distribution.pitchScheduled.status.name";
	public static String DISTRIBUTION_STATUS_VALUE = "asset.distribution.pitchScheduled.status.value";
	public static String STATUS_SUCCESS_VALUE = "asset.distribution.pitchScheduled.success.value";

	private static final Logger logger = Logger
			.getLogger(SetPitchScheduledStatusAction.class);

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
	 */
	public void execute(ExecutionContext context) throws Exception {
		InputStream stream = this.getClass().getResourceAsStream(
				ASSET_DISTRIBUTION_PROPERTIES);
		Properties config = new Properties();
		config.load(stream);
		String statusName = config.getProperty(DISTRIBUTION_STATUS_NAME);
		String statusValue = config.getProperty(DISTRIBUTION_STATUS_VALUE);
		String statusSuccessValue = config.getProperty(STATUS_SUCCESS_VALUE);

		context.setVariable(STATUS_NAME, statusName);
		context.setVariable(STATUS_VALUE, statusValue);
		context.setVariable(SUCCESS_VALUE, statusSuccessValue);

		logger.debug("Set " + STATUS_NAME + " to: " + statusName + " , "
				+ STATUS_VALUE + " to: " + statusValue + " and "
				+ SUCCESS_VALUE + " to: " + statusSuccessValue);
	}

}
