Package org.apache.agila.impl.servlet

Source Code of org.apache.agila.impl.servlet.AgilaServlet

/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.agila.impl.servlet;

import org.apache.velocity.VelocityContext;
import org.apache.agila.services.TokenService;
import org.apache.agila.services.user.UserID;
import org.apache.agila.services.task.TaskService;
import org.apache.agila.services.task.Task;
import org.apache.agila.services.task.TaskID;
import org.apache.agila.engine.MessageProcessor;
import org.apache.agila.impl.QueueServiceImpl;
import org.apache.agila.impl.memory.InstanceServiceImpl;
import org.apache.agila.impl.memory.BusinessProcessServiceImpl;
import org.apache.agila.impl.memory.TimerServiceImpl;
import org.apache.agila.impl.memory.TokenServiceImpl;
import org.apache.agila.impl.memory.TaskServiceImpl;
import org.apache.agila.engine.Engine;
import org.apache.agila.engine.InstanceID;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.Reader;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.List;
import java.util.HashMap;

/**
*  Simple servlet to demo the core workflow engine.  This is somewhat
*  deprecated at this point.  Use the one in the web package.
*
* @author <a href="mailto:geir@gluecode.com">Geir Magnusson Jr.</a>
* @version $Id: AgilaServlet.java 38 2005-06-01 19:39:54Z chirino $
*/
public class AgilaServlet extends VelocityActionServlet {

    private TokenService tokenService = null;
    private InstanceServiceImpl eiSvc = null;
    private BusinessProcessServiceImpl graphManager = null;
    private TaskService taskService = null;
    private TimerServiceImpl timerService = null;
    private MessageProcessor impl = null;
    private QueueServiceImpl qs = null;
    private Engine engine = null;

    public void init()
        throws ServletException {

        super.init();

        this.tokenService = new TokenServiceImpl();
        this.eiSvc = new InstanceServiceImpl();
        this.graphManager = new BusinessProcessServiceImpl();
        this.taskService = new TaskServiceImpl();
        this.timerService = new TimerServiceImpl();

        this.impl = new MessageProcessor();

        this.impl.setTaskService(taskService);
        this.impl.setTimerService(timerService);
        this.impl.setExecutionInstanceService(eiSvc);
        this.impl.setTokenService(tokenService);
        this.impl.setBusinessProcessService(graphManager);

        this.qs = new QueueServiceImpl(impl);

        timerService.setQueueService(qs);

        impl.setQueueService(qs);

        eiSvc.setBusinessProcessService(graphManager);
        eiSvc.setQueueService(qs);
        eiSvc.setTokenService(tokenService);

        /*
         * now start the message pump for processing since we are all ready
         */

        qs.start();

        engine = new Engine(tokenService, eiSvc, graphManager, qs);

        Reader reader = new InputStreamReader(
                getClass().getClassLoader().getResourceAsStream("org/apache/agila/workflow_simple.xml"));

        engine.addBusinessProcess( reader );
    }

    /**
     * Return the root of template path.  Note that this should not include
     * the bit returned by getTemplatePathPrefix().
     */
    public String getTemplateRoot() {
        return "/";
    }

    /**
     * Abstract method to be implemented by children, called when
     * there is no action specified
     *
     * @param req
     * @param res
     * @throws javax.servlet.ServletException
     * @throws java.io.IOException
     */
    public void defaultAction(HttpServletRequest req, HttpServletResponse res, VelocityContext ctx) throws ServletException, IOException {

        renderTemplate(req, res, ctx, "index.vm");
    }

    public void upload_submit(HttpServletRequest req, HttpServletResponse res, VelocityContext ctx)
        throws ServletException, IOException {

        String xml = req.getParameter("xml");

        System.out.println("upload_submit : " + xml);

        engine.addBusinessProcess( new StringReader( xml ) );

        show_process_list(req,res,ctx);
    }

    public void upload_process(HttpServletRequest req, HttpServletResponse res, VelocityContext ctx)
            throws ServletException, IOException {

        renderTemplate(req, res, ctx, "uploadprocess.vm");

    }


    public void show_process_list(HttpServletRequest req, HttpServletResponse res, VelocityContext ctx) throws ServletException, IOException {

        List l = graphManager.getCurrentProcessInfos();

        ctx.put("list", l);

        renderTemplate(req, res, ctx, "processlist.vm");
    }

    public void show_task_list(HttpServletRequest req, HttpServletResponse res, VelocityContext ctx) throws ServletException, IOException {

        List l = taskService.getTasksForUser(new UserID(1), Task.TASK_ALL);

        ctx.put("list", l);

        renderTemplate(req, res, ctx, "tasklist.vm");

    }



    public void show_instance_list(HttpServletRequest req, HttpServletResponse res, VelocityContext ctx) throws ServletException, IOException {

        List l = eiSvc.listInstanceInfo();

        ctx.put("list", l);
        ctx.put("tokenService", tokenService);
        ctx.put("graphManager", graphManager);

        renderTemplate(req, res, ctx, "instancelist.vm");
    }

    public void start_process_instance(HttpServletRequest req, HttpServletResponse res, VelocityContext ctx) throws ServletException, IOException {

        InstanceID id = engine.startNewInstance(1, new HashMap());

        ctx.put("iid", id);

        renderTemplate(req, res, ctx, "startedprocess.vm");
    }

    public void nudge_from_task(HttpServletRequest req, HttpServletResponse res, VelocityContext ctx) throws ServletException, IOException {

        Task t = taskService.getTaskByID(new TaskID(Integer.parseInt(req.getParameter("taskid"))));

        engine.nudge(t.getSourceTokenID());

        taskService.setTaskStatus(t.getTaskID(), Task.TASK_INCOMPLETE);
        show_task_list(req,res, ctx);
    }

    /**
     * Abstract method to be implemented by children, calle when
     * the action specified is not found
     *
     * @param req
     * @param res
     * @throws javax.servlet.ServletException
     * @throws java.io.IOException
     */
    public void unknownAction(HttpServletRequest req, HttpServletResponse res, VelocityContext ctx) throws ServletException, IOException {

    }
}
TOP

Related Classes of org.apache.agila.impl.servlet.AgilaServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.