1 package org.enhydra.shark; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 import java.util.Map ; 8 9 import org.enhydra.shark.api.RootException; 10 import org.enhydra.shark.api.SharkTransaction; 11 import org.enhydra.shark.api.client.wfbase.BaseException; 12 import org.enhydra.shark.api.client.wfmodel.WfActivity; 13 import org.enhydra.shark.api.client.wfmodel.WfActivityIterator; 14 import org.enhydra.shark.api.client.wfmodel.WfAssignment; 15 import org.enhydra.shark.api.client.wfmodel.WfAssignmentIterator; 16 import org.enhydra.shark.api.client.wfmodel.WfProcess; 17 import org.enhydra.shark.api.client.wfmodel.WfProcessIterator; 18 import org.enhydra.shark.api.client.wfmodel.WfProcessMgr; 19 import org.enhydra.shark.api.client.wfmodel.WfResource; 20 import org.enhydra.shark.api.client.wfservice.ConnectFailed; 21 import org.enhydra.shark.api.client.wfservice.ExecutionAdministration; 22 import org.enhydra.shark.api.client.wfservice.NotConnected; 23 import org.enhydra.shark.api.client.wfservice.WfProcessMgrIterator; 24 import org.enhydra.shark.api.client.wfservice.WfResourceIterator; 25 import org.enhydra.shark.api.common.SharkConstants; 26 import org.enhydra.shark.api.internal.caching.CacheMgr; 27 import org.enhydra.shark.api.internal.instancepersistence.ActivityPersistenceInterface; 28 import org.enhydra.shark.api.internal.instancepersistence.ActivityVariablePersistenceInterface; 29 import org.enhydra.shark.api.internal.instancepersistence.PersistenceException; 30 import org.enhydra.shark.api.internal.instancepersistence.PersistentManagerInterface; 31 import org.enhydra.shark.api.internal.instancepersistence.ProcessPersistenceInterface; 32 import org.enhydra.shark.api.internal.instancepersistence.ProcessVariablePersistenceInterface; 33 import org.enhydra.shark.api.internal.processlocking.LockMaster; 34 import org.enhydra.shark.api.internal.security.SecurityManager; 35 import org.enhydra.shark.api.internal.working.CallbackUtilities; 36 import org.enhydra.shark.api.internal.working.WfActivityInternal; 37 import org.enhydra.shark.api.internal.working.WfAssignmentInternal; 38 import org.enhydra.shark.api.internal.working.WfProcessInternal; 39 import org.enhydra.shark.api.internal.working.WfProcessMgrInternal; 40 import org.enhydra.shark.api.internal.working.WfResourceInternal; 41 42 49 public class ExecutionAdmin implements ExecutionAdministration { 50 51 private String userId; 52 private boolean connected=false; 53 54 private String connectionKey; 55 56 57 private CallbackUtilities cus; 58 protected ExecutionAdmin () { 59 this.cus=SharkEngineManager.getInstance().getCallbackUtilities(); 60 } 61 62 public void connect (String userId,String password,String engineName,String scope) throws BaseException, ConnectFailed { 63 SharkTransaction t = null; 64 try { 65 t = SharkUtilities.createTransaction(); 66 connect(t, userId, password, engineName, scope); 67 SharkUtilities.commitTransaction(t); 68 } catch (RootException e) { 69 SharkUtilities.rollbackTransaction(t,e); 70 if (e instanceof ConnectFailed) 71 throw (ConnectFailed)e; 72 else if (e instanceof BaseException) 73 throw (BaseException)e; 74 else 75 throw new BaseException(e); 76 } finally { 77 SharkUtilities.releaseTransaction(t); 78 } 79 } 80 81 public void connect (SharkTransaction t,String userId,String password,String engineName,String scope) throws BaseException, ConnectFailed { 82 this.userId=userId; 83 84 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 85 if (sm!=null) { 86 try { 87 sm.check_executionadministration_connect(t,userId); 88 } catch (Exception ex) { 89 throw new BaseException(ex); 90 } 91 } 92 try { 93 if (!SharkUtilities.validateUser(userId,password)) { 94 cus.info("ExecutionAdmin -> Login failed: Invalid username or password"+userId); 95 throw new ConnectFailed("Connection failed, invalid username or password"); 96 } 97 98 if (SharkUtilities.getResource(t, userId)==null) { 99 WfResourceInternal resInternal=SharkEngineManager 100 .getInstance() 101 .getObjectFactory() 102 .createResource(t,userId); 103 } 104 connectionKey=SharkUtilities.connect(userId); 105 connected=true; 106 cus.info("ExecutionAdmin -> User "+userId+" with connection key "+connectionKey+" is logged on"); 107 } catch (Exception ex) { 108 if (ex instanceof ConnectFailed) { 109 throw (ConnectFailed)ex; 110 } 111 cus.info("ExecutionAdmin -> Unexpected error while user "+userId+" loggs on"); 112 ex.printStackTrace(); 113 throw new BaseException(ex); 114 } 115 } 116 117 public void disconnect () throws BaseException, NotConnected { 118 SharkTransaction t = null; 119 try { 120 t = SharkUtilities.createTransaction(); 121 disconnect(t); 122 } catch (RootException e) { 124 SharkUtilities.emptyCaches(t); 126 if (e instanceof NotConnected) 127 throw (NotConnected)e; 128 else if (e instanceof BaseException) 129 throw (BaseException)e; 130 else 131 throw new BaseException(e); 132 } finally { 133 SharkUtilities.releaseTransaction(t); 134 } 135 } 136 137 public void disconnect (SharkTransaction t) throws BaseException, NotConnected { 138 if (!connected) { 139 throw new NotConnected("The connection is not established..."); 140 } 141 try { 142 SharkUtilities.disconnect(connectionKey); 143 connected=false; 144 cus.info("ExecutionAdmin -> User "+userId+" with connection key "+connectionKey+" is logged off"); 145 } catch (Exception ex) { 146 if (ex instanceof NotConnected) { 147 throw (NotConnected)ex; 148 } 149 cus.info("ExecutionAdmin -> Unexpected error while user "+userId+" loggs off"); 150 throw new BaseException(ex); 151 } 152 } 153 154 public WfProcessMgrIterator get_iterator_processmgr () throws BaseException, NotConnected { 155 WfProcessMgrIterator ret = null; 156 SharkTransaction t = null; 157 try { 158 t = SharkUtilities.createTransaction(); 159 ret = get_iterator_processmgr(t); 160 } catch (RootException e) { 162 SharkUtilities.emptyCaches(t); 164 if (e instanceof NotConnected) 165 throw (NotConnected)e; 166 else if (e instanceof BaseException) 167 throw (BaseException)e; 168 else 169 throw new BaseException(e); 170 } finally { 171 SharkUtilities.releaseTransaction(t); 172 } 173 return ret; 174 } 175 176 public WfProcessMgrIterator get_iterator_processmgr (SharkTransaction t) throws BaseException, NotConnected { 177 if (!connected) { 178 throw new NotConnected("The connection is not established..."); 179 } 180 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 181 if (sm!=null) { 182 try { 183 sm.check_executionadministration_get_iterator_processmgr(t,userId); 184 } catch (Exception ex) { 185 throw new BaseException(ex); 186 } 187 } 188 try { 189 WfProcessMgrIterator ret=SharkEngineManager.getInstance(). 190 getObjectFactory().createProcessMgrIteratorWrapper(t,userId); 191 return ret; 192 } catch (Exception ex) { 193 cus.info("ExecutionAdmin -> Unexpected error while user tries to get process managers iterator"); 194 throw new BaseException(ex); 195 } 196 } 197 198 public WfProcessMgr[] get_sequence_processmgr (int max_number) throws BaseException, NotConnected { 199 WfProcessMgr[] ret = null; 200 SharkTransaction t = null; 201 try { 202 t = SharkUtilities.createTransaction(); 203 ret = get_sequence_processmgr(t, max_number); 204 } catch (RootException e) { 206 SharkUtilities.emptyCaches(t); 208 if (e instanceof NotConnected) 209 throw (NotConnected)e; 210 else if (e instanceof BaseException) 211 throw (BaseException)e; 212 else 213 throw new BaseException(e); 214 } finally { 215 SharkUtilities.releaseTransaction(t); 216 } 217 return ret; 218 } 219 220 public WfProcessMgr[] get_sequence_processmgr (SharkTransaction t,int max_number) throws BaseException, NotConnected { 221 if (!connected) { 222 throw new NotConnected("The connection is not established..."); 223 } 224 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 225 if (sm!=null) { 226 try { 227 sm.check_executionadministration_get_sequence_processmgr(t,userId); 228 } catch (Exception ex) { 229 throw new BaseException(ex); 230 } 231 } 232 try { 233 return SharkEngineManager 234 .getInstance() 235 .getObjectFactory() 236 .createProcessMgrIteratorWrapper(t,userId) 237 .get_next_n_sequence (t,max_number); 238 } catch (Exception ex) { 239 cus.info("ExecutionAdmin -> Unexpected error while user tries to get the list of process managers"); 240 throw new BaseException(ex); 241 } 242 } 243 244 public WfResourceIterator get_iterator_resource () throws BaseException, NotConnected { 245 WfResourceIterator ret = null; 246 SharkTransaction t = null; 247 try { 248 t = SharkUtilities.createTransaction(); 249 ret = get_iterator_resource(t); 250 } catch (RootException e) { 252 SharkUtilities.emptyCaches(t); 254 if (e instanceof NotConnected) 255 throw (NotConnected)e; 256 else if (e instanceof BaseException) 257 throw (BaseException)e; 258 else 259 throw new BaseException(e); 260 } finally { 261 SharkUtilities.releaseTransaction(t); 262 } 263 return ret; 264 } 265 266 public WfResourceIterator get_iterator_resource (SharkTransaction t) throws BaseException, NotConnected { 267 if (!connected) { 268 throw new NotConnected("The connection is not established..."); 269 } 270 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 271 if (sm!=null) { 272 try { 273 sm.check_executionadministration_get_iterator_resource(t,userId); 274 } catch (Exception ex) { 275 throw new BaseException(ex); 276 } 277 } 278 try { 279 return SharkEngineManager 280 .getInstance() 281 .getObjectFactory() 282 .createResourceIteratorWrapper(t,userId); 283 } catch (Exception ex) { 284 cus.info("ExecutionAdmin -> Unexpected error while user tries to get resource's iterator"); 285 throw new BaseException(ex); 286 } 287 } 288 289 public WfResource[] get_sequence_resource (int max_number) throws BaseException, NotConnected { 290 WfResource[] ret = null; 291 SharkTransaction t = null; 292 try { 293 t = SharkUtilities.createTransaction(); 294 ret = get_sequence_resource(t, max_number); 295 } catch (RootException e) { 297 SharkUtilities.emptyCaches(t); 299 if (e instanceof NotConnected) 300 throw (NotConnected)e; 301 else if (e instanceof BaseException) 302 throw (BaseException)e; 303 else 304 throw new BaseException(e); 305 } finally { 306 SharkUtilities.releaseTransaction(t); 307 } 308 return ret; 309 } 310 311 public WfResource[] get_sequence_resource (SharkTransaction t,int max_number) throws BaseException, NotConnected { 312 if (!connected) { 313 throw new NotConnected("The connection is not established..."); 314 } 315 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 316 if (sm!=null) { 317 try { 318 sm.check_executionadministration_get_sequence_resource(t,userId); 319 } catch (Exception ex) { 320 throw new BaseException(ex); 321 } 322 } 323 324 try { 325 return SharkEngineManager 326 .getInstance() 327 .getObjectFactory() 328 .createResourceIteratorWrapper(t,userId) 329 .get_next_n_sequence (max_number); 330 } catch (Exception ex) { 331 cus.info("ExecutionAdmin -> Unexpected error while user tries to get the list of resources"); 332 throw new BaseException(ex); 333 } 334 } 335 336 public Map getLoggedUsers () throws BaseException, NotConnected { 337 Map ret = null; 338 SharkTransaction t = null; 339 try { 340 t = SharkUtilities.createTransaction(); 341 ret = getLoggedUsers(t); 342 } catch (RootException e) { 344 SharkUtilities.emptyCaches(t); 346 if (e instanceof NotConnected) 347 throw (NotConnected)e; 348 else if (e instanceof BaseException) 349 throw (BaseException)e; 350 else 351 throw new BaseException(e); 352 } finally { 353 SharkUtilities.releaseTransaction(t); 354 } 355 return ret; 356 } 357 358 public Map getLoggedUsers(SharkTransaction t) throws BaseException, NotConnected { 359 if (!connected) { 360 throw new NotConnected("The connection is not established..."); 361 } 362 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 363 if (sm!=null) { 364 try { 365 sm.check_executionadministration_getLoggedUsers(t,userId); 366 } catch (Exception ex) { 367 throw new BaseException(ex); 368 } 369 } 370 try { 371 Map ret=SharkUtilities.getLoggedUsers(); 372 return ret; 373 } catch (Exception ex) { 374 cus.info("ExecutionAdmin -> Unexpected error while user tries to get logged users"); 375 throw new BaseException(ex); 376 } 377 } 378 379 public void startActivity (String procId,String blockActId,String actDefId) throws BaseException, NotConnected { 380 SharkTransaction t = null; 381 try { 382 t = SharkUtilities.createTransaction(); 383 startActivity(t, procId, blockActId, actDefId); 384 SharkUtilities.commitTransaction(t); 385 } catch (RootException e) { 386 SharkUtilities.rollbackTransaction(t,e); 387 if (e instanceof NotConnected) 388 throw (NotConnected)e; 389 else if (e instanceof BaseException) 390 throw (BaseException)e; 391 else 392 throw new BaseException(e); 393 } finally { 394 SharkUtilities.releaseTransaction(t); 395 } 396 } 397 398 public void startActivity (SharkTransaction t,String procId,String blockActId,String actDefId) throws BaseException, NotConnected { 399 if (!connected) { 400 throw new NotConnected("The connection is not established..."); 401 } 402 try { 403 WfProcessInternal proc=SharkUtilities.getProcess(t, procId); 404 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 405 if (sm!=null) { 406 sm.check_executionadministration_startActivity(t, 407 procId, 408 userId, 409 proc.requester(t).getResourceRequesterUsername(t)); 410 } 411 proc.start_activity(t, actDefId, blockActId); 412 } catch (Exception ex) { 413 throw new BaseException(ex); 414 } 415 } 416 417 public WfProcessMgr getProcessMgr (String name) throws BaseException, NotConnected { 418 WfProcessMgr ret = null; 419 SharkTransaction t = null; 420 try { 421 t = SharkUtilities.createTransaction(); 422 ret = getProcessMgr(t, name); 423 } catch (RootException e) { 425 SharkUtilities.emptyCaches(t); 427 if (e instanceof NotConnected) 428 throw (NotConnected)e; 429 else if (e instanceof BaseException) 430 throw (BaseException)e; 431 else 432 throw new BaseException(e); 433 } finally { 434 SharkUtilities.releaseTransaction(t); 435 } 436 return ret; 437 } 438 439 public WfProcessMgr getProcessMgr (SharkTransaction t,String name) throws BaseException, NotConnected { 440 if (!connected) { 441 throw new NotConnected("The connection is not established..."); 442 } 443 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 444 if (sm!=null) { 445 try { 446 sm.check_executionadministration_getProcessMgr(t,name,userId); 447 } catch (Exception ex) { 448 throw new BaseException(ex); 449 } 450 } 451 try { 452 return (null != SharkUtilities.getProcessMgr(t, name)) 453 ? SharkEngineManager.getInstance().getObjectFactory().createProcessMgrWrapper(userId,name) 454 : null; 455 } catch (Exception ex) { 456 throw new BaseException(ex); 457 } 458 } 459 460 public WfProcessMgr getProcessMgr (String pkgId,String pDefId) throws BaseException, NotConnected { 461 WfProcessMgr ret = null; 462 SharkTransaction t = null; 463 try { 464 t = SharkUtilities.createTransaction(); 465 ret = getProcessMgr(t, pkgId, pDefId); 466 } catch (RootException e) { 468 SharkUtilities.emptyCaches(t); 470 if (e instanceof NotConnected) 471 throw (NotConnected)e; 472 else if (e instanceof BaseException) 473 throw (BaseException)e; 474 else 475 throw new BaseException(e); 476 } finally { 477 SharkUtilities.releaseTransaction(t); 478 } 479 return ret; 480 } 481 482 public WfProcessMgr getProcessMgr (SharkTransaction t,String pkgId,String pDefId) throws BaseException, NotConnected { 483 if (!connected) { 484 throw new NotConnected("The connection is not established..."); 485 } 486 try { 487 String curVer=SharkUtilities.getCurrentPkgVersion(pkgId,false); 488 String mgrName=SharkUtilities.createProcessMgrKey(pkgId,curVer,pDefId); 489 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 490 if (sm!=null) { 491 sm.check_executionadministration_getProcessMgr(t,mgrName,userId); 492 } 493 return (null != SharkUtilities.getProcessMgr(t, mgrName)) 494 ? SharkEngineManager.getInstance().getObjectFactory().createProcessMgrWrapper(userId,mgrName) 495 : null; 496 } catch (Exception ex) { 497 throw new BaseException(ex); 498 } 499 } 500 501 public WfProcessMgr getProcessMgr (String pkgId,String pkgVer,String pDefId) throws BaseException, NotConnected { 502 WfProcessMgr ret = null; 503 SharkTransaction t = null; 504 try { 505 t = SharkUtilities.createTransaction(); 506 ret = getProcessMgr(t, pkgId, pkgVer, pDefId); 507 } catch (RootException e) { 509 SharkUtilities.emptyCaches(t); 511 if (e instanceof NotConnected) 512 throw (NotConnected)e; 513 else if (e instanceof BaseException) 514 throw (BaseException)e; 515 else 516 throw new BaseException(e); 517 } finally { 518 SharkUtilities.releaseTransaction(t); 519 } 520 return ret; 521 } 522 523 public WfProcessMgr getProcessMgr (SharkTransaction t,String pkgId,String pkgVer,String pDefId) throws BaseException, NotConnected { 524 if (!connected) { 525 throw new NotConnected("The connection is not established..."); 526 } 527 try { 528 String mgrName=SharkUtilities.createProcessMgrKey(pkgId,pkgVer,pDefId); 529 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 530 if (sm!=null) { 531 sm.check_executionadministration_getProcessMgr(t,mgrName,userId); 532 } 533 return (null != SharkUtilities.getProcessMgr(t, mgrName)) 534 ? SharkEngineManager.getInstance().getObjectFactory().createProcessMgrWrapper(userId,mgrName) 535 : null; 536 } catch (Exception ex) { 537 throw new BaseException(ex); 538 } 539 } 540 541 public WfProcess getProcess (String procId) throws BaseException, NotConnected { 542 WfProcess ret = null; 543 SharkTransaction t = null; 544 try { 545 t = SharkUtilities.createTransaction(); 546 ret = getProcess(t, procId); 547 } catch (RootException e) { 549 SharkUtilities.emptyCaches(t); 551 if (e instanceof NotConnected) 552 throw (NotConnected)e; 553 else if (e instanceof BaseException) 554 throw (BaseException)e; 555 else 556 throw new BaseException(e); 557 } finally { 558 SharkUtilities.releaseTransaction(t); 559 } 560 return ret; 561 } 562 563 public WfProcess getProcess (SharkTransaction t,String procId) throws BaseException, NotConnected { 564 if (!connected) { 565 throw new NotConnected("The connection is not established..."); 566 } 567 try { 568 WfProcessInternal proc=SharkUtilities.getProcess(t, procId); 569 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 570 if (sm!=null && proc!=null) { 571 sm.check_executionadministration_getProcess(t, 572 procId, 573 userId, 574 proc.requester(t).getResourceRequesterUsername(t)); 575 } 576 return (null != proc) 577 ? SharkEngineManager.getInstance().getObjectFactory().createProcessWrapper(userId,proc.manager_name(t),procId) 578 : null; 579 } catch (Exception ex) { 580 throw new BaseException(ex); 581 } 582 } 583 584 public WfActivity getActivity (String procId,String actId) throws BaseException, NotConnected { 585 WfActivity ret = null; 586 SharkTransaction t = null; 587 try { 588 t = SharkUtilities.createTransaction(); 589 ret = getActivity(t, procId, actId); 590 } catch (RootException e) { 592 SharkUtilities.emptyCaches(t); 594 if (e instanceof NotConnected) 595 throw (NotConnected)e; 596 else if (e instanceof BaseException) 597 throw (BaseException)e; 598 else 599 throw new BaseException(e); 600 } finally { 601 SharkUtilities.releaseTransaction(t); 602 } 603 return ret; 604 } 605 606 public WfActivity getActivity (SharkTransaction t,String procId,String actId) throws BaseException, NotConnected { 607 if (!connected) { 608 throw new NotConnected("The connection is not established..."); 609 } 610 try { 611 WfActivityInternal act=SharkUtilities.getActivity(t, procId, actId); 612 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 613 if (sm!=null && act!=null) { 614 sm.check_executionadministration_getActivity(t, 615 procId, 616 actId, 617 userId, 618 act.container(t).requester(t).getResourceRequesterUsername(t), 619 act.getResourceUsername(t), 620 act.getAssignmentResourceIds(t)); 621 } 622 return (null != act) 623 ? SharkEngineManager.getInstance().getObjectFactory().createActivityWrapper(userId,act.manager_name(t),procId,actId) 624 : null; 625 } catch (Exception ex) { 626 throw new BaseException(ex); 627 } 628 } 629 630 public WfResource getResource (String username) throws BaseException, NotConnected { 631 WfResource ret = null; 632 SharkTransaction t = null; 633 try { 634 t = SharkUtilities.createTransaction(); 635 ret = getResource(t, username); 636 } catch (RootException e) { 638 SharkUtilities.emptyCaches(t); 640 if (e instanceof NotConnected) 641 throw (NotConnected)e; 642 else if (e instanceof BaseException) 643 throw (BaseException)e; 644 else 645 throw new BaseException(e); 646 } finally { 647 SharkUtilities.releaseTransaction(t); 648 } 649 return ret; 650 } 651 652 public WfResource getResource (SharkTransaction t,String username) throws BaseException, NotConnected { 653 if (!connected) { 654 throw new NotConnected("The connection is not established..."); 655 } 656 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 657 if (sm!=null) { 658 try { 659 sm.check_executionadministration_getResource(t,username,userId); 660 } catch (Exception ex) { 661 throw new BaseException(ex); 662 } 663 } 664 try { 665 return (null != SharkUtilities.getResource(t,username)) 666 ? SharkEngineManager.getInstance().getObjectFactory().createResourceWrapper(userId,username) 667 : null; 668 } catch (Exception ex) { 669 throw new BaseException(ex); 670 } 671 } 672 673 public WfAssignment getAssignment (String procId,String actId,String username) throws BaseException, NotConnected { 674 WfAssignment ret = null; 675 SharkTransaction t = null; 676 try { 677 t = SharkUtilities.createTransaction(); 678 ret = getAssignment(t, procId, actId, username); 679 } catch (RootException e) { 681 SharkUtilities.emptyCaches(t); 683 if (e instanceof NotConnected) 684 throw (NotConnected)e; 685 else if (e instanceof BaseException) 686 throw (BaseException)e; 687 else 688 throw new BaseException(e); 689 } finally { 690 SharkUtilities.releaseTransaction(t); 691 } 692 return ret; 693 } 694 695 public WfAssignment getAssignment (SharkTransaction t,String procId,String actId,String username) throws BaseException, NotConnected { 696 if (!connected) { 697 throw new NotConnected("The connection is not established..."); 698 } 699 try { 700 WfAssignmentInternal ass=SharkUtilities.getAssignment(t, procId, actId, username); 701 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 702 if (sm!=null && ass!=null) { 703 sm.check_executionadministration_getAssignment(t, 704 procId, 705 actId, 706 username, 707 userId, 708 ass.activity(t).container(t).requester(t).getResourceRequesterUsername(t), 709 ass.activity(t).getResourceUsername(t), 710 ass.activity(t).getAssignmentResourceIds(t)); 711 } 712 return (null != ass) 713 ? SharkEngineManager.getInstance().getObjectFactory().createAssignmentWrapper(userId,ass.managerName(t),procId,actId,username) 714 : null; 715 } catch (Exception ex) { 716 throw new BaseException(ex); 717 } 718 } 719 720 public WfAssignment getAssignment (String procId,String assId) throws BaseException, NotConnected { 721 WfAssignment ret = null; 722 SharkTransaction t = null; 723 try { 724 t = SharkUtilities.createTransaction(); 725 ret = getAssignment(t, procId, assId); 726 } catch (RootException e) { 728 SharkUtilities.emptyCaches(t); 730 if (e instanceof NotConnected) 731 throw (NotConnected)e; 732 else if (e instanceof BaseException) 733 throw (BaseException)e; 734 else 735 throw new BaseException(e); 736 } finally { 737 SharkUtilities.releaseTransaction(t); 738 } 739 return ret; 740 } 741 742 public WfAssignment getAssignment (SharkTransaction t,String procId,String assId) throws BaseException, NotConnected { 743 if (!connected) { 744 throw new NotConnected("The connection is not established..."); 745 } 746 try { 747 WfProcessInternal proc=SharkUtilities.getProcess(t,procId); 748 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 749 if (sm!=null && proc!=null) { 750 sm.check_executionadministration_getAssignment(t, 751 procId, 752 assId, 753 userId, 754 proc.requester(t).getResourceRequesterUsername(t)); 755 } 756 757 return (null != proc) 758 ? SharkUtilities.getAssignmentWrapper(t, userId, procId, assId) 759 : null; 760 } catch (Exception ex) { 761 throw new BaseException(ex); 762 } 763 } 764 765 public void reevaluateAssignments () throws BaseException, NotConnected { 766 SharkTransaction t = null; 767 try { 768 t = SharkUtilities.createTransaction(); 769 reevaluateAssignments(t); 770 SharkUtilities.commitTransaction(t); 771 } catch (RootException e) { 772 SharkUtilities.rollbackTransaction(t,e); 773 if (e instanceof NotConnected) 774 throw (NotConnected)e; 775 else if (e instanceof BaseException) 776 throw (BaseException)e; 777 else 778 throw new BaseException(e); 779 } finally { 780 SharkUtilities.releaseTransaction(t); 781 } 782 } 783 784 public void reevaluateAssignments (SharkTransaction t) throws BaseException, NotConnected { 785 if (!connected) { 786 throw new NotConnected("The connection is not established..."); 787 } 788 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 789 if (sm!=null) { 790 try { 791 sm.check_executionadministration_reevaluateAssignments(t,userId); 792 } catch (Exception ex) { 793 throw new BaseException(ex); 794 } 795 } 796 SharkUtilities.reevaluateAssignments(t); 797 } 798 799 public void reevaluateAssignments (String pkgId) throws BaseException, NotConnected { 800 SharkTransaction t = null; 801 try { 802 t = SharkUtilities.createTransaction(); 803 reevaluateAssignments(t,pkgId); 804 SharkUtilities.commitTransaction(t); 805 } catch (RootException e) { 806 SharkUtilities.rollbackTransaction(t,e); 807 if (e instanceof NotConnected) 808 throw (NotConnected)e; 809 else if (e instanceof BaseException) 810 throw (BaseException)e; 811 else 812 throw new BaseException(e); 813 } finally { 814 SharkUtilities.releaseTransaction(t); 815 } 816 } 817 818 public void reevaluateAssignments (SharkTransaction t,String pkgId) throws BaseException, NotConnected { 819 if (!connected) { 820 throw new NotConnected("The connection is not established..."); 821 } 822 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 823 if (sm!=null) { 824 try { 825 sm.check_executionadministration_reevaluateAssignments(t,userId); 826 } catch (Exception ex) { 827 throw new BaseException(ex); 828 } 829 } 830 WfProcessMgrIterator iter=SharkEngineManager.getInstance(). 831 getObjectFactory().createProcessMgrIteratorWrapper(t,userId); 832 String query="packageId.equals(\""+pkgId+"\")"; 833 try { 834 iter.set_query_expression(t,query); 835 } catch (Exception ex) { 836 throw new BaseException(ex); 837 } 838 WfProcessMgr[] mgrs=iter.get_next_n_sequence(t,0); 839 if (mgrs!=null) { 840 for (int i=0; i<mgrs.length; i++) { 841 String mgrName=mgrs[i].name(t); 842 SharkUtilities.reevalAssignments(t,mgrName); 843 } 844 } 845 } 846 847 public void reevaluateAssignments (String pkgId,String pDefId) throws BaseException, NotConnected { 848 SharkTransaction t = null; 849 try { 850 t = SharkUtilities.createTransaction(); 851 reevaluateAssignments(t,pkgId,pDefId); 852 SharkUtilities.commitTransaction(t); 853 } catch (RootException e) { 854 SharkUtilities.rollbackTransaction(t,e); 855 if (e instanceof NotConnected) 856 throw (NotConnected)e; 857 else if (e instanceof BaseException) 858 throw (BaseException)e; 859 else 860 throw new BaseException(e); 861 } finally { 862 SharkUtilities.releaseTransaction(t); 863 } 864 } 865 866 public void reevaluateAssignments (SharkTransaction t,String pkgId,String pDefId) throws BaseException, NotConnected { 867 if (!connected) { 868 throw new NotConnected("The connection is not established..."); 869 } 870 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 871 if (sm!=null) { 872 try { 873 sm.check_executionadministration_reevaluateAssignments(t,userId); 874 } catch (Exception ex) { 875 throw new BaseException(ex); 876 } 877 } 878 WfProcessMgrIterator iter=SharkEngineManager.getInstance(). 879 getObjectFactory().createProcessMgrIteratorWrapper(t,userId); 880 String query="packageId.equals(\""+pkgId+"\") && processDefinitionId.equals(\""+pDefId+"\")"; 881 try { 882 iter.set_query_expression(t,query); 883 } catch (Exception ex) { 884 throw new BaseException(ex); 885 } 886 WfProcessMgr[] mgrs=iter.get_next_n_sequence(t,0); 887 if (mgrs!=null) { 888 for (int i=0; i<mgrs.length; i++) { 889 String mgrName=mgrs[i].name(t); 890 SharkUtilities.reevalAssignments(t,mgrName); 891 } 892 } 893 } 894 895 public void reevaluateAssignments (String pkgId,String pDefId,String aDefId) throws BaseException, NotConnected { 896 SharkTransaction t = null; 897 try { 898 t = SharkUtilities.createTransaction(); 899 reevaluateAssignments(t,pkgId,pDefId,aDefId); 900 SharkUtilities.commitTransaction(t); 901 } catch (RootException e) { 902 SharkUtilities.rollbackTransaction(t,e); 903 if (e instanceof NotConnected) 904 throw (NotConnected)e; 905 else if (e instanceof BaseException) 906 throw (BaseException)e; 907 else 908 throw new BaseException(e); 909 } finally { 910 SharkUtilities.releaseTransaction(t); 911 } 912 } 913 914 public void reevaluateAssignments (SharkTransaction t,String pkgId,String pDefId,String aDefId) throws BaseException, NotConnected { 915 if (!connected) { 916 throw new NotConnected("The connection is not established..."); 917 } 918 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 919 if (sm!=null) { 920 try { 921 sm.check_executionadministration_reevaluateAssignments(t,userId); 922 } catch (Exception ex) { 923 throw new BaseException(ex); 924 } 925 } 926 927 WfProcessMgrIterator iter=SharkEngineManager.getInstance(). 928 getObjectFactory().createProcessMgrIteratorWrapper(t,userId); 929 String query="packageId.equals(\""+pkgId+"\") && processDefinitionId.equals(\""+pDefId+"\")"; 930 try { 931 iter.set_query_expression(t,query); 932 } catch (Exception ex) { 933 throw new BaseException(ex); 934 } 935 WfProcessMgr[] mgrs=iter.get_next_n_sequence(t,0); 936 if (mgrs!=null) { 937 for (int i=0; i<mgrs.length; i++) { 938 String mgrName=mgrs[i].name(t); 939 940 List l=SharkUtilities.createProcessMgrsProcessWrappers(t,userId,mgrName); 941 Iterator it=l.iterator(); 942 while (it.hasNext()) { 943 WfProcess p=(WfProcess)it.next(); 944 String procId=p.key(t); 945 WfActivityIterator actIter=SharkEngineManager 946 .getInstance() 947 .getObjectFactory() 948 .createActivityIteratorWrapper(t,userId,procId); 949 String actQuery="definitionId.equals(\""+aDefId+"\")"; 950 try { 951 actIter.set_query_expression(t,actQuery); 952 } catch (Exception ex) { 953 throw new BaseException(ex); 954 } 955 WfActivity[] acts=actIter.get_next_n_sequence(t,0); 956 for (int j=0; j<acts.length; j++) { 957 WfActivity act=acts[j]; 958 WfActivityInternal aint=SharkUtilities.getActivity(t,procId,act.key(t)); 959 aint.reevaluateAssignments(t); 960 } 961 } 962 } 963 } 964 } 965 966 public void deleteClosedProcesses () throws BaseException, NotConnected { 967 SharkTransaction t = null; 968 try { 969 t = SharkUtilities.createTransaction(); 970 deleteClosedProcesses(t); 971 SharkUtilities.commitTransaction(t); 972 } catch (RootException e) { 973 SharkUtilities.rollbackTransaction(t,e); 974 if (e instanceof NotConnected) 975 throw (NotConnected)e; 976 else if (e instanceof BaseException) 977 throw (BaseException)e; 978 else 979 throw new BaseException(e); 980 } finally { 981 SharkUtilities.releaseTransaction(t); 982 } 983 } 984 985 public void deleteClosedProcesses (SharkTransaction t) throws BaseException, NotConnected { 986 if (!connected) { 987 throw new NotConnected("The connection is not established..."); 988 } 989 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 990 if (sm!=null) { 991 try { 992 sm.check_executionadministration_reevaluateAssignments(t,userId); 993 } catch (Exception ex) { 994 throw new BaseException(ex); 995 } 996 } 997 LockMaster lm=SharkEngineManager.getInstance().getLockMaster(); 998 try { 999 PersistentManagerInterface ipm=SharkEngineManager.getInstance().getInstancePersistenceManager(); 1000 List procs=ipm.getAllFinishedProcesses(t); 1001 cus.info("ExecutionAdmin -> Deleting "+procs.size()+" closed processes:"); 1002 for (Iterator i=procs.iterator(); i.hasNext();) { 1003 ProcessPersistenceInterface po=(ProcessPersistenceInterface)i.next(); 1004 if (po.getActivityRequesterId()!=null) { 1005 ActivityPersistenceInterface apo=ipm.restoreActivity(po.getActivityRequesterId(),t); 1006 if (apo!=null && apo.getState().startsWith(SharkConstants.STATEPREFIX_OPEN)) { 1007 cus.info("... Process " + po.getId()+" can't be deleted yet because it has active activity requester!"); 1008 continue; 1009 } 1010 } 1011 cus.info("... Deleting process "+po.getId()); 1012 if (lm!=null) { 1013 lm.lock(t,po.getId()); 1014 } 1015 ipm.deleteProcess(po.getId(),true,t); 1016 CacheMgr cm=SharkEngineManager.getInstance().getCacheManager(); 1017 if (cm!=null) { 1018 cm.getProcessCache().remove(po.getId()); 1019 } 1020 } 1021 } catch (Exception ex) { 1022 throw new BaseException(ex); 1023 } 1024 } 1025 1026 public void deleteClosedProcesses (java.util.Date closedBefore) throws BaseException, NotConnected { 1027 SharkTransaction t = null; 1028 try { 1029 t = SharkUtilities.createTransaction(); 1030 deleteClosedProcesses(t,closedBefore); 1031 SharkUtilities.commitTransaction(t); 1032 } catch (RootException e) { 1033 SharkUtilities.rollbackTransaction(t,e); 1034 if (e instanceof NotConnected) 1035 throw (NotConnected)e; 1036 else if (e instanceof BaseException) 1037 throw (BaseException)e; 1038 else 1039 throw new BaseException(e); 1040 } finally { 1041 SharkUtilities.releaseTransaction(t); 1042 } 1043 } 1044 1045 public void deleteClosedProcesses (SharkTransaction t,java.util.Date closedBefore) throws BaseException, NotConnected { 1046 if (!connected) { 1047 throw new NotConnected("The connection is not established..."); 1048 } 1049 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 1050 if (sm!=null) { 1051 try { 1052 sm.check_executionadministration_deleteClosedProcesses(t,userId); 1053 } catch (Exception ex) { 1054 throw new BaseException(ex); 1055 } 1056 } 1057 LockMaster lm=SharkEngineManager.getInstance().getLockMaster(); 1058 try { 1059 PersistentManagerInterface ipm=SharkEngineManager.getInstance().getInstancePersistenceManager(); 1060 List procs=ipm.getAllFinishedProcesses(t,closedBefore); 1061 cus.info("ExecutionAdmin -> Deleting "+procs.size()+" processes closed before "+closedBefore+":"); 1062 for (Iterator i=procs.iterator(); i.hasNext();) { 1063 ProcessPersistenceInterface po=(ProcessPersistenceInterface)i.next(); 1064 if (po.getActivityRequesterId()!=null) { 1065 ActivityPersistenceInterface apo=ipm.restoreActivity(po.getActivityRequesterId(),t); 1066 if (apo!=null && apo.getState().startsWith(SharkConstants.STATEPREFIX_OPEN)) { 1067 cus.info("... Process " + po.getId()+" can't be deleted yet because it has active activity requester!"); 1068 continue; 1069 } 1070 } 1071 cus.info("... Deleting process "+po.getId()); 1072 if (lm!=null) { 1073 lm.lock(t,po.getId()); 1074 } 1075 ipm.deleteProcess(po.getId(),true,t); 1076 CacheMgr cm=SharkEngineManager.getInstance().getCacheManager(); 1077 if (cm!=null) { 1078 cm.getProcessCache().remove(po.getId()); 1079 } 1080 } 1081 } catch (Exception ex) { 1082 throw new BaseException(ex); 1083 } 1084 } 1085 1086 public void deleteClosedProcesses (String pkgId) throws BaseException, NotConnected { 1087 SharkTransaction t = null; 1088 try { 1089 t = SharkUtilities.createTransaction(); 1090 deleteClosedProcesses(t,pkgId); 1091 SharkUtilities.commitTransaction(t); 1092 } catch (RootException e) { 1093 SharkUtilities.rollbackTransaction(t,e); 1094 if (e instanceof NotConnected) 1095 throw (NotConnected)e; 1096 else if (e instanceof BaseException) 1097 throw (BaseException)e; 1098 else 1099 throw new BaseException(e); 1100 } finally { 1101 SharkUtilities.releaseTransaction(t); 1102 } 1103 } 1104 1105 public void deleteClosedProcesses (SharkTransaction t,String pkgId) throws BaseException, NotConnected { 1106 if (!connected) { 1107 throw new NotConnected("The connection is not established..."); 1108 } 1109 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 1110 if (sm!=null) { 1111 try { 1112 sm.check_executionadministration_deleteClosedProcesses(t,userId); 1113 } catch (Exception ex) { 1114 throw new BaseException(ex); 1115 } 1116 } 1117 LockMaster lm=SharkEngineManager.getInstance().getLockMaster(); 1118 try { 1119 PersistentManagerInterface ipm=SharkEngineManager.getInstance().getInstancePersistenceManager(); 1120 List procs=ipm.getAllFinishedProcesses(t,pkgId); 1121 cus.info("ExecutionAdmin -> Deleting "+procs.size()+" closed processes for package Id="+pkgId+":"); 1122 for (Iterator i=procs.iterator(); i.hasNext();) { 1123 ProcessPersistenceInterface po=(ProcessPersistenceInterface)i.next(); 1124 if (po.getActivityRequesterId()!=null) { 1125 ActivityPersistenceInterface apo=ipm.restoreActivity(po.getActivityRequesterId(),t); 1126 if (apo!=null && apo.getState().startsWith(SharkConstants.STATEPREFIX_OPEN)) { 1127 cus.info("... Process " + po.getId()+" can't be deleted yet because it has active activity requester!"); 1128 continue; 1129 } 1130 } 1131 cus.info("... Deleting process "+po.getId()); 1132 if (lm!=null) { 1133 lm.lock(t,po.getId()); 1134 } 1135 ipm.deleteProcess(po.getId(),true,t); 1136 CacheMgr cm=SharkEngineManager.getInstance().getCacheManager(); 1137 if (cm!=null) { 1138 cm.getProcessCache().remove(po.getId()); 1139 } 1140 } 1141 } catch (Exception ex) { 1142 throw new BaseException(ex); 1143 } 1144 } 1145 1146 public void deleteClosedProcessesForMgr (String mgrName) throws BaseException, NotConnected { 1147 SharkTransaction t=null; 1148 try { 1149 t = SharkUtilities.createTransaction(); 1150 deleteClosedProcessesForMgr(t,mgrName); 1151 SharkUtilities.commitTransaction(t); 1152 } catch (RootException e) { 1153 SharkUtilities.rollbackTransaction(t,e); 1154 if (e instanceof NotConnected) 1155 throw (NotConnected)e; 1156 else if (e instanceof BaseException) 1157 throw (BaseException)e; 1158 else 1159 throw new BaseException(e); 1160 } finally { 1161 SharkUtilities.releaseTransaction(t); 1162 } 1163 } 1164 1165 public void deleteClosedProcessesForMgr (SharkTransaction t,String mgrName) throws BaseException, NotConnected { 1166 if (!connected) { 1167 throw new NotConnected("The connection is not established..."); 1168 } 1169 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 1170 if (sm!=null) { 1171 try { 1172 sm.check_executionadministration_deleteClosedProcesses(t,userId); 1173 } catch (Exception ex) { 1174 throw new BaseException(ex); 1175 } 1176 } 1177 LockMaster lm=SharkEngineManager.getInstance().getLockMaster(); 1178 try { 1179 String pkgId=SharkUtilities.getProcessMgrPkgId(mgrName); 1180 String pDefId=SharkUtilities.getProcessMgrProcDefId(mgrName); 1181 String pkgVer=SharkUtilities.getProcessMgrVersion(mgrName); 1182 1183 1184 PersistentManagerInterface ipm=SharkEngineManager.getInstance().getInstancePersistenceManager(); 1185 List procs=ipm.getAllFinishedProcesses(t,pkgId,pDefId,pkgVer); 1186 cus.info("ExecutionAdmin -> Deleting "+procs.size()+" closed processes for package Id="+pkgId+", version="+pkgVer+", pDefId= :"+pDefId); 1187 for (Iterator i=procs.iterator(); i.hasNext();) { 1188 ProcessPersistenceInterface po=(ProcessPersistenceInterface)i.next(); 1189 if (po.getActivityRequesterId()!=null) { 1190 ActivityPersistenceInterface apo=ipm.restoreActivity(po.getActivityRequesterId(),t); 1191 if (apo!=null && apo.getState().startsWith(SharkConstants.STATEPREFIX_OPEN)) { 1192 cus.info("... Process " + po.getId()+" can't be deleted yet because it has active activity requester!"); 1193 continue; 1194 } 1195 } 1196 cus.info("... Deleting process "+po.getId()); 1197 if (lm!=null) { 1198 lm.lock(t,po.getId()); 1199 } 1200 ipm.deleteProcess(po.getId(),true,t); 1201 CacheMgr cm=SharkEngineManager.getInstance().getCacheManager(); 1202 if (cm!=null) { 1203 cm.getProcessCache().remove(po.getId()); 1204 } 1205 } 1206 } catch (Exception ex) { 1207 throw new BaseException(ex); 1208 } 1209 } 1210 1211 public void deleteClosedProcessesWithVersion (String pkgId,String pkgVer) throws BaseException, NotConnected { 1212 SharkTransaction t=null; 1213 try { 1214 t = SharkUtilities.createTransaction(); 1215 deleteClosedProcessesWithVersion(t,pkgId,pkgVer); 1216 SharkUtilities.commitTransaction(t); 1217 } catch (RootException e) { 1218 SharkUtilities.rollbackTransaction(t,e); 1219 if (e instanceof NotConnected) 1220 throw (NotConnected)e; 1221 else if (e instanceof BaseException) 1222 throw (BaseException)e; 1223 else 1224 throw new BaseException(e); 1225 } finally { 1226 SharkUtilities.releaseTransaction(t); 1227 } 1228 } 1229 1230 public void deleteClosedProcessesWithVersion (SharkTransaction t,String pkgId,String pkgVer) throws BaseException, NotConnected { 1231 if (!connected) { 1232 throw new NotConnected("The connection is not established..."); 1233 } 1234 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 1235 if (sm!=null) { 1236 try { 1237 sm.check_executionadministration_deleteClosedProcesses(t,userId); 1238 } catch (Exception ex) { 1239 throw new BaseException(ex); 1240 } 1241 } 1242 LockMaster lm=SharkEngineManager.getInstance().getLockMaster(); 1243 try { 1244 PersistentManagerInterface ipm=SharkEngineManager.getInstance().getInstancePersistenceManager(); 1245 List procs=ipm.getAllFinishedProcesses(t,pkgId,null,pkgVer); 1246 cus.info("ExecutionAdmin -> Deleting "+procs.size()+" closed processes for package Id="+pkgId+", version="+pkgVer+" :"); 1247 for (Iterator i=procs.iterator(); i.hasNext();) { 1248 ProcessPersistenceInterface po=(ProcessPersistenceInterface)i.next(); 1249 if (po.getActivityRequesterId()!=null) { 1250 ActivityPersistenceInterface apo=ipm.restoreActivity(po.getActivityRequesterId(),t); 1251 if (apo!=null && apo.getState().startsWith(SharkConstants.STATEPREFIX_OPEN)) { 1252 cus.info("... Process " + po.getId()+" can't be deleted yet because it has active activity requester!"); 1253 continue; 1254 } 1255 } 1256 cus.info("... Deleting process "+po.getId()); 1257 if (lm!=null) { 1258 lm.lock(t,po.getId()); 1259 } 1260 ipm.deleteProcess(po.getId(),true,t); 1261 CacheMgr cm=SharkEngineManager.getInstance().getCacheManager(); 1262 if (cm!=null) { 1263 cm.getProcessCache().remove(po.getId()); 1264 } 1265 } 1266 } catch (Exception ex) { 1267 throw new BaseException(ex); 1268 } 1269 } 1270 1271 public void deleteClosedProcesses (String pkgId,String pDefId) throws BaseException, NotConnected { 1272 SharkTransaction t = null; 1273 try { 1274 t = SharkUtilities.createTransaction(); 1275 deleteClosedProcesses(t,pkgId,pDefId); 1276 SharkUtilities.commitTransaction(t); 1277 } catch (RootException e) { 1278 SharkUtilities.rollbackTransaction(t,e); 1279 if (e instanceof NotConnected) 1280 throw (NotConnected)e; 1281 else if (e instanceof BaseException) 1282 throw (BaseException)e; 1283 else 1284 throw new BaseException(e); 1285 } finally { 1286 SharkUtilities.releaseTransaction(t); 1287 } 1288 } 1289 1290 public void deleteClosedProcesses (SharkTransaction t,String pkgId,String pDefId) throws BaseException, NotConnected { 1291 if (!connected) { 1292 throw new NotConnected("The connection is not established..."); 1293 } 1294 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 1295 if (sm!=null) { 1296 try { 1297 sm.check_executionadministration_deleteClosedProcesses(t,userId); 1298 } catch (Exception ex) { 1299 throw new BaseException(ex); 1300 } 1301 } 1302 LockMaster lm=SharkEngineManager.getInstance().getLockMaster(); 1303 try { 1304 PersistentManagerInterface ipm=SharkEngineManager.getInstance().getInstancePersistenceManager(); 1305 List procs=ipm.getAllFinishedProcesses(t,pkgId,pDefId); 1306 cus.info("ExecutionAdmin -> Deleting "+procs.size()+" closed processes for packageId="+pkgId+"and processDefinitionId="+pDefId+":"); 1307 for (Iterator i=procs.iterator(); i.hasNext();) { 1308 ProcessPersistenceInterface po=(ProcessPersistenceInterface)i.next(); 1309 if (po.getActivityRequesterId()!=null) { 1310 ActivityPersistenceInterface apo=ipm.restoreActivity(po.getActivityRequesterId(),t); 1311 if (apo!=null && apo.getState().startsWith(SharkConstants.STATEPREFIX_OPEN)) { 1312 cus.info("... Process " + po.getId()+" can't be deleted yet because it has active activity requester!"); 1313 continue; 1314 } 1315 } 1316 cus.info("... Deleting process "+po.getId()); 1317 if (lm!=null) { 1318 lm.lock(t,po.getId()); 1319 } 1320 ipm.deleteProcess(po.getId(),true,t); 1321 CacheMgr cm=SharkEngineManager.getInstance().getCacheManager(); 1322 if (cm!=null) { 1323 cm.getProcessCache().remove(po.getId()); 1324 } 1325 } 1326 } catch (Exception ex) { 1327 throw new BaseException(ex); 1328 } 1329 } 1330 1331 public void deleteClosedProcess (String procId) throws BaseException, NotConnected { 1332 SharkTransaction t = null; 1333 try { 1334 t = SharkUtilities.createTransaction(); 1335 deleteClosedProcess(t, procId); 1336 SharkUtilities.commitTransaction(t); 1337 } catch (RootException e) { 1338 SharkUtilities.rollbackTransaction(t,e); 1339 if (e instanceof NotConnected) 1340 throw (NotConnected)e; 1341 else if (e instanceof BaseException) 1342 throw (BaseException)e; 1343 else 1344 throw new BaseException(e); 1345 } finally { 1346 SharkUtilities.releaseTransaction(t); 1347 } 1348 } 1349 1350 public void deleteClosedProcess (SharkTransaction t,String procId) throws BaseException, NotConnected { 1351 if (!connected) { 1352 throw new NotConnected("The connection is not established..."); 1353 } 1354 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 1355 if (sm!=null) { 1356 try { 1357 sm.check_executionadministration_deleteClosedProcesses(t,userId); 1358 } catch (Exception ex) { 1359 throw new BaseException(ex); 1360 } 1361 } 1362 LockMaster lm=SharkEngineManager.getInstance().getLockMaster(); 1363 try { 1364 1365 PersistentManagerInterface ipm=SharkEngineManager.getInstance().getInstancePersistenceManager(); 1366 ProcessPersistenceInterface po=ipm.restoreProcess(procId,t); 1367 if (po.getState().startsWith(SharkConstants.STATEPREFIX_OPEN)) { 1368 throw new BaseException("Can't delete processes which are not closed"); 1369 } 1370 if (po.getActivityRequesterId()!=null) { 1371 ActivityPersistenceInterface apo=ipm.restoreActivity(po.getActivityRequesterId(),t); 1372 if (apo!=null && apo.getState().startsWith(SharkConstants.STATEPREFIX_OPEN)) { 1373 cus.info("... Process " + po.getId()+" can't be deleted yet because it has active activity requester!"); 1374 return; 1375 } 1376 } 1377 cus.info("... Deleting process "+po.getId()); 1378 if (lm!=null) { 1379 lm.lock(t,po.getId()); 1380 } 1381 ipm.deleteProcess(po.getId(),true,t); 1382 CacheMgr cm=SharkEngineManager.getInstance().getCacheManager(); 1383 if (cm!=null) { 1384 cm.getProcessCache().remove(po.getId()); 1385 } 1386 } catch (Exception ex) { 1387 throw new BaseException("Problems with deleting process for Id "+procId,ex); 1388 } 1389 } 1390 1391 public String [] deleteClosedProcessesForMgr(String mgrName, 1392 int procPerTrans, 1393 int failures2ignore) throws BaseException, 1394 NotConnected { 1395 if (!connected) { throw new NotConnected("The connection is not established..."); } 1396 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 1397 if (sm!=null) { 1398 SharkTransaction t=null; 1399 try { 1400 t = SharkUtilities.createTransaction(); 1401 sm.check_executionadministration_deleteClosedProcesses(t,userId); 1402 SharkUtilities.commitTransaction(t); 1403 } catch (RootException e) { 1404 SharkUtilities.rollbackTransaction(t,e); 1405 if (e instanceof NotConnected) 1406 throw (NotConnected)e; 1407 else if (e instanceof BaseException) 1408 throw (BaseException)e; 1409 else 1410 throw new BaseException(e); 1411 } finally { 1412 SharkUtilities.releaseTransaction(t); 1413 } 1414 } 1415 List instancesFailed2check = new ArrayList (); 1416 Iterator iterProcesses = null; 1417 List currentBatch = null; 1418 1419 List procs=null; 1420 SharkTransaction t = null; 1421 PersistentManagerInterface ipm=SharkEngineManager.getInstance().getInstancePersistenceManager(); 1422 try { 1423 t = SharkUtilities.createTransaction(); 1424 procs = ipm.getAllFinishedProcesses(t); 1425 cus.info("ExecutionAdmin -> Deleting " 1426 + procs.size() + " closed processes:"); 1427 } catch (RootException e) { 1428 SharkUtilities.rollbackTransaction(t,e); 1429 throw new BaseException(e); 1430 } finally { 1431 SharkUtilities.releaseTransaction(t); 1432 } 1433 LockMaster lm=SharkEngineManager.getInstance().getLockMaster(); 1434 do { 1435 t = null; 1436 currentBatch = new ArrayList (); 1437 try { 1438 t = SharkUtilities.createTransaction(); 1439 String pkgId = SharkUtilities.getProcessMgrPkgId(mgrName); 1440 String pDefId = SharkUtilities.getProcessMgrProcDefId(mgrName); 1441 String pkgVer = SharkUtilities.getProcessMgrVersion(mgrName); 1442 1443 iterProcesses = procs.iterator(); 1444 for (int n = 0; n < procPerTrans; ++n) { 1445 if (!iterProcesses.hasNext()) { 1446 break; 1447 } 1448 ProcessPersistenceInterface po = (ProcessPersistenceInterface) iterProcesses.next(); 1449 iterProcesses.remove(); 1450 if (po.getActivityRequesterId()!=null) { 1451 ActivityPersistenceInterface apo=ipm.restoreActivity(po.getActivityRequesterId(),t); 1452 if (apo!=null && apo.getState().startsWith(SharkConstants.STATEPREFIX_OPEN)) { 1453 cus.info("... Process " + po.getId()+" can't be deleted yet because it has active activity requester!"); 1454 continue; 1455 } 1456 } 1457 cus.info("... Deleting process "+po.getId()); 1458 if (lm!=null) { 1459 lm.lock(t,po.getId()); 1460 } 1461 ipm.deleteProcess(po.getId(),true,t); 1462 CacheMgr cm=SharkEngineManager.getInstance().getCacheManager(); 1463 if (cm!=null) { 1464 cm.getProcessCache().remove(po.getId()); 1465 } 1466 currentBatch.add(po.getId()); 1467 } 1468 SharkUtilities.commitTransaction(t); 1469 } catch (RootException _) { 1470 SharkUtilities.rollbackTransaction(t,_); 1471 instancesFailed2check.addAll(currentBatch); 1472 } finally { 1474 SharkUtilities.releaseTransaction(t); 1475 } 1476 System.err.println("\ttransaction finished: batch size:"+currentBatch.size()); 1477 } while (instancesFailed2check.size() <= failures2ignore 1478 && iterProcesses.hasNext()); 1479 String [] ret = new String [instancesFailed2check.size()]; 1480 instancesFailed2check.toArray(ret); 1481 System.err.println(" deleting finished: failed:"+ret.length); 1482 return ret; 1483 } 1484 1485 public String [] deleteClosedProcesses ( 1486 int procPerTrans, 1487 int failures2ignore) throws BaseException, NotConnected { 1488 if (!connected) { throw new NotConnected("The connection is not established..."); } 1489 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 1490 if (sm!=null) { 1491 SharkTransaction t=null; 1492 try { 1493 t = SharkUtilities.createTransaction(); 1494 sm.check_executionadministration_deleteClosedProcesses(t,userId); 1495 SharkUtilities.commitTransaction(t); 1496 } catch (RootException e) { 1497 SharkUtilities.rollbackTransaction(t,e); 1498 if (e instanceof NotConnected) 1499 throw (NotConnected)e; 1500 else if (e instanceof BaseException) 1501 throw (BaseException)e; 1502 else 1503 throw new BaseException(e); 1504 } finally { 1505 SharkUtilities.releaseTransaction(t); 1506 } 1507 } 1508 List instancesFailed2check = new ArrayList (); 1509 Iterator iterProcesses = null; 1510 List currentBatch = null; 1511 1512 List procs=null; 1513 SharkTransaction t = null; 1514 PersistentManagerInterface ipm=SharkEngineManager.getInstance().getInstancePersistenceManager(); 1515 try { 1517 t = SharkUtilities.createTransaction(); 1518 procs = ipm.getAllFinishedProcesses(t); 1519 cus.info("ExecutionAdmin -> Deleting " 1520 + procs.size() + " closed processes:"); 1521 } catch (RootException e) { 1522 SharkUtilities.rollbackTransaction(t,e); 1523 throw new BaseException(e); 1524 } finally { 1525 SharkUtilities.releaseTransaction(t); 1526 } 1527 LockMaster lm=SharkEngineManager.getInstance().getLockMaster(); 1529 1532 do { 1533 t=null; 1535 currentBatch = new ArrayList (); 1536 try { 1537 t = SharkUtilities.createTransaction(); 1538 1539 iterProcesses = procs.iterator(); 1540 for (int n = 0; n < procPerTrans; ++n) { 1541 if (!iterProcesses.hasNext()) { 1543 break; 1544 } 1545 ProcessPersistenceInterface po = (ProcessPersistenceInterface) iterProcesses.next(); 1546 iterProcesses.remove(); 1547 1548 1555 cus.info("... Deleting process "+po.getId()); 1556 if (lm!=null) { 1557 lm.lock(t,po.getId()); 1558 } 1559 ipm.deleteProcess(po.getId(),true,t); 1562 CacheMgr cm=SharkEngineManager.getInstance().getCacheManager(); 1565 if (cm!=null) { 1566 cm.getProcessCache().remove(po.getId()); 1567 } 1568 currentBatch.add(po.getId()); 1569 1572 } 1573 SharkUtilities.commitTransaction(t); 1575 } catch (RootException _) { 1578 SharkUtilities.rollbackTransaction(t,_); 1579 instancesFailed2check.addAll(currentBatch); 1580 } finally { 1583 SharkUtilities.releaseTransaction(t); 1584 } 1585 System.err.println("\ttransaction finished: batch size:"+currentBatch.size()); 1587 } while (instancesFailed2check.size() <= failures2ignore 1588 && iterProcesses.hasNext()); 1589 String [] ret = new String [instancesFailed2check.size()]; 1590 instancesFailed2check.toArray(ret); 1591 System.err.println(" deleting finished: failed:"+ret.length); 1592 return ret; 1594 } 1595 1596 public Map getProcessMgrInputSignature(String name) throws BaseException, NotConnected { 1597 Map ret = null; 1598 SharkTransaction t = null; 1599 try { 1600 t = SharkUtilities.createTransaction(); 1601 ret = getProcessMgrInputSignature(t, name); 1602 } catch (RootException e) { 1604 SharkUtilities.emptyCaches(t); 1606 if (e instanceof NotConnected) 1607 throw (NotConnected)e; 1608 else if (e instanceof BaseException) 1609 throw (BaseException)e; 1610 else 1611 throw new BaseException(e); 1612 } finally { 1613 SharkUtilities.releaseTransaction(t); 1614 } 1615 return ret; 1616 } 1617 1618 public Map getProcessMgrInputSignature(SharkTransaction t, String name) throws BaseException, NotConnected { 1619 return getProcessMgrInputSignature(t, 1620 SharkUtilities.getProcessMgrPkgId(name), 1621 SharkUtilities.getProcessMgrVersion(name), 1622 SharkUtilities.getProcessMgrProcDefId(name)); 1623 } 1624 1625 public Map getProcessMgrInputSignature(String pkgId, String pDefId) throws BaseException, NotConnected { 1626 Map ret = null; 1627 SharkTransaction t = null; 1628 try { 1629 t = SharkUtilities.createTransaction(); 1630 ret = getProcessMgrInputSignature(t, pkgId, pDefId); 1631 } catch (RootException e) { 1633 SharkUtilities.emptyCaches(t); 1635 if (e instanceof NotConnected) 1636 throw (NotConnected)e; 1637 else if (e instanceof BaseException) 1638 throw (BaseException)e; 1639 else 1640 throw new BaseException(e); 1641 } finally { 1642 SharkUtilities.releaseTransaction(t); 1643 } 1644 return ret; 1645 } 1646 1647 public Map getProcessMgrInputSignature(SharkTransaction t, String pkgId, String pDefId) throws BaseException, NotConnected { 1648 return getProcessMgrInputSignature(t, 1649 pkgId, 1650 SharkUtilities.getCurrentPkgVersion(pkgId, 1651 false), 1652 pDefId); 1653 1654 } 1655 1656 public Map getProcessMgrInputSignature(String pkgId, String pkgVer, String pDefId) throws BaseException, NotConnected { 1657 Map ret = null; 1658 SharkTransaction t = null; 1659 try { 1660 t = SharkUtilities.createTransaction(); 1661 ret = getProcessMgrInputSignature(t, pkgId, pkgVer, pDefId); 1662 } catch (RootException e) { 1664 SharkUtilities.emptyCaches(t); 1666 if (e instanceof NotConnected) 1667 throw (NotConnected)e; 1668 else if (e instanceof BaseException) 1669 throw (BaseException)e; 1670 else 1671 throw new BaseException(e); 1672 } finally { 1673 SharkUtilities.releaseTransaction(t); 1674 } 1675 return ret; 1676 } 1677 1678 public Map getProcessMgrInputSignature(SharkTransaction t, 1679 String pkgId, 1680 String pkgVer, 1681 String pDefId) throws BaseException, 1682 NotConnected { 1683 if (!connected) { 1684 throw new NotConnected("The connection is not established..."); 1685 } 1686 try { 1687 String mgrName=SharkUtilities.createProcessMgrKey(pkgId,pkgVer,pDefId); 1688 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 1689 if (sm!=null) { 1690 sm.check_executionadministration_getProcessMgr(t,mgrName,userId); 1691 } 1692 WfProcessMgrInternal a = SharkUtilities.getProcessMgr(t, mgrName); 1693 if (null != a) { 1694 return a.input_signature(t); 1695 } 1696 return null; 1697 } catch (Exception ex) { 1698 throw new BaseException(ex); 1699 } 1700 } 1701 1702 public Object getProcessContext(String procId, String variableName) throws BaseException, NotConnected { 1703 Object ret = null; 1704 SharkTransaction t = null; 1705 try { 1706 t = SharkUtilities.createTransaction(); 1707 ret = getProcessContext(t, procId, variableName); 1708 } catch (RootException e) { 1710 SharkUtilities.emptyCaches(t); 1712 if (e instanceof NotConnected) 1713 throw (NotConnected)e; 1714 else if (e instanceof BaseException) 1715 throw (BaseException)e; 1716 else 1717 throw new BaseException(e); 1718 } finally { 1719 SharkUtilities.releaseTransaction(t); 1720 } 1721 return ret; 1722 } 1723 1724 public Object getProcessContext(SharkTransaction t, 1725 String procId, 1726 String variableName) throws BaseException, 1727 NotConnected { 1728 if (!connected) { 1729 throw new NotConnected("The connection is not established..."); 1730 } 1731 try { 1732 1738 PersistentManagerInterface ipm = SharkEngineManager.getInstance() 1739 .getInstancePersistenceManager(); 1740 ProcessVariablePersistenceInterface a = ipm.createProcessVariable(); 1741 a.setDefinitionId(variableName); 1742 a.setProcessId(procId); 1743 if (ipm.restore(a, t)) { 1744 return a.getValue(); 1745 } 1746 } catch (PersistenceException ex) { 1747 throw new BaseException(ex); 1748 } 1749 throw new BaseException("variable not found"); 1750 } 1751 1752 public Map getProcessContext(String procId, String [] variableNames) throws BaseException, NotConnected { 1753 Map ret = null; 1754 SharkTransaction t = null; 1755 try { 1756 t = SharkUtilities.createTransaction(); 1757 ret = getProcessContext(t, procId, variableNames); 1758 } catch (RootException e) { 1760 SharkUtilities.emptyCaches(t); 1762 if (e instanceof NotConnected) 1763 throw (NotConnected)e; 1764 else if (e instanceof BaseException) 1765 throw (BaseException)e; 1766 else 1767 throw new BaseException(e); 1768 } finally { 1769 SharkUtilities.releaseTransaction(t); 1770 } 1771 return ret; 1772 } 1773 1774 public Map getProcessContext(SharkTransaction t, String procId, String [] variableNames) throws BaseException, NotConnected { 1775 if (!connected) { 1776 throw new NotConnected("The connection is not established..."); 1777 } 1778 Map ret = new HashMap (); 1779 1785 for (int i = 0; i < variableNames.length; i++) { 1786 ret.put(variableNames[i],getProcessContext(t,procId,variableNames[i])); 1787 } 1788 return ret; 1789 } 1790 1791 public Object getActivityContext(String procId, String actId, String variableName) throws BaseException, NotConnected { 1792 Object ret = null; 1793 SharkTransaction t = null; 1794 try { 1795 t = SharkUtilities.createTransaction(); 1796 ret = getActivityContext(t, procId, actId, variableName); 1797 } catch (RootException e) { 1799 SharkUtilities.emptyCaches(t); 1801 if (e instanceof NotConnected) 1802 throw (NotConnected)e; 1803 else if (e instanceof BaseException) 1804 throw (BaseException)e; 1805 else 1806 throw new BaseException(e); 1807 } finally { 1808 SharkUtilities.releaseTransaction(t); 1809 } 1810 return ret; 1811 } 1812 1813 public Object getActivityContext(SharkTransaction t, String procId, String actId, String variableName) throws BaseException, NotConnected { 1814 if (!connected) { 1815 throw new NotConnected("The connection is not established..."); 1816 } 1817 try { 1818 1824 PersistentManagerInterface ipm = SharkEngineManager.getInstance() 1825 .getInstancePersistenceManager(); 1826 ActivityVariablePersistenceInterface a = ipm.createActivityVariable(); 1827 a.setDefinitionId(variableName); 1828 a.setActivityId(actId); 1829 if (ipm.restore(a, t)) { 1830 return a.getValue(); 1831 } 1832 } catch (PersistenceException ex) { 1833 throw new BaseException(ex); 1834 } 1835 throw new BaseException("variable not found"); 1836 } 1837 1838 public Map getActivityContext(String procId, 1839 String actId, 1840 String [] variableNames) throws BaseException, 1841 NotConnected { 1842 Map ret = null; 1843 SharkTransaction t = null; 1844 try { 1845 t = SharkUtilities.createTransaction(); 1846 ret = getActivityContext(t, procId, actId, variableNames); 1847 } catch (RootException e) { 1849 SharkUtilities.emptyCaches(t); 1851 if (e instanceof NotConnected) 1852 throw (NotConnected) e; 1853 else if (e instanceof BaseException) 1854 throw (BaseException) e; 1855 else 1856 throw new BaseException(e); 1857 } finally { 1858 SharkUtilities.releaseTransaction(t); 1859 } 1860 return ret; 1861 } 1862 1863 public Map getActivityContext(SharkTransaction t, String procId, String actId, String [] variableNames) throws BaseException, NotConnected { 1864 if (!connected) { 1865 throw new NotConnected("The connection is not established..."); 1866 } 1867 Map ret = new HashMap (); 1868 1874 for (int i = 0; i < variableNames.length; i++) { 1875 ret.put(variableNames[i],getActivityContext(t,procId, actId,variableNames[i])); 1876 } 1877 return ret; 1878 } 1879 1880 public WfAssignmentIterator get_iterator_assignment() throws NotConnected, BaseException { 1881 WfAssignmentIterator ret = null; 1882 SharkTransaction t = null; 1883 try { 1884 t = SharkUtilities.createTransaction(); 1885 ret = get_iterator_assignment(t); 1886 } catch (RootException e) { 1888 SharkUtilities.emptyCaches(t); 1890 if (e instanceof NotConnected) 1891 throw (NotConnected) e; 1892 else if (e instanceof BaseException) 1893 throw (BaseException) e; 1894 else 1895 throw new BaseException(e); 1896 } finally { 1897 SharkUtilities.releaseTransaction(t); 1898 } 1899 return ret; 1900 } 1901 1902 public WfAssignmentIterator get_iterator_assignment (SharkTransaction t) throws NotConnected, BaseException { 1903 return SharkEngineManager.getInstance() 1904 .getObjectFactory() 1905 .createAssignmentIteratorWrapper(t, userId, null); 1906 } 1907 1908 public WfProcessIterator get_iterator_process() throws NotConnected, BaseException { 1909 WfProcessIterator ret = null; 1910 SharkTransaction t = null; 1911 try { 1912 t = SharkUtilities.createTransaction(); 1913 ret = get_iterator_process(t); 1914 } catch (RootException e) { 1916 SharkUtilities.emptyCaches(t); 1918 if (e instanceof NotConnected) 1919 throw (NotConnected) e; 1920 else if (e instanceof BaseException) 1921 throw (BaseException) e; 1922 else 1923 throw new BaseException(e); 1924 } finally { 1925 SharkUtilities.releaseTransaction(t); 1926 } 1927 return ret; 1928 } 1929 1930 public WfProcessIterator get_iterator_process (SharkTransaction t) throws NotConnected, BaseException { 1931 return SharkEngineManager.getInstance() 1932 .getObjectFactory() 1933 .createProcessIteratorWrapper(t, userId, null, false); 1934 } 1935 1936 public WfActivityIterator get_iterator_activity() throws NotConnected, BaseException { 1937 WfActivityIterator ret = null; 1938 SharkTransaction t = null; 1939 try { 1940 t = SharkUtilities.createTransaction(); 1941 ret = get_iterator_activity(t); 1942 } catch (RootException e) { 1944 SharkUtilities.emptyCaches(t); 1946 if (e instanceof NotConnected) 1947 throw (NotConnected) e; 1948 else if (e instanceof BaseException) 1949 throw (BaseException) e; 1950 else 1951 throw new BaseException(e); 1952 } finally { 1953 SharkUtilities.releaseTransaction(t); 1954 } 1955 return ret; 1956 } 1957 1958 public WfActivityIterator get_iterator_activity (SharkTransaction t) throws NotConnected, BaseException { 1959 return SharkEngineManager.getInstance() 1960 .getObjectFactory() 1961 .createActivityIteratorWrapper(t, userId, null); 1962 } 1963 1964 public void finalize() throws Throwable { 1966 if (connected) { 1967 connected=false; 1968 SharkUtilities.disconnect(connectionKey); 1969 cus.info("ExecutionAdmin -> User "+userId+" with connection key "+connectionKey+" is automatically disconnected"); 1970 } 1971 } 1972} 1973 1974 | Popular Tags |