1 2 package org.enhydra.shark; 3 4 import java.util.ArrayList ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 import org.enhydra.shark.api.ParticipantMappingTransaction; 8 import org.enhydra.shark.api.RepositoryTransaction; 9 import org.enhydra.shark.api.RootException; 10 import org.enhydra.shark.api.client.wfbase.BaseException; 11 import org.enhydra.shark.api.client.wfservice.ParticipantMap; 12 import org.enhydra.shark.api.client.wfservice.ParticipantMappingAdministration; 13 import org.enhydra.shark.api.internal.partmappersistence.ParticipantMappingManager; 14 import org.enhydra.shark.api.internal.repositorypersistence.RepositoryPersistenceManager; 15 import org.enhydra.shark.xpdl.elements.Participant; 16 import org.enhydra.shark.xpdl.elements.Participants; 17 import org.enhydra.shark.xpdl.elements.WorkflowProcess; 18 import org.enhydra.shark.xpdl.elements.WorkflowProcesses; 19 20 26 public class ParticipantMappingsAdministrationImpl implements ParticipantMappingAdministration { 27 28 29 private ParticipantMappingManager pmanager; 30 private String userId="Unknown"; 31 32 protected ParticipantMappingsAdministrationImpl() 33 { 34 pmanager=SharkEngineManager.getInstance().getParticipantMapPersistenceManager(); 35 } 36 37 public void connect (String userId) { 38 this.userId=userId; 39 } 40 41 public ParticipantMap[] getAllParticipants() throws BaseException { 42 ParticipantMap[] retVal; 43 ParticipantMappingTransaction t = null; 44 try { 45 t = SharkUtilities.createParticipantMappingTransaction(); 46 retVal = getAllParticipants(t); 47 } catch (RootException e) { 48 if (e instanceof BaseException) 49 throw (BaseException)e; 50 else 51 throw new BaseException(e); 52 } finally { 53 SharkUtilities.releaseMappingTransaction(t); 54 } 55 return retVal; 56 } 57 58 59 public ParticipantMap[] getAllParticipants(ParticipantMappingTransaction t) 60 throws BaseException { 61 List pl=new ArrayList (); 62 63 List packageIds=null; 64 65 RepositoryPersistenceManager rpm=SharkEngineManager 66 .getInstance() 67 .getRepositoryPersistenceManager(); 68 69 RepositoryTransaction rt=null; 70 try { 71 rt = SharkUtilities.createRepositoryTransaction(); 72 packageIds=rpm.getExistingXPDLIds(rt); 73 } catch (Exception e) { 74 throw new BaseException(e); 75 } finally { 76 SharkUtilities.releaseRepositoryTransaction(rt); 77 } 78 79 Iterator pkgIdsIter=packageIds.iterator(); 80 while (pkgIdsIter.hasNext()) 81 { 82 String pkgId=(String )pkgIdsIter.next(); 83 pl.addAll(getParticipantsFromPackage(pkgId)); 84 } 85 ParticipantMap[] pms=new ParticipantMap[pl.size()]; 86 pl.toArray(pms); 87 return pms; 88 } 89 90 public ParticipantMap[] getAllParticipantMappings() throws BaseException { 91 ParticipantMap[] retVal; 92 ParticipantMappingTransaction t = null; 93 try { 94 t = SharkUtilities.createParticipantMappingTransaction(); 95 retVal = getAllParticipantMappings(t); 96 } catch (RootException e) { 97 if (e instanceof BaseException) 98 throw (BaseException)e; 99 else 100 throw new BaseException(e); 101 } finally { 102 SharkUtilities.releaseMappingTransaction(t); 103 } 104 return retVal; 105 } 106 107 public ParticipantMap[] getAllParticipantMappings(ParticipantMappingTransaction t) 108 throws BaseException { 109 if (pmanager==null) throw new BaseException("The shark is configured to work without internal implementation of this API"); 110 try 111 { 112 List clientMapList = new ArrayList (); 113 List persistentMapList = pmanager.getAllParticipantMappings(t); 114 for ( int i = 0; i < persistentMapList.size(); i++ ) 115 { 116 clientMapList.add( createClientMapFromPersistentParticipantMap( 117 ( org.enhydra.shark.api.internal.partmappersistence.ParticipantMap ) 118 persistentMapList.get( i ) 119 ) ); 120 } 121 ParticipantMap[] pma=new ParticipantMap[clientMapList.size()]; 122 clientMapList.toArray(pma); 123 return pma; 124 } 125 catch ( Exception e ) 126 { 127 throw new BaseException(e); 128 } 129 } 130 131 public ParticipantMap[] getAllParticipants (String pkgId) throws BaseException { 132 ParticipantMap[] retVal; 133 ParticipantMappingTransaction t = null; 134 try { 135 t = SharkUtilities.createParticipantMappingTransaction(); 136 retVal = getAllParticipants(t,pkgId); 137 } catch (RootException e) { 138 if (e instanceof BaseException) 139 throw (BaseException)e; 140 else 141 throw new BaseException(e); 142 } finally { 143 SharkUtilities.releaseMappingTransaction(t); 144 } 145 return retVal; 146 } 147 148 public ParticipantMap[] getAllParticipants (ParticipantMappingTransaction trans,String pkgId) throws BaseException 149 { 150 if (pkgId==null) throw new BaseException("The package Id can't be null"); 151 List pl=getParticipantsFromPackage(pkgId); 152 ParticipantMap[] pms=new ParticipantMap[pl.size()]; 153 pl.toArray(pms); 154 return pms; 155 } 156 157 public ParticipantMap[] getAllParticipants (String pkgId,String pDefId) throws BaseException { 158 ParticipantMap[] retVal; 159 ParticipantMappingTransaction t = null; 160 try { 161 t = SharkUtilities.createParticipantMappingTransaction(); 162 retVal = getAllParticipants(t,pkgId,pDefId); 163 } catch (RootException e) { 164 if (e instanceof BaseException) 165 throw (BaseException)e; 166 else 167 throw new BaseException(e); 168 } finally { 169 SharkUtilities.releaseMappingTransaction(t); 170 } 171 return retVal; 172 } 173 174 public ParticipantMap[] getAllParticipants (ParticipantMappingTransaction trans,String pkgId,String pDefId) throws BaseException 175 { 176 if (pkgId==null) throw new BaseException("The package Id can't be null"); 177 List pl=getParticipantsFromPackageProcess(pkgId,pDefId); 178 ParticipantMap[] pms=new ParticipantMap[pl.size()]; 179 pl.toArray(pms); 180 return pms; 181 } 182 183 private List getParticipantsFromPackageProcess (String pkgId,String pDefId) throws BaseException { 184 List pl=new ArrayList (); 185 org.enhydra.shark.xpdl.elements.Package pkg= 186 SharkEngineManager.getInstance().getXMLInterface().getPackageById(pkgId); 187 if (pkg==null) throw new BaseException("Can't find package with Id="+pkgId); 188 WorkflowProcess wp=pkg.getWorkflowProcesses().getWorkflowProcess(pDefId); 189 if (wp==null) throw new BaseException("Can't find process definition with Id="+pDefId+" in pkg "+pkgId); 190 191 Participants ps=wp.getParticipants(); 192 Iterator participants=ps.toElements().iterator(); 193 while (participants.hasNext()) { 194 Participant p=(Participant)participants.next(); 195 ParticipantMap pm=SharkEngineManager 196 .getInstance() 197 .getObjectFactory() 198 .createParticipantMap(); 199 pm.setPackageId(pkgId); 200 pm.setProcessDefinitionId(wp.getId()); 201 pm.setParticipantId(p.getId()); 202 pl.add(pm); 203 } 204 return pl; 205 } 206 207 private List getParticipantsFromPackage (String pkgId) throws BaseException { 208 List pl=new ArrayList (); 209 org.enhydra.shark.xpdl.elements.Package pkg= 210 SharkEngineManager.getInstance().getXMLInterface().getPackageById(pkgId); 211 if (pkg==null) throw new BaseException("Can't find package with Id="+pkgId); 212 Participants ps=pkg.getParticipants(); 213 Iterator participants=ps.toElements().iterator(); 214 while (participants.hasNext()) 215 { 216 Participant p=(Participant)participants.next(); 217 ParticipantMap pm=SharkEngineManager 218 .getInstance() 219 .getObjectFactory() 220 .createParticipantMap(); 221 pm.setPackageId(pkgId); 222 pm.setParticipantId(p.getId()); 223 pl.add(pm); 224 } 225 Iterator processes=pkg.getWorkflowProcesses().toElements().iterator(); 226 while (processes.hasNext()) 227 { 228 String pDefId=((WorkflowProcess)processes.next()).getId(); 229 pl.addAll(getParticipantsFromPackageProcess(pkgId,pDefId)); 230 } 231 return pl; 232 } 233 234 public void addParticipantMapping(ParticipantMap pm) throws BaseException { 235 ParticipantMappingTransaction t = null; 236 try { 237 t = SharkUtilities.createParticipantMappingTransaction(); 238 addParticipantMapping(t, pm); 239 SharkUtilities.commitMappingTransaction(t); 240 } catch (RootException e) { 241 SharkUtilities.rollbackMappingTransaction(t,e); 242 if (e instanceof BaseException) 243 throw (BaseException)e; 244 else 245 throw new BaseException(e); 246 } finally { 247 SharkUtilities.releaseMappingTransaction(t); 248 } 249 } 250 251 public void addParticipantMapping(ParticipantMappingTransaction t, ParticipantMap pm) 252 throws BaseException { 253 if (pmanager==null) throw new BaseException("The shark is configured to work without internal implementation of this API"); 254 try 255 { 256 pmanager.saveParticipantMapping( 257 t, 258 this.createPersistentParticipantMapFromClientMap( pm ) ); 259 } 260 catch ( Exception e ) 261 { 262 throw new BaseException(e); 263 } 264 265 } 266 267 public void removeParticipantMapping(ParticipantMap pm) 268 throws BaseException { 269 ParticipantMappingTransaction t = null; 270 try { 271 t = SharkUtilities.createParticipantMappingTransaction(); 272 removeParticipantMapping(t, pm); 273 SharkUtilities.commitMappingTransaction(t); 274 } catch (RootException e) { 275 SharkUtilities.rollbackMappingTransaction(t,e); 276 if (e instanceof BaseException) 277 throw (BaseException)e; 278 else 279 throw new BaseException(e); 280 } finally { 281 SharkUtilities.releaseMappingTransaction(t); 282 } 283 } 284 285 public void removeParticipantMapping( 286 ParticipantMappingTransaction t, 287 ParticipantMap pm) 288 throws BaseException { 289 if (pmanager==null) throw new BaseException("The shark is configured to work without internal implementation of this API"); 290 try 291 { 292 pmanager.deleteParticipantMapping( 293 t, 294 this.createPersistentParticipantMapFromClientMap( pm ) ); 295 296 300 } 306 catch ( Exception e ) 307 { 308 throw new BaseException(e); 309 } 310 } 311 312 public ParticipantMap[] getParticipantMappings( 313 String packageId, 314 String processDefinitionId, 315 String participantId) 316 throws BaseException { 317 ParticipantMap[] retVal; 318 ParticipantMappingTransaction t = null; 319 try { 320 t = SharkUtilities.createParticipantMappingTransaction(); 321 retVal = getParticipantMappings( 322 t, 323 packageId, 324 processDefinitionId, 325 participantId); 326 } catch (RootException e) { 328 if (e instanceof BaseException) 330 throw (BaseException)e; 331 else 332 throw new BaseException(e); 333 } finally { 334 SharkUtilities.releaseMappingTransaction(t); 335 } 336 return retVal; 337 } 338 339 public ParticipantMap[] getParticipantMappings( 340 ParticipantMappingTransaction t, 341 String packageId, 342 String processDefinitionId, 343 String participantId) 344 throws BaseException { 345 if (pmanager==null) throw new BaseException("The shark is configured to work without internal implementation of this API"); 346 ParticipantMap[] pma = null; 347 try 348 { 349 List persistentMapList = pmanager.getParticipantMappings( 350 t, 351 packageId, 352 processDefinitionId, 353 participantId ); 354 355 List clientMapList = new ArrayList (); 356 for ( int i = 0; i < persistentMapList.size(); i++ ) 357 { 358 clientMapList.add( createClientMapFromPersistentParticipantMap( 359 ( org.enhydra.shark.api.internal.partmappersistence.ParticipantMap ) 360 persistentMapList.get( i ) 361 ) ); 362 } 363 pma=new ParticipantMap[clientMapList.size()]; 364 clientMapList.toArray(pma); 365 } 366 catch ( Exception e ) 367 { 368 throw new BaseException(e); 369 } 370 return pma; 371 } 372 373 public void removeParticipantMappings( 374 String packageId, 375 String processDefinitionId, 376 String participantId) 377 throws BaseException { 378 ParticipantMappingTransaction t = null; 379 try { 380 t = SharkUtilities.createParticipantMappingTransaction(); 381 removeParticipantMappings( 382 t, 383 packageId, 384 processDefinitionId, 385 participantId); 386 SharkUtilities.commitMappingTransaction(t); 387 } catch (RootException e) { 388 SharkUtilities.rollbackMappingTransaction(t,e); 389 if (e instanceof BaseException) 390 throw (BaseException)e; 391 else 392 throw new BaseException(e); 393 } finally { 394 SharkUtilities.releaseMappingTransaction(t); 395 } 396 } 397 398 399 public void removeParticipantMappings( 400 ParticipantMappingTransaction t, 401 String packageId, 402 String processDefinitionId, 403 String participantId) 404 throws BaseException { 405 if (pmanager==null) throw new BaseException("The shark is configured to work without internal implementation of this API"); 406 try 407 { 408 pmanager.deleteParticipantMappings( 409 t, 410 packageId, 411 processDefinitionId, 412 participantId ); 413 } 414 catch ( Exception e ) 415 { 416 throw new BaseException(e); 417 } 418 } 419 420 public void removeParticipantMappings(String username) 421 throws BaseException { 422 ParticipantMappingTransaction t = null; 423 try { 424 t = SharkUtilities.createParticipantMappingTransaction(); 425 removeParticipantMappings( 426 t,username); 427 SharkUtilities.commitMappingTransaction(t); 428 } catch (RootException e) { 429 SharkUtilities.rollbackMappingTransaction(t,e); 430 if (e instanceof BaseException) 431 throw (BaseException)e; 432 else 433 throw new BaseException(e); 434 } finally { 435 SharkUtilities.releaseMappingTransaction(t); 436 } 437 } 438 439 public void removeParticipantMappings( 440 ParticipantMappingTransaction t, 441 String username) 442 throws BaseException { 443 if (pmanager==null) throw new BaseException("The shark is configured to work without internal implementation of this API"); 444 try 445 { 446 pmanager.deleteParticipantMappings( t,username ); 447 } 448 catch ( Exception e ) 449 { 450 throw new BaseException(e); 451 } 452 } 453 454 public ParticipantMap createParticipantMap() { 455 return SharkEngineManager 456 .getInstance() 457 .getObjectFactory() 458 .createParticipantMap(); 459 } 460 461 public ParticipantMap createParticipantMap(ParticipantMappingTransaction t) { 462 return SharkEngineManager 463 .getInstance() 464 .getObjectFactory() 465 .createParticipantMap(); 466 } 467 468 public String [] getAllGroupnames() throws BaseException { 469 return SharkEngineManager.getInstance().getObjectFactory(). 470 createUserGroupAdministration(). 471 getAllGroupnames(); 472 } 473 474 public String [] getAllGroupnames(ParticipantMappingTransaction t) 475 throws BaseException { 476 return SharkEngineManager.getInstance().getObjectFactory(). 477 createUserGroupAdministration(). 478 getAllGroupnames(); 479 } 480 481 public String [] getAllUsers() throws BaseException { 482 return SharkEngineManager.getInstance().getObjectFactory(). 483 createUserGroupAdministration(). 484 getAllUsers(); 485 } 486 487 public String [] getAllUsers(ParticipantMappingTransaction t) throws BaseException { 488 return SharkEngineManager.getInstance().getObjectFactory(). 489 createUserGroupAdministration(). 490 getAllUsers(); 491 } 492 493 public String [] getAllUsers(String groupName) throws BaseException { 494 return SharkEngineManager.getInstance().getObjectFactory(). 495 createUserGroupAdministration(). 496 getAllUsers(groupName); 497 } 498 499 public String [] getAllUsers(ParticipantMappingTransaction t, String groupName) 500 throws BaseException { 501 return SharkEngineManager.getInstance().getObjectFactory(). 502 createUserGroupAdministration(). 503 getAllUsers(groupName); 504 } 505 506 private org.enhydra.shark.api.internal.partmappersistence.ParticipantMap 507 createPersistentParticipantMapFromClientMap( ParticipantMap pm ) throws BaseException 508 { 509 if (pmanager==null) throw new BaseException("The shark is configured to work without internal implementation of this API"); 510 org.enhydra.shark.api.internal.partmappersistence.ParticipantMap 511 pmpersistent = null; 512 try { 513 pmpersistent = pmanager.createParticipantMap(); 514 pmpersistent.setUsername( pm.getUsername() ); 515 pmpersistent.setProcessDefinitionId( pm.getProcessDefinitionId() ); 516 pmpersistent.setParticipantId( pm.getParticipantId() ); 517 pmpersistent.setPackageId( pm.getPackageId() ); 518 pmpersistent.setIsGroupUser( pm.getIsGroupUser() ); 519 }catch(Exception e) { 520 throw new BaseException(e); 521 } 522 return pmpersistent; 523 } 524 525 private ParticipantMap 526 createClientMapFromPersistentParticipantMap( org.enhydra.shark.api.internal.partmappersistence.ParticipantMap pm ) 527 { 528 if (pm==null) return null; 529 ParticipantMap pmClient = createParticipantMap(); 530 pmClient.setUsername( pm.getUsername() ); 531 pmClient.setProcessDefinitionId( pm.getProcessDefinitionId() ); 532 pmClient.setParticipantId( pm.getParticipantId()); 533 pmClient.setPackageId( pm.getPackageId() ); 534 pmClient.setIsGroupUser( pm.getIsGroupUser() ); 535 return pmClient; 536 } 537 538 } 539 | Popular Tags |