1 29 30 package hero.client.samples; 31 32 import javax.security.auth.login.LoginContext ; 33 import hero.client.test.SimpleCallbackHandler; 34 35 import hero.interfaces.ProjectSession; 36 import hero.interfaces.ProjectSessionHome; 37 import hero.interfaces.ProjectSessionUtil; 38 39 import hero.interfaces.Constants; 40 41 42 public class Sample1CreateProcessModel { 43 44 static public void main(String [] args) throws Exception { 45 char[] password={'t','o','t','o'}; 47 SimpleCallbackHandler handler = new SimpleCallbackHandler("admin",password); 48 LoginContext lc = new LoginContext ("TestClient", handler); 49 lc.login(); 50 51 53 ProjectSessionHome prjHome= (ProjectSessionHome) ProjectSessionUtil.getHome(); 55 ProjectSession prjSession = prjHome.create(); 56 57 59 prjSession.initModel("Order Processing"); 60 61 64 prjSession.addNode("Receive Order",Constants.Nd.AND_JOIN_NODE); 66 prjSession.setNodeTraditional("Receive Order"); 67 68 prjSession.setNodeProperty("Receive Order","once_more","OK",true); 70 prjSession.setNodeProperty("Receive Order","customer_name","",true); 71 prjSession.setNodeProperty("Receive Order","product_name","",true); 72 prjSession.setNodeProperty("Receive Order","items","",true); 73 74 prjSession.addNode("Check Stock",Constants.Nd.AND_JOIN_AUTOMATIC_NODE ); 76 prjSession.setNodeTraditional("Check Stock"); 77 78 79 prjSession.addEdge("Receive Order","Check Stock"); 81 82 String scriptHook = 85 "import hero.interfaces.*;\n" 86 + "import hero.interfaces.BnNodeLocal;\n" 87 + "beforeTerminate (Object b,Object n) {\n" 88 + "hero.interfaces.ProjectSessionLocalHome pHome = (hero.interfaces.ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome(); \n" 89 + "hero.interfaces.ProjectSessionLocal subProcess = pHome.create(); \n" 90 + "subProcess.initModel(n.getBnProject().getName()); \n" 91 + "if (customer_name != null && product_name != null && items != null) \n" 92 + "{ System.out.println(\"(Order Processing : Check Stock) Stock Status = OK\"); \n" 93 + " subProcess.setNodeProperty(n.getName(), \"stock_status\",\"ok\",true);\n " 94 + " }\n" 95 + " else \n" 96 + "{ System.out.println(\"(Order Processing : Check Stock) Stock Status = NOK\");\n " 97 + "subProcess.setNodeProperty(n.getName(), \"stock_status\",\"nok\",true); \n" 98 + " }\n" 99 + "}"; 100 101 prjSession.addNodeInterHook("Check Stock","Check Stock Hook",Constants.Nd.BEFORETERMINATE,Constants.Hook.BSINTERACTIVE,scriptHook); 102 103 prjSession.addNodeSubProcess("Accept Order","Customer Service"); 105 106 String edgeStockOrder = prjSession.addEdge("Check Stock","Accept Order"); 109 String condition = "stock_status.equals(\"ok\")"; 110 prjSession.setEdgeCondition(edgeStockOrder,condition); 111 112 prjSession.addNode("Ship & Report",Constants.Nd.AND_JOIN_AUTOMATIC_NODE ); 115 prjSession.setNodeTraditional("Ship & Report"); 116 117 String scriptHookSR = 120 "import hero.interfaces.*;\n" 121 + "import hero.interfaces.BnNodeLocal;\n" 122 + "beforeTerminate (Object b,Object n) {\n" 123 + "hero.interfaces.ProjectSessionLocalHome pHome = (hero.interfaces.ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome(); \n" 124 + "hero.interfaces.ProjectSessionLocal subProcess = pHome.create(); \n" 125 + "subProcess.initModel(n.getBnProject().getName()); \n" 126 + "System.out.println(\"(Order Processing : Ship & Report) That's OK\"); \n" 127 + "}" ; 128 129 prjSession.addNodeInterHook("Ship & Report","Ship Report Hook",Constants.Nd.BEFORETERMINATE,Constants.Hook.BSINTERACTIVE,scriptHookSR); 130 131 132 String edgeOrderReport = prjSession.addEdge("Accept Order","Ship & Report"); 133 String condition1 = "partial_sales_status.equals(\"ok\")"; 134 prjSession.setEdgeCondition(edgeOrderReport,condition1); 135 136 prjSession.addNode("Cancel Order",Constants.Nd.AND_JOIN_AUTOMATIC_NODE ); 138 prjSession.setNodeTraditional("Cancel Order"); 139 140 String scriptHookCO = 143 "import hero.interfaces.*;\n" 144 + "import hero.interfaces.BnNodeLocal;\n" 145 + "beforeTerminate (Object b,Object n) {\n" 146 + "hero.interfaces.ProjectSessionLocalHome pHome = (hero.interfaces.ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome(); \n" 147 + "hero.interfaces.ProjectSessionLocal subProcess = pHome.create(); \n" 148 + "subProcess.initModel(n.getBnProject().getName()); \n" 149 + "System.out.println(\"(Order Processing : Cancel Order) That's NOT OK\"); \n" 150 + "}" ; 151 152 prjSession.addNodeInterHook("Cancel Order","Cancel Order Hook",Constants.Nd.BEFORETERMINATE,Constants.Hook.BSINTERACTIVE,scriptHookCO); 153 154 155 156 157 158 String edgeOrderCancel = prjSession.addEdge("Accept Order","Cancel Order"); 159 String condition2 = "partial_sales_status.equals(\"nok\")"; 160 prjSession.setEdgeCondition(edgeOrderCancel,condition2); 161 162 prjSession.addRole("agent","Customer Service agent"); 164 prjSession.addRole("customer","Sales order customer"); 165 166 prjSession.setNodeRole("Accept Order","agent"); 168 prjSession.setNodeRole("Check Stock","agent"); 169 prjSession.setNodeRole("Ship & Report","agent"); 170 prjSession.setNodeRole("Cancel Order","agent"); 171 prjSession.setNodeRole("Receive Order","customer"); 172 173 174 String iterCondition="once_more.equals(\"OK\")" ; 179 prjSession.addIteration("Ship & Report","Receive Order",iterCondition); 180 } 181 182 183 } 184 185 186 | Popular Tags |