001: /**
002: * Bonita
003: * Copyright (C) 1999 Bull S.A.
004: * Bull 68 route de versailles 78434 Louveciennes Cedex France
005: * Further information: bonita@objectweb.org
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
020: * USA
021: --------------------------------------------------------------------------
022: * BONITA Workflow Patterns sample
023: * Pattern 10 : Arbitrary Cycles (Extra Exit Point)
024: * Author : Jordi Anguela
025: * Date : 2006/03/01
026: --------------------------------------------------------------------------
027: * Example
028: * Classical example of approval workflow where the user request a demand
029: * to be approved for another person. If the demand is approved then
030: * processes the demand, if not, then the flow is redirect to the first
031: * user again to able to change his request.
032: --------------------------------------------------------------------------
033: */package hero.client.samples.patterns.src;
034:
035: import hero.client.test.SimpleCallbackHandler;
036: import hero.interfaces.ProjectSession;
037: import hero.interfaces.ProjectSessionHome;
038: import hero.interfaces.ProjectSessionUtil;
039:
040: import javax.security.auth.login.LoginContext;
041:
042: public class Pattern10ArbitraryCycles1ExtraExitPoint {
043:
044: public static void main(String[] args) {
045: try {
046: // User Admin login
047: char[] password = { 't', 'o', 't', 'o' };
048: SimpleCallbackHandler handler = new SimpleCallbackHandler(
049: "admin", password);
050: LoginContext lc = new LoginContext("TestClient", handler);
051: lc.login();
052:
053: // Project Session Bean creation
054: ProjectSessionHome prjHome = (ProjectSessionHome) ProjectSessionUtil
055: .getHome();
056: ProjectSession prjSession = prjHome.create();
057:
058: // Model creation
059: System.out
060: .print("\n Pattern 10 - Arbitrary Cycles (Extra Exit Point)");
061: prjSession
062: .initModel("Pattern 10 - Arbitrary Cycles (Extra Exit Point) 666");
063:
064: // Add activities and set them to Non anticipable
065: prjSession.addNode("request_demand",
066: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
067: prjSession.addNode("approve_demand",
068: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
069: prjSession.addNode("process_demand",
070: hero.interfaces.Constants.Nd.AND_JOIN_NODE);
071: prjSession.addNode("cancel_demand666",
072: hero.interfaces.Constants.Nd.OR_JOIN_NODE);
073: prjSession.setNodeTraditional("request_demand");
074: prjSession.setNodeTraditional("approve_demand");
075: prjSession.setNodeTraditional("process_demand");
076: prjSession.setNodeTraditional("cancel_demand666");
077:
078: // Add transitions between activities
079: String fromDemandToapprove_demand = prjSession.addEdge(
080: "request_demand", "approve_demand");
081: String fromDemandToCancel = prjSession.addEdge(
082: "request_demand", "cancel_demand666");
083: String fromapprove_demandToProcess = prjSession.addEdge(
084: "approve_demand", "process_demand");
085: String fromapprove_demandToCancel = prjSession.addEdge(
086: "approve_demand", "cancel_demand666");
087:
088: // Add Project Properties and set transition conditions
089: prjSession.setProperty("approved", "false");
090: prjSession.setProperty("cancel", "false");
091: prjSession.setProperty("iterations", "1");
092: prjSession.setEdgeCondition(fromDemandToapprove_demand,
093: "cancel.equals(\"false\")");
094: prjSession.setEdgeCondition(fromDemandToCancel,
095: "cancel.equals(\"true\")");
096: prjSession
097: .setEdgeCondition(fromapprove_demandToProcess,
098: "(approved.equals(\"true\") && cancel.equals(\"false\"))");
099: prjSession.setEdgeCondition(fromapprove_demandToCancel,
100: "cancel.equals(\"true\")");
101:
102: // Add iteration
103: prjSession
104: .addIteration("approve_demand", "request_demand",
105: "(approved.equals(\"false\") && cancel.equals(\"false\"))");
106:
107: // Add Hook to approve_demand activity to iterate twice and then accept the demand
108: String approve_demandHookScript = "import hero.interfaces.*;\n"
109: + "beforeStart(Object engine, Object currentNode) {\n\n\n"
110: + " hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
111: + " hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
112: + " prjSession.initModel(currentNode.getBnProject().getName()); \n"
113: + " BnProjectPropertyValue propIterations = prjSession.getProperty(\"iterations\"); \n"
114: + " int it= Integer.parseInt(propIterations.getTheValue()); \n"
115: + " if ( it > 0 ) { \n"
116: + " it--; \n"
117: + " prjSession.setProperty(\"iterations\", Integer.toString(it)); \n"
118: + " } else { \n "
119: + " prjSession.setProperty(\"approved\", \"true\"); \n"
120: + " } \n" + "}";
121: prjSession.addNodeInterHook("approve_demand",
122: "approve_demand Hook",
123: hero.interfaces.Constants.Nd.BEFORESTART,
124: hero.interfaces.Constants.Hook.BSINTERACTIVE,
125: approve_demandHookScript);
126:
127: // Add and set a role for the user admin to execute the activities
128: prjSession.addRole("Executor",
129: "Rol that enables to execute the activities");
130: prjSession.setUserRole("admin", "Executor");
131: prjSession.setNodeRole("request_demand", "Executor");
132: prjSession.setNodeRole("approve_demand", "Executor");
133: prjSession.setNodeRole("process_demand", "Executor");
134: prjSession.setNodeRole("cancel_demand666", "Executor");
135:
136: // Check model definition
137: prjSession.checkModelDefinition();
138:
139: System.out.println(" [ OK ]");
140: } catch (Exception e) {
141: System.out.println("\n\n [ ERROR ] : " + e);
142: e.printStackTrace();
143: } // Maybe something is wrong
144: }
145: }
|