1 package hero.util; 2 3 23 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.Arrays ; 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 30 import org.apache.axis.client.Service; 31 32 import hero.interfaces.Constants; 33 34 import org.apache.axis.client.Stub; 35 36 import hero.net.UserSession.UserSession; 37 import hero.net.UserSession.UserSessionService; 38 import hero.net.UserSession.UserSessionServiceLocator; 39 40 import hero.net.ProjectSession.ProjectSession; 41 import hero.net.ProjectSession.ProjectSessionService; 42 import hero.net.ProjectSession.ProjectSessionServiceLocator; 43 44 45 public class BonitaClient { 46 private final String userSession = "UserSession"; 48 private final String projectSession = "ProjectSession"; 49 50 private ProjectSession projectSessionClient; 52 private UserSession userSessionClient; 53 54 private String host; 56 private int port; 57 private String baseUrl = "/bonita_ws/services/"; 58 59 private String userName = null; 61 private String userPassword = null; 62 63 private Service service; 65 private URL defaultUri; 66 private URL userUri; 67 private URL projectUri; 68 70 private String currentProject; 72 private boolean permission = false; 73 74 private void createUserSoapCall() throws Exception { 76 Stub stub = ((Stub) userSessionClient); 77 stub.setUsername(this.userName); 78 stub.setPassword(this.userPassword); 79 } 80 private void createProjectSoapCall() throws Exception { 81 Stub stub = ((Stub) projectSessionClient); 82 stub.setUsername(this.userName); 83 stub.setPassword(this.userPassword); 84 stub.setMaintainSession(true); 85 } 86 87 public void login(String user, String pass) throws Exception { 89 this.userName = user; 90 this.userPassword = pass; 91 92 UserSessionService serviceUS = new UserSessionServiceLocator(); 93 userSessionClient = serviceUS.getUserSession(userUri); 94 95 ProjectSessionService servicePSS = new ProjectSessionServiceLocator(); 96 projectSessionClient = servicePSS.getProjectSession(projectUri); 97 98 this.createUserSoapCall(); 99 this.createProjectSoapCall(); 100 } 101 public String getUser() throws Exception { 102 return (this.userName); 103 } 104 public String getProjectName() { 105 return this.currentProject; 106 } 107 public boolean hasPermission() { 108 return permission; 109 } 110 111 113 public BonitaClient(String host, int port, String urlBase) throws Exception { 114 this.host = host; 115 this.port = port; 116 this.baseUrl = urlBase; 117 userUri = new URL ("http://" + host + ":" + port + baseUrl + userSession); 119 projectUri = new URL ("http://" + host + ":" + port + baseUrl + projectSession); 120 } 121 122 124 public void initProject(String managerProject) throws Exception { 125 this.currentProject = managerProject; 126 projectSessionClient.initProject(currentProject); 127 128 permission = isInRole(userName, "admin"); 130 } 131 132 public void initModel(String managerProject) throws Exception { 133 this.currentProject = managerProject; 134 projectSessionClient.initModel(currentProject); 135 136 permission = isInRole(userName, "admin"); 138 } 139 140 public void initProject(String src, String dest) throws Exception { 141 this.login(this.userName,this.userPassword); 142 projectSessionClient.initProject(src,dest); 143 this.currentProject = dest; 145 } 146 147 public void instantiateProject(String src) throws Exception { 148 this.login(this.userName,this.userPassword); 149 projectSessionClient.instantiateProject(src); 150 } 151 152 public boolean openProject(String projectName) throws Exception { 153 initProject(projectName); 154 return true; 155 } 156 public boolean createProject(String projectName) throws Exception { 157 if (exists(projectName)) { 158 return false; 159 } 160 initProject(projectName); 161 return true; 162 } 163 164 public boolean createModel(String modelName) throws Exception { 165 if (exists(modelName)) { 166 return false; 167 } 168 initModel(modelName); 169 return true; 170 } 171 172 public boolean cloneProject(String projectSrc, String projectDest) throws Exception { 173 if (exists(projectDest)) { 174 return false; 175 } 176 initProject(projectSrc, projectDest); 177 return true; 178 } 179 180 private boolean exists(String name) throws Exception { 181 Collection projects = getProjects(); 182 Iterator i = projects.iterator(); 183 while (i.hasNext()) { 184 String prj = (String ) i.next(); 185 if (prj.equalsIgnoreCase(name)) { 186 return true; 187 } 188 } 189 return false; 190 } 191 192 public Collection getProjects() throws Exception { 193 ArrayList result = new ArrayList (); 194 Object [] projects = userSessionClient.getProjectListNames(); 195 Iterator i = ((java.util.List ) Arrays.asList(projects)).iterator(); 196 while (i.hasNext()) { 197 result.add(i.next()); 198 } 199 return result; 200 } 201 202 public Collection getProjectsList() throws Exception { 203 ArrayList result = new ArrayList (); 204 Object [] projects = userSessionClient.getProjectList(); 205 Iterator i = ((java.util.List ) Arrays.asList(projects)).iterator(); 206 while (i.hasNext()) { 207 result.add((hero.net.UserSession.BnProjectLightValue)i.next()); 208 } 209 return result; 210 } 211 212 public Collection getProjectInstances(String projectName) throws Exception { 213 ArrayList result = new ArrayList (); 214 Object [] instances = userSessionClient.getProjectInstancesNames(projectName); 215 Iterator i = ((java.util.List ) Arrays.asList(instances)).iterator(); 216 while (i.hasNext()) { 217 result.add(i.next()); 218 } 219 return result; 220 } 221 222 public Collection getInstances() throws Exception { 223 ArrayList result = new ArrayList (); 224 Object [] instances = userSessionClient.getInstancesListNames(); 225 Iterator i = ((java.util.List ) Arrays.asList(instances)).iterator(); 226 while (i.hasNext()) { 227 result.add(i.next()); 228 } 229 return result; 230 } 231 232 public boolean containsNode(String value) throws Exception { 233 Collection nodes = getNodes(); 234 235 Iterator i = nodes.iterator(); 236 while (i.hasNext()) { 237 String nodeName = (String ) i.next(); 238 if (value.equalsIgnoreCase(nodeName)) { 239 return true; 240 } 241 } 242 return false; 243 } 244 245 public String getType() throws Exception { 246 return (projectSessionClient.getType()); 247 } 248 249 public String getStatus() throws Exception { 250 return (projectSessionClient.getStatus()); 251 } 252 253 public void setStatus(String status) throws Exception { 254 if (status.equals(Constants.Pj.ACTIVE)) 255 projectSessionClient.activeProcess(); 256 else 257 projectSessionClient.hideProcess(); 258 } 259 260 261 public Collection getNodes() throws Exception { 262 ArrayList result = new ArrayList (); 263 Object [] nodes = projectSessionClient.getNodesNames(); 264 Iterator i = ((java.util.List ) Arrays.asList(nodes)).iterator(); 265 while (i.hasNext()) { 266 result.add(i.next()); 267 } 268 return (result); 269 } 270 public Collection getEdges() throws Exception { 271 ArrayList result = new ArrayList (); 272 Object [] edges = projectSessionClient.getEdgesNames(); 273 274 Iterator i = ((java.util.List ) Arrays.asList(edges)).iterator(); 275 while (i.hasNext()) { 276 result.add(i.next()); 277 } 278 279 return result; 280 } 281 282 public void addNodeProperty(String node, String key,String value, boolean propagate) throws Exception { 283 284 projectSessionClient.setNodeProperty( node,key,value, propagate); 285 } 286 287 public void addIteration(String from, String to, String condition) throws Exception { 288 projectSessionClient.addIteration(from,to,condition); 289 } 290 291 public Collection getIterations() throws Exception { 292 ArrayList result = new ArrayList (); 293 Object [] ite = projectSessionClient.getIterations(); 294 295 Iterator i = ((java.util.List ) Arrays.asList(ite)).iterator(); 296 while (i.hasNext()) { 297 result.add((hero.net.ProjectSession.BnIterationLightValue)i.next()); 298 } 299 300 return result; 301 } 302 303 public void addProjectProperty(String key,String value) throws Exception { 304 projectSessionClient.setProperty(key,value); 305 } 306 307 public void addNodeInterHook(String node, String hook, String event, String value) throws Exception { 308 309 projectSessionClient.addNodeInterHook(node,hook,event,6,value); 310 } 311 312 public void addProjectInterHook(String hook, String event, String value) throws Exception { 313 projectSessionClient.addInterHook(hook,event,6,value); 314 } 315 316 public void addNode(String name, String type) throws Exception { 317 int nodeType = 0; 318 if (type.equals("AND JOIN")) 319 nodeType = Constants.Nd.AND_JOIN_NODE; 320 if (type.equals("OR JOIN")) 321 nodeType = Constants.Nd.OR_JOIN_NODE; 322 if (type.equals("AND JOIN AUTO")) 323 nodeType = Constants.Nd.AND_JOIN_AUTOMATIC_NODE; 324 if (type.equals("OR JOIN AUTO")) 325 nodeType = Constants.Nd.OR_JOIN_AUTOMATIC_NODE; 326 if (type.equals("SUB PROCESS")) 327 nodeType = Constants.Nd.SUB_PROCESS_NODE; 328 projectSessionClient.addNode(name, nodeType); 329 330 } 331 332 public void addNodeSubProcess(String name, String projectName) throws Exception { 333 projectSessionClient.addNodeSubProcess(name,projectName); 334 } 335 336 public boolean deleteNode(String node) throws Exception { 337 projectSessionClient.deleteNode(node); 338 return true; 339 } 340 341 public boolean deleteProject(String projectName) throws Exception { 342 userSessionClient.removeProject(projectName); 343 return true; 344 } 345 346 347 public void deleteEdges(Object [] edges) throws Exception { 348 for (int i = 0; i < edges.length; i++) { 349 projectSessionClient.deleteEdge((String ) edges[i]); 350 } 351 } 352 353 public String addEdge(String src, String dest) throws Exception { 354 String name = null; 355 name = projectSessionClient.addEdge(src,dest); 356 return name; 357 } 358 359 public String setEdgeCondition(String edgeName, String condition) throws Exception { 360 projectSessionClient.setEdgeCondition(edgeName,condition); 361 return edgeName; 362 } 363 364 public String getEdgeCondition(String edgeName) throws Exception { 365 return(projectSessionClient.getEdgeCondition(edgeName)); 366 } 367 368 public String getState(String name) throws Exception { 369 int state = getNodeState(name); 370 switch (state) { 371 case Constants.Nd.INITIAL : 372 return ("Initial"); 373 case Constants.Nd.READY : 374 return ("Ready"); 375 case Constants.Nd.ANTICIPABLE : 376 return ("Anticipable"); 377 case Constants.Nd.ANTICIPATING : 378 return ("Anticipating"); 379 case Constants.Nd.EXECUTING : 380 return ("Executing"); 381 case Constants.Nd.EXECUTED : 382 return ("Executed"); 383 case Constants.Nd.TERMINATED : 384 return ("Terminated"); 385 case Constants.Nd.ANT_SUSPENDED : 386 return ("Ant_suspended"); 387 case Constants.Nd.EXEC_SUSPENDED : 388 return ("Exec_suspended"); 389 } 390 return (""); 391 } 392 393 public int getNodeState(String name) throws Exception { 394 return (projectSessionClient.getNodeState(name)); 395 } 396 397 public int getNodeType(String name) throws Exception { 398 return (projectSessionClient.getNodeType(name)); 399 } 400 401 public boolean getNodeAnticipable(String name) throws Exception { 402 return (projectSessionClient.getNodeAnticipable(name)); 403 } 404 405 public String getNodeInterHookValue(String nodeName, String hookName) throws Exception { 406 return (projectSessionClient.getNodeInterHookValue(nodeName,hookName)); 407 } 408 409 public void setNodeInterHookValue(String nodeName, String hookName, String value) throws Exception { 410 projectSessionClient.setNodeInterHookValue(nodeName,hookName,value); 411 } 412 413 public String getProjectInterHookValue(String hookName) throws Exception { 414 return (projectSessionClient.getInterHookValue(hookName)); 415 } 416 417 public void setProjectInterHookValue(String hookName, String value) throws Exception { 418 projectSessionClient.setInterHookValue(hookName,value); 419 } 420 421 public String getNodeDescription(String nodeName) throws Exception { 422 return (projectSessionClient.getNodeDescription(nodeName)); 423 } 424 425 public void setNodeDescription(String nodeName, String description) throws Exception { 426 projectSessionClient.setNodeDescription(nodeName,description); 427 } 428 429 public void setNodeTraditional(String nodeName) throws Exception { 430 projectSessionClient.setNodeTraditional(nodeName); 431 } 432 433 public void setNodeAnticipable(String nodeName) throws Exception { 434 projectSessionClient.setNodeAnticipable(nodeName); 435 } 436 437 public String getEdgeInNode(String name) throws Exception { 438 return (projectSessionClient.getEdgeInNode(name)); 439 } 440 441 public String getEdgeOutNode(String name) throws Exception { 442 return (projectSessionClient.getEdgeOutNode(name)); 443 } 444 445 public boolean isActive(String name) throws Exception { int state = getNodeState(name); 447 switch (state) { 448 case Constants.Nd.INITIAL : 449 return false; 450 case Constants.Nd.READY : 451 return false; 452 case Constants.Nd.ANTICIPABLE : 453 return false; 454 case Constants.Nd.ANTICIPATING : 455 return true; 456 case Constants.Nd.EXECUTING : 457 return true; 458 case Constants.Nd.EXECUTED : 459 return false; 460 case Constants.Nd.TERMINATED : 461 return true; 462 case Constants.Nd.ANT_SUSPENDED : 463 return false; 464 case Constants.Nd.EXEC_SUSPENDED : 465 return false; 466 } 467 return false; 468 } 469 470 public String getType(String name) throws Exception { 471 int type = projectSessionClient.getNodeType(name); 472 switch (type) { 473 case Constants.Nd.AND_JOIN_NODE : 474 return ("And Join"); 475 case Constants.Nd.OR_JOIN_NODE : 476 return ("Or Join"); 477 case Constants.Nd.AND_JOIN_AUTOMATIC_NODE : 478 return ("And Join Automatic"); 479 case Constants.Nd.OR_JOIN_AUTOMATIC_NODE : 480 return ("Or Join Automatic"); 481 case Constants.Nd.SUB_PROCESS_NODE : 482 return ("Sub Procss"); 483 } 484 return (""); 485 } 486 487 public String getRole(String name) throws Exception { 488 return(projectSessionClient.getNodeRoleName(name)); 489 } 490 491 public void setNodeRole(String node, String newRole) throws Exception { 492 projectSessionClient.setNodeRole(node,newRole); 493 } 494 495 496 public String getDeadline(String name) throws Exception { 497 return(projectSessionClient.getNodeDeadline(name)); 498 } 499 500 public void setDeadline(String node, long dl) throws Exception { 501 projectSessionClient.setNodeDeadline(node,dl); 502 } 503 504 public Collection getRoles() throws Exception { 505 ArrayList result = new ArrayList (); 506 Object [] roles = projectSessionClient.getRolesNames(); 507 Iterator i = ((java.util.List ) Arrays.asList(roles)).iterator(); 508 while (i.hasNext()) { 509 result.add(i.next()); 510 } 511 return (result); 512 } 513 514 public Collection getUsersInProject() throws Exception { 515 ArrayList result = new ArrayList (); 516 Object [] users = projectSessionClient.getUsers(); 517 Iterator i = ((java.util.List ) Arrays.asList(users)).iterator(); 518 while (i.hasNext()) { 519 result.add(i.next()); 520 } 521 return (result); 522 } 523 524 public Collection getAllUsers() throws Exception { 525 ArrayList result = new ArrayList (); 526 Object [] users = projectSessionClient.getAllUsers(); 527 Iterator i = ((java.util.List ) Arrays.asList(users)).iterator(); 528 while (i.hasNext()) { 529 result.add(i.next()); 530 } 531 return (result); 532 } 533 534 public void addUser(String name) throws Exception { 535 projectSessionClient.addUser(name); 536 } 537 public void addRole(String name, String desc) throws Exception { 538 projectSessionClient.addRole(name,desc); 539 } 540 public void setUserRole(String name, String role) throws Exception { 541 projectSessionClient.setUserRole(name,role); 542 } 543 544 public void addRoleMapper(String role, String mapper, String type) throws Exception { 545 int mapperType=0; 546 if (type.equals(Constants.Mapper.PROPERTIESMAPPER)) 547 mapperType=1; 548 if (type.equals(Constants.Mapper.CUSTOMMAPPER)) 549 mapperType=2; 550 projectSessionClient.addRoleMapper(role,mapper,mapperType); 551 } 552 553 public void addNodePerformerAssigment(String node, String name, String type, String property) throws Exception { 554 int performerType=0; 555 if (type.equals(Constants.PerformerAssigment.PROPERTIESPA)) 556 performerType=1; 557 projectSessionClient.addNodePerformerAssign(node, name, performerType, property); 558 } 559 560 public boolean isInRole(String name, String role) throws Exception { 561 Object [] projects = projectSessionClient.getUserRolesInProjectNames(name); 562 563 Iterator i = ((java.util.List ) Arrays.asList(projects)).iterator(); 564 while (i.hasNext()) { 565 String roleName = (String ) i.next(); 566 if (roleName.equals(role)) 567 return true; 568 } 569 return false; 570 } 571 572 public Collection getToDoList(String project) throws Exception { 573 ArrayList result = new ArrayList (); 574 Object [] activity = userSessionClient.getToDoList(project); 575 Iterator i = ((java.util.List ) Arrays.asList(activity)).iterator(); 576 while (i.hasNext()) { 577 result.add(i.next()); 578 } 579 return result; 580 } 581 582 public Collection getActivityList(String project) throws Exception { 583 ArrayList result = new ArrayList (); 584 Object [] activity = userSessionClient.getActivityList(project); 585 Iterator i = ((java.util.List ) Arrays.asList(activity)).iterator(); 586 while (i.hasNext()) { 587 result.add(i.next()); 588 } 589 return result; 590 } 591 592 593 public Object [] getProjectNodes() throws Exception { 594 return(projectSessionClient.getNodes()); 595 } 596 597 public Collection getProperties() throws Exception { 598 ArrayList result = new ArrayList (); 599 Object [] prop = projectSessionClient.getPropertiesKey(); 600 Iterator i = ((java.util.List ) Arrays.asList(prop)).iterator(); 601 while (i.hasNext()) { 602 result.add(i.next()); 603 } 604 return result; 605 } 606 607 public void setEditNode(String node, String role, String description, long date) throws Exception { 608 projectSessionClient.setEditNode(node, role, description,date); 609 } 610 611 public void startActivity(String project, String activity) throws Exception { 612 userSessionClient.startActivity(project,activity); 613 } 614 615 public void terminateActivity(String project, String activity) throws Exception { 616 userSessionClient.terminateActivity(project,activity); 617 } 618 public void cancelActivity(String project, String activity) throws Exception { 619 userSessionClient.cancelActivity(project,activity); 620 } 621 622 public void terminateProject(String project) throws Exception { 623 userSessionClient.terminate(project); 624 } 625 public hero.net.ProjectSession.StrutsNodeValue getStrutsNode(String name) throws Exception { 626 return(projectSessionClient.getStrutsNode(name)); 627 } 628 629 } 630
| Popular Tags
|