/*
 * $Id: VisualizeProcessAction.java,v 1.3 2005/07/26 23:05:46 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * Created on 09.07.2004
 *
 * $Log: VisualizeProcessAction.java,v $
 * Revision 1.3  2005/07/26 23:05:46  marbobo
 * + Alle bekannte Probleme mit IE behoben
 *
 * Revision 1.2  2004/09/20 10:26:13  koppy
 * +javadoc Dokumentation
 *
 * Revision 1.1  2004/08/30 14:49:56  koppy
 * Initiale Version der Workflow-Komponente
 *
 */
package vkc.workflow.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import vkc.db.entities.VKCUser;
import vkc.util.ServletUtils;
import vkc.workflow.WorkflowServiceFactory;
import vkc.workflow.service.VKCWorkflowService;

/**
 * This struts action class is used
 * to visualize a process (definition).
 * <p>
 * It generates a JPG and outputs it to the Browser.
 * 
 * @author Andreas Koop
 */
public class VisualizeProcessAction extends Action {


    
    /** 
     * (non-Javadoc)
     * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        VKCUser 		user 			= ServletUtils.getUser( request );
        VKCWorkflowService wfService 		= WorkflowServiceFactory.getWorkflowService();
        
        response.setContentType( "image/jpeg" );
        if( request.getParameter( "procId" ) != null ){
            wfService.writeProcessGraph( user.getUser(), user.getClearPassword(),
                    request.getParameter( "procId" ), response.getOutputStream() );    
        }else if( request.getParameter( "procDefId" ) != null
                	&& request.getParameter( "pkgId" ) != null){
            wfService.writeProcessDefGraph( user.getUser(), user.getClearPassword(),
                    request.getParameter( "pkgId" ),
                    request.getParameter( "procDefId" ), response.getOutputStream() );    
        }
        
        
        return null;
    }
}
