KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > version > VersionBootstrap


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.version;
18
19 import javax.transaction.UserTransaction JavaDoc;
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 /**
29  * Bootstrap Version Store
30  *
31  * @author David Caruana
32  */

33 public class VersionBootstrap
34 {
35     private TransactionService transactionService;
36     private NodeService nodeService;
37     private AuthenticationComponent authenticationComponent;
38     private PermissionService permissionService;
39     
40     
41     /**
42      * Sets the Transaction Service
43      *
44      * @param userTransaction the user transaction
45      */

46     public void setTransactionService(TransactionService transactionService)
47     {
48         this.transactionService = transactionService;
49     }
50
51     /**
52      * Sets the Node Service
53      *
54      * @param nodeService the node service
55      */

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     /**
74      * Bootstrap the Version Store
75      */

76     public void bootstrap()
77     {
78         UserTransaction JavaDoc userTransaction = transactionService.getUserTransaction();
79         authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
80         
81         try
82         {
83             userTransaction.begin();
84
85             // Ensure that the version store has been created
86
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                 // TODO: For now there are no permissions on version access
94
permissionService.setPermission(nodeService.getRootNode(vStore), permissionService.getAllAuthorities(), permissionService.getAllPermission(), true);
95                 userTransaction.commit();
96             }
97         }
98         catch(Throwable JavaDoc e)
99         {
100             // rollback the transaction
101
try { if (userTransaction != null) {userTransaction.rollback();} } catch (Exception JavaDoc ex) {}
102             try {authenticationComponent.clearCurrentSecurityContext(); } catch (Exception JavaDoc ex) {}
103             throw new AlfrescoRuntimeException("Bootstrap failed", e);
104         }
105         finally
106         {
107             authenticationComponent.clearCurrentSecurityContext();
108         }
109     }
110     
111 }
112
Popular Tags