incubator-jspwiki-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Janne Jalkanen <Janne.Jalka...@ecyrd.com>
Subject Re: workflows - examples?
Date Wed, 17 Sep 2008 17:05:49 GMT
Very nice, thanks!

Could you post this somewhere on jspwiki.org as well?

/Janne

On 17 Sep 2008, at 19:46, Louis.Masters@log-net.com wrote:

> OK, I took Andrew's suggestion and looked at UserManager.  I  
> combined some
> of that code with the javadoc example in the WorkFlow.java source  
> and came
> up with the following very simple but working example.  It sends an  
> email,
> waits for a member of the Admins group to make a decision and then  
> sends
> another email (I said it was very basic).  It's pretty easy once  
> you see
> it and I thought I would post in case anyone else was wondering about
> workflows.
>
>
>
> package com.lognet.wiki.plugin;
>
> import java.util.*;
> import java.io.*;
> import java.sql.*;
>
> import java.security.Principal;
>
> import com.ecyrd.jspwiki.*;
>
> import  com.ecyrd.jspwiki.auth.user.*;
> import com.ecyrd.jspwiki.workflow.*;
> import com.ecyrd.jspwiki.util.MailUtil;
> import com.ecyrd.jspwiki.auth.GroupPrincipal;
> import com.ecyrd.jspwiki.auth.permissions.AllPermission;
> import com.ecyrd.jspwiki.auth.permissions.WikiPermission;
> import com.ecyrd.jspwiki.auth.user.AbstractUserDatabase;
> import com.ecyrd.jspwiki.auth.user.DuplicateUserException;
> import com.ecyrd.jspwiki.auth.user.UserDatabase;
> import com.ecyrd.jspwiki.auth.user.UserProfile;
> import com.ecyrd.jspwiki.event.WikiEventListener;
> import com.ecyrd.jspwiki.event.WikiEventManager;
> import com.ecyrd.jspwiki.event.WikiSecurityEvent;
> import com.ecyrd.jspwiki.filters.PageFilter;
> import com.ecyrd.jspwiki.filters.SpamFilter;
> import com.ecyrd.jspwiki.i18n.InternationalizationManager;
> import com.ecyrd.jspwiki.rpc.RPCCallable;
> import com.ecyrd.jspwiki.rpc.json.JSONRPCManager;
> import com.ecyrd.jspwiki.ui.InputValidator;
> import com.ecyrd.jspwiki.util.ClassUtil;
>
>
> public class WorkFlowTestPlugin extends LNWikiAncestor    // 
> LNWikiAncestor
> is just a wrapper for WikiPlugin
> {
>         private WikiEngine m_engine;
>         private WikiSession session;
>
>
>
>         public String execPayload(WikiContext context, Map p) throws
> Exception
>         {
>                 m_engine = context.getEngine();
>
>                 Workflow workflow = new Workflow("TestWorkFlow",
> context.getCurrentUser());
>                 Step initTask = new InitTask(m_engine);
>                 Step finishTask = new FinishTask(m_engine);
>                 Principal actor = new GroupPrincipal("Admins");
>                 Decision decision = new SimpleDecision(workflow,
> "decision.AdminDecision", actor);
>                 Fact aFact = new Fact( "Request Number", "123456");
>                 decision.addFact(aFact);
>                 initTask.addSuccessor(Outcome.STEP_COMPLETE,  
> decision);
>                 decision.addSuccessor(Outcome.DECISION_APPROVE,
> finishTask);
>                 workflow.setFirstStep(initTask);
>                 m_engine.getWorkflowManager().start(workflow);
>
>
>                 return "OK";
>         }
>
>         public static class InitTask extends Task
>         {
>                 private final WikiEngine m_engine;
>
>                 public InitTask( WikiEngine engine )
>                 {
>                         super( "task.sendEmail" );
>                         m_engine = engine;
>                 }
>
>                 public Outcome execute() throws WikiException
>                 {
>                         try{
>                                 MailUtil.sendMessage( m_engine,
> "xax@fff.com", "WFTEST", "This is an init test from the workflow");
>                         }
>                         catch (Exception e)
>                         {
>                                 throw new WikiException("Could not  
> execute
> task");
>                         }
>
>                         return Outcome.STEP_COMPLETE;
>                 }
>         }
>         public static class FinishTask extends Task
>         {
>                 private final WikiEngine m_engine;
>
>                 public FinishTask( WikiEngine engine )
>                 {
>                         super( "task.sendEmail" );
>                         m_engine = engine;
>                 }
>
>                 public Outcome execute() throws WikiException
>                 {
>                         try{
>                                 MailUtil.sendMessage( m_engine,
> "aaa@bbb.com", "WFTEST", "This is a finish test from the workflow");
>                         }
>                         catch (Exception e)
>                         {
>                                 throw new WikiException("Could not  
> execute
> task");
>                         }
>
>                         return Outcome.STEP_COMPLETE;
>                 }
>         }
> }
>
>
>
>
>
> Andrew Jaquith <andrew.jaquith@me.com>
> 09/16/2008 03:20 PM
> Please respond to
> jspwiki-user@incubator.apache.org
>
>
> To
> "jspwiki-user@incubator.apache.org" <jspwiki- 
> user@incubator.apache.org>
> cc
>
> Subject
> Re: workflows - examples?
>
>
>
>
>
>
> Louis, Bob--
>
> Probably the best example is in the PageManager code; we use the
> workflow service to route page-save operations if approval is
> required. UserManager also creates workflows if approval is required
> for new wiki accounts.
>
> Andrew
>
> On Sep 16, 2008, at 13:15, Bob Paige <bobpaige@gmail.com> wrote:
>
>> I posted the same question some months ago. I hope to see an answer
>> this
>> time as this could be a useful feature for me.
>>
>> -- 
>> Bobman
>>
>> On Tue, Sep 16, 2008 at 11:27 AM, <Louis.Masters@log-net.com> wrote:
>>
>>> Does anyone have any example code for setting up or using
>>> workflows?  I
>>> see the java classes and the workflow tab, but I can't seem to
>>> figure out
>>> how to interact with them.
>>>
>


Mime
View raw message