/**
 * ContextDispatchAction.java
 * Created on Jul 3, 2008
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.watchpoint.pmm.web.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.tandbergtv.watchpoint.pmm.entities.ContainerType;
import com.tandbergtv.watchpoint.pmm.entities.IContainer;
import com.tandbergtv.workflow.core.service.ServiceRegistry;
import com.tandbergtv.workflow.core.service.cache.ICacheService;

/**
 * Class used to determine the proper link to a destination on the 
 * TitlesActivity page
 *  
 * @author Vlada Jakobac
 * 
 */
public class ContextDispatchAction extends DispatchAction {
	
	private static final Logger logger = Logger
		.getLogger(ContextDispatchAction.class);
	private static String CONTAINER_CACHE_SERVICE_NAME = "Container Cache";
	
	@SuppressWarnings("unchecked")
	public ActionForward forwardToPartnerOrService(ActionMapping actionMapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String contextId = request.getParameter("contextId");

		logger.debug("contextId------->" + contextId);
		
		ICacheService<IContainer> containerCache = (ICacheService<IContainer>) ServiceRegistry
				.getDefault().lookup(CONTAINER_CACHE_SERVICE_NAME);
		IContainer container = containerCache.get(Long.parseLong(contextId));
		if (container.getContainerType() == ContainerType.PARTNER){
			return actionMapping.findForward("partnerDetails");
		}
		return actionMapping.findForward("serviceDetails");
		
	}
}
