1 17 package org.alfresco.repo.version; 18 19 import javax.transaction.UserTransaction ; 20 21 import org.alfresco.error.AlfrescoRuntimeException; 22 import org.alfresco.repo.security.authentication.AuthenticationComponent; 23 import org.alfresco.service.cmr.repository.NodeService; 24 import org.alfresco.service.cmr.repository.StoreRef; 25 import org.alfresco.service.cmr.security.PermissionService; 26 import org.alfresco.service.transaction.TransactionService; 27 28 33 public class VersionBootstrap 34 { 35 private TransactionService transactionService; 36 private NodeService nodeService; 37 private AuthenticationComponent authenticationComponent; 38 private PermissionService permissionService; 39 40 41 46 public void setTransactionService(TransactionService transactionService) 47 { 48 this.transactionService = transactionService; 49 } 50 51 56 public void setNodeService(NodeService nodeService) 57 { 58 this.nodeService = nodeService; 59 } 60 61 public void setAuthenticationComponent(AuthenticationComponent authenticationComponent) 62 { 63 this.authenticationComponent = authenticationComponent; 64 } 65 66 67 68 public void setPermissionService(PermissionService permissionService) 69 { 70 this.permissionService = permissionService; 71 } 72 73 76 public void bootstrap() 77 { 78 UserTransaction userTransaction = transactionService.getUserTransaction(); 79 authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); 80 81 try 82 { 83 userTransaction.begin(); 84 85 if (this.nodeService.exists(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, VersionModel.STORE_ID)) == true) 87 { 88 userTransaction.rollback(); 89 } 90 else 91 { 92 StoreRef vStore = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, VersionModel.STORE_ID); 93 permissionService.setPermission(nodeService.getRootNode(vStore), permissionService.getAllAuthorities(), permissionService.getAllPermission(), true); 95 userTransaction.commit(); 96 } 97 } 98 catch(Throwable e) 99 { 100 try { if (userTransaction != null) {userTransaction.rollback();} } catch (Exception ex) {} 102 try {authenticationComponent.clearCurrentSecurityContext(); } catch (Exception ex) {} 103 throw new AlfrescoRuntimeException("Bootstrap failed", e); 104 } 105 finally 106 { 107 authenticationComponent.clearCurrentSecurityContext(); 108 } 109 } 110 111 } 112 | Popular Tags |