1 package hero.client.grapheditor; 2 3 24 25 import hero.interfaces.Constants; 26 27 import java.util.Iterator ; 28 import java.util.Collection ; 29 import java.util.Date ; 30 31 import javax.swing.JOptionPane ; 32 import hero.util.BonitaClient; 33 import hero.util.ProjectNodes; 34 import hero.net.ProjectSession.StrutsNodeValue; 35 import javax.swing.ImageIcon ; 36 import java.text.SimpleDateFormat ; 37 38 public class WFPersistence { 39 40 private String projectName; 42 public boolean permission = false; 43 private String endpoint = null; 44 private String url = null; 45 private String userPassword = null; 46 public BonitaClient soapclient; 47 private ProjectNodes pn = new ProjectNodes(); 48 public final static String imageBase = "images/"; 49 public final static ImageIcon icon = new ImageIcon (Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png")); 50 51 public WFPersistence(String managerProject, BonitaClient soapclient) throws Exception { 52 this.soapclient = soapclient; 53 soapclient.openProject(managerProject); 54 projectName = managerProject; 55 permission = isInRole(this.getUser(), Constants.ADMIN); 56 } 57 58 public boolean openProject(String projectName) throws Exception { 59 soapclient.openProject(projectName); 60 this.projectName = projectName; 61 this.setProjectNodes(); 62 return true; 63 } 64 65 public boolean createProject(String projectName) throws Exception { 66 67 if (exists(projectName)) { 68 return false; 69 } 70 71 soapclient.createProject(projectName); 72 this.projectName = projectName; 74 return true; 75 76 } 77 78 public boolean createModel(String modelName) throws Exception { 79 80 if (exists(modelName)) { 81 return false; 82 } 83 84 soapclient.createModel(modelName); 85 this.projectName = modelName; 87 return true; 88 89 } 90 91 public boolean cloneProject(String projectSrc, String projectDest) 92 throws Exception { 93 if (exists(projectDest)) { 94 return false; 95 } 96 soapclient.cloneProject(projectSrc, projectDest); 97 this.projectName = projectDest; 99 return true; 100 } 101 102 public boolean cloneSubProject(String projectSrc, String projectDest) 103 throws Exception { 104 soapclient.cloneProject(projectSrc, projectDest); 105 return true; 106 } 107 108 public String getUser() throws Exception { 109 return (soapclient.getUser()); 110 } 111 112 public boolean hasPermission() { 113 return permission; 114 } 115 116 private boolean exists(String name) throws Exception { 117 String prj; 118 Collection projects = soapclient.getProjects(); 119 Iterator i = projects.iterator(); 120 while (i.hasNext()) { 121 prj = (String ) i.next(); 122 if (prj.equalsIgnoreCase(name)) { 123 return true; 124 } 125 } 126 return false; 127 } 128 129 public Object [] getProjects() throws Exception { 130 Collection projects = soapclient.getProjects(); 131 return (projects.toArray()); 132 } 133 134 public boolean containsNode(String value) throws Exception { 135 Collection nodes = soapclient.getNodes(); 136 Iterator i = nodes.iterator(); 137 while (i.hasNext()) { 138 String nodeName = (String ) i.next(); 139 if (value.equalsIgnoreCase(nodeName)) { 140 return true; 141 } 142 } 143 return false; 144 } 145 146 public boolean containsProject(String value) throws Exception { 147 Collection projects = soapclient.getProjects(); 148 Iterator i = projects.iterator(); 149 while (i.hasNext()) { 150 String projectName = (String ) i.next(); 151 if (value.equalsIgnoreCase(projectName)) { 152 return true; 153 } 154 } 155 return false; 156 } 157 158 public Object [] getNodes() throws Exception { 159 Collection nodes = soapclient.getNodes(); 160 return (nodes.toArray()); 161 } 162 163 public Object [] getEdges() throws Exception { 164 Collection nodes = soapclient.getEdges(); 165 return (nodes.toArray()); 166 } 167 168 public void addNode(String name, String type) throws Exception { 169 soapclient.addNode(name, type); 170 } 171 172 public void addNodeSubProcess(String name, String projectName) throws Exception { 173 soapclient.addNodeSubProcess(name, projectName); 174 } 175 176 public boolean deleteNode(String node) throws Exception { 177 soapclient.deleteNode(node); 178 return true; 179 } 180 181 public boolean deleteProject(String project) throws Exception { 182 soapclient.deleteProject(project); 183 return true; 184 } 185 186 public void deleteEdges(Object [] edges) throws Exception { 187 soapclient.deleteEdges(edges); 188 } 189 190 public String addEdge(String src, String dest) throws Exception { 191 return soapclient.addEdge(src, dest); 192 } 193 194 public String setEdgeCondition(String edgeName, String condition) 195 throws Exception { 196 soapclient.setEdgeCondition(edgeName, condition); 197 return edgeName; 198 } 199 200 public String getEdgeCondition(String edgeName) 201 throws Exception { 202 return (soapclient.getEdgeCondition(edgeName)); 203 } 204 205 public String getState(String name) throws Exception { 206 int state = soapclient.getNodeState(name); 207 switch (state) { 208 case Constants.Nd.INITIAL : 209 return ("Initial"); 210 case Constants.Nd.READY : 211 return ("READY"); 212 case Constants.Nd.ANTICIPABLE : 213 return ("Anticipable"); 214 case Constants.Nd.ANTICIPATING : 215 return ("Anticipating"); 216 case Constants.Nd.EXECUTING : 217 return ("Executing"); 218 case Constants.Nd.EXECUTED : 219 return ("Executed"); 220 case Constants.Nd.TERMINATED : 221 return ("Terminated"); 222 case Constants.Nd.ANT_SUSPENDED : 223 return ("Ant_suspended"); 224 case Constants.Nd.EXEC_SUSPENDED : 225 return ("Exec_suspended"); 226 } 227 return (""); 228 } 229 230 public int getNodeState(String name) throws Exception { 231 239 return(soapclient.getNodeState(name)); 240 } 241 242 public int getNodeType(String name) throws Exception { 243 251 return(soapclient.getNodeType(name)); 252 } 253 254 public String getEdgeInNode(String name) throws Exception { 255 return (soapclient.getEdgeInNode(name)); 256 } 257 258 public String getEdgeOutNode(String name) throws Exception { 259 return (soapclient.getEdgeOutNode(name)); 260 } 261 262 public boolean isActive(String name) 263 throws Exception { int state = soapclient.getNodeState(name); 265 switch (state) { 266 case Constants.Nd.INITIAL : 267 return false; 268 case Constants.Nd.READY : 269 return false; 270 case Constants.Nd.ANTICIPABLE : 271 return false; 272 case Constants.Nd.ANTICIPATING : 273 return true; 274 case Constants.Nd.EXECUTING : 275 return true; 276 case Constants.Nd.EXECUTED : 277 return false; 278 case Constants.Nd.TERMINATED : 279 return true; 280 case Constants.Nd.ANT_SUSPENDED : 281 return false; 282 case Constants.Nd.EXEC_SUSPENDED : 283 return false; 284 } 285 return false; 286 } 287 288 public String getType(String name) throws Exception { 289 return (soapclient.getType(name)); 290 } 291 292 public String getRole(String name) throws Exception { 293 return (soapclient.getRole(name)); 294 } 295 296 public void setNodeRole(String node, String newRole) throws Exception { 297 soapclient.setNodeRole(node, newRole); 298 this.setProjectNodeRole(node,newRole); 299 } 300 301 public String getDeadline(String name) throws Exception { 302 this.setProjectNodes(); 303 return (soapclient.getDeadline(name)); 304 } 305 306 public void setDeadline(String name, long dl) throws Exception { 307 soapclient.setDeadline(name, dl); 308 } 309 310 public String getNodeInterHookValue(String nodeName, String hookName) 311 throws Exception { 312 return (soapclient.getNodeInterHookValue(nodeName, hookName)); 313 } 314 315 public String getProjectInterHookValue(String hookName) 316 throws Exception { 317 return (soapclient.getProjectInterHookValue(hookName)); 318 } 319 320 public String getNodeDescription(String nodeName) throws Exception { 321 return (soapclient.getNodeDescription(nodeName)); 322 } 323 324 public void setNodeDescription(String nodeName, String description) 325 throws Exception { 326 soapclient.setNodeDescription(nodeName, description); 327 this.setProjectNodeDescription(nodeName,description); 328 } 329 330 public void setNodeTraditional(String nodeName) 331 throws Exception { 332 soapclient.setNodeTraditional(nodeName); 333 } 334 335 public void setNodeAnticipable(String nodeName) 336 throws Exception { 337 soapclient.setNodeAnticipable(nodeName); 338 } 339 340 public boolean getNodeAnticipable(String nodeName) 341 throws Exception { 342 return(soapclient.getNodeAnticipable(nodeName)); 343 } 344 345 public void setNodeInterHookValue(String nodeName,String hookName,String value) 346 throws Exception { 347 soapclient.setNodeInterHookValue(nodeName, hookName, value); 348 } 349 350 public void setProjectInterHookValue(String hookName,String value) 351 throws Exception { 352 soapclient.setProjectInterHookValue(hookName, value); 353 } 354 355 public Object [] getRoles() throws Exception { 356 Collection roles = soapclient.getRoles(); 357 return (roles.toArray()); 358 } 359 360 public Object [] getUsersInProject() throws Exception { 361 Collection users = soapclient.getUsersInProject(); 362 return (users.toArray()); 363 } 364 365 public Object [] getAllUsers() throws Exception { 366 Collection users = soapclient.getAllUsers(); 367 return (users.toArray()); 368 } 369 370 public void addUser(String name) throws Exception { 371 soapclient.addUser(name); 372 } 373 374 public void addRole(String name, String desc) throws Exception { 375 soapclient.addRole(name, desc); 376 } 377 378 public void addNodeProperty(String nodeName,String key,String value,boolean propagate) 379 throws Exception { 380 soapclient.addNodeProperty(nodeName, key, value, propagate); 381 } 382 383 public void addProjectProperty(String key,String value) 384 throws Exception { 385 soapclient.addProjectProperty(key, value); 386 } 387 388 public void setUserRole(String name, String role) throws Exception { 389 soapclient.setUserRole(name, role); 390 } 391 392 public void addRoleMapper(String role, String mapper, String type) throws Exception { 393 soapclient.addRoleMapper(role,mapper,type); 394 } 395 396 public void addPerformerAssigment(String node, String performerName, String type, String property) throws Exception { 397 soapclient.addNodePerformerAssigment(node,performerName,type,property); 398 } 399 400 public void setEditNode(String node, String role, String description, Date deadline) throws Exception { 401 soapclient.setEditNode(node, role, description, deadline.getTime()); 402 this.setProjectNodeRole(node,role); 403 this.setProjectNodeDescription(node,description); 404 this.setProjectNodeDeadline(node,deadline.getTime()); 405 } 406 407 public void addNodeInterHook(String nodeName,String hookName,String event,String value) 408 throws Exception { 409 soapclient.addNodeInterHook(nodeName, hookName, event, value); 410 } 411 412 public void addProjectInterHook(String hookName,String event,String value) 413 throws Exception { 414 soapclient.addProjectInterHook(hookName, event, value); 415 } 416 417 public void addIteration(String from,String to, String condition) 418 throws Exception { 419 soapclient.addIteration(from, to, condition); 420 } 421 422 public Collection getIterations() 423 throws Exception { 424 return(soapclient.getIterations()); 425 } 426 427 428 public boolean isInRole(String name, String role) throws Exception { 429 return (soapclient.isInRole(name, role)); 430 } 431 432 public String getProjectName() { 433 return this.projectName; 434 } 435 436 public String getStateString(int state) throws Exception { 437 switch (state) { 438 case Constants.Nd.INITIAL : 439 return ("INITIAL"); 440 case Constants.Nd.READY : 441 return ("READY"); 442 case Constants.Nd.ANTICIPABLE : 443 return ("ANTICIPABLE"); 444 case Constants.Nd.ANTICIPATING : 445 return ("ANTICIPATING"); 446 case Constants.Nd.EXECUTING : 447 return ("EXECUTING"); 448 case Constants.Nd.EXECUTED : 449 return ("EXECUTED"); 450 case Constants.Nd.TERMINATED : 451 return ("TERMINATED"); 452 case Constants.Nd.ANT_SUSPENDED : 453 return ("ANT_SUSPENDED"); 454 case Constants.Nd.EXEC_SUSPENDED : 455 return ("EXEC_SUSPENDED"); 456 } 457 return (""); 458 } 459 460 public int getStateInt(String state) throws Exception { 461 if (state.equals("INITIAL")) 462 return Constants.Nd.INITIAL; 463 if (state.equals("READY")) 464 return Constants.Nd.READY; 465 if (state.equals("ANTICIPABLE")) 466 return Constants.Nd.ANTICIPABLE; 467 if (state.equals("ANTICIPATING")) 468 return Constants.Nd.ANTICIPATING; 469 if (state.equals("EXECUTING")) 470 return Constants.Nd.EXECUTING; 471 if (state.equals("TERMINATED")) 472 return Constants.Nd.TERMINATED; 473 return (-1); 474 } 475 476 477 public String getTypeString(int type) throws Exception { 478 switch (type) { 479 case Constants.Nd.AND_JOIN_NODE : 480 return ("And Join"); 481 case Constants.Nd.OR_JOIN_NODE : 482 return ("Or Join"); 483 case Constants.Nd.AND_JOIN_AUTOMATIC_NODE : 484 return ("And Join Automatic"); 485 case Constants.Nd.OR_JOIN_AUTOMATIC_NODE : 486 return ("Or Join Automatic"); 487 } 488 return (""); 489 } 490 491 public void setProjectNodes() throws Exception { 492 this.pn.setNodes(soapclient.getProjectNodes()); 493 } 494 495 public Object [] getProjectNodes() throws Exception { 496 return(soapclient.getProjectNodes()); 497 } 498 499 public Object [] getProjectNodesArray() throws Exception { 500 return(this.pn.getNodes()); 501 } 502 503 public Collection getProperties() throws Exception { 504 return(soapclient.getProperties()); 505 } 506 507 public void windowMessage(String msg) { 508 JOptionPane.showMessageDialog(null, msg); 509 } 510 511 513 public StrutsNodeValue getProjectNode(String nodeName) throws Exception { 514 517 Object [] nodes = this.pn.getNodes(); 518 for (int i=0;i<nodes.length;i++) 519 { 520 StrutsNodeValue node = (StrutsNodeValue)nodes[i]; 521 if ((node.getName()).equals(nodeName)) 522 return node; 523 } 524 return null; 525 } 527 528 public void setProjectNodeState(String nodeName, int state) throws Exception { 529 Object [] nodes = this.pn.getNodes(); 530 for (int i=0;i<nodes.length;i++) 531 { 532 StrutsNodeValue node = (StrutsNodeValue) nodes[i]; 533 if ((node.getName()).equals(nodeName)) 534 node.setState(this.getStateString(state)); 535 } 536 } 537 538 public void setProjectNodeRole(String nodeName, String role) throws Exception { 539 Object [] nodes = this.pn.getNodes(); 540 for (int i=0;i<nodes.length;i++) 541 { 542 StrutsNodeValue node = (StrutsNodeValue) nodes[i]; 543 if ((node.getName()).equals(nodeName)) 544 node.setRole(role); 545 } 546 } 547 548 public void setProjectNodeDescription(String nodeName, String description) throws Exception { 549 Object [] nodes = this.pn.getNodes(); 550 for (int i=0;i<nodes.length;i++) 551 { 552 StrutsNodeValue node = (StrutsNodeValue) nodes[i]; 553 if ((node.getName()).equals(nodeName)) 554 node.setDescription(description); 555 } 556 } 557 558 public void setProjectNodeDeadline(String nodeName, long deadline) throws Exception { 559 Object [] nodes = this.pn.getNodes(); 560 for (int i=0;i<nodes.length;i++) 561 { 562 StrutsNodeValue node = (StrutsNodeValue) nodes[i]; 563 if ((node.getName()).equals(nodeName)){ 564 SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd"); 565 node.setDeadline(df.format(df.parse(new java.sql.Date (deadline).toString()))); 566 } 567 } 568 } 569 570 } 572 | Popular Tags |