KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > admin > patch > impl > DescriptorUpdatePatch


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.admin.patch.impl;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import org.alfresco.i18n.I18NUtil;
26 import org.alfresco.model.ContentModel;
27 import org.alfresco.repo.admin.patch.AbstractPatch;
28 import org.alfresco.repo.importer.ImporterBootstrap;
29 import org.alfresco.service.cmr.repository.NodeRef;
30 import org.alfresco.service.cmr.repository.NodeService;
31 import org.alfresco.service.cmr.repository.StoreRef;
32 import org.alfresco.service.cmr.search.SearchService;
33 import org.alfresco.service.namespace.NamespaceService;
34
35 /**
36  * Apply Version Edition to Repository Descriptor
37  *
38  * @author David Caruana
39  */

40 public class DescriptorUpdatePatch extends AbstractPatch
41 {
42     private static final String JavaDoc MSG_SUCCESS = "patch.descriptorUpdate.result";
43
44
45     private ImporterBootstrap systemBootstrap;
46     private SearchService searchService;
47     private NodeService nodeService;
48     private NamespaceService namespaceService;
49     
50     public void setSystemBootstrap(ImporterBootstrap systemBootstrap)
51     {
52         this.systemBootstrap = systemBootstrap;
53     }
54
55     public void setSearchService(SearchService searchService)
56     {
57         this.searchService = searchService;
58     }
59     
60     public void setNodeService(NodeService nodeService)
61     {
62         this.nodeService = nodeService;
63     }
64
65     public void setNamespaceService(NamespaceService namespaceService)
66     {
67         this.namespaceService = namespaceService;
68     }
69     
70     
71     @Override JavaDoc
72     protected String JavaDoc applyInternal() throws Exception JavaDoc
73     {
74         // retrieve system descriptor location
75
StoreRef storeRef = systemBootstrap.getStoreRef();
76         Properties JavaDoc systemProperties = systemBootstrap.getConfiguration();
77
78         // check for the store
79
if (nodeService.exists(storeRef))
80         {
81             // get the current descriptor
82
String JavaDoc path = systemProperties.getProperty("system.descriptor.current.childname");
83             String JavaDoc searchPath = "/" + path;
84             NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
85             List JavaDoc<NodeRef> nodeRefs = searchService.selectNodes(rootNodeRef, searchPath, null, namespaceService, false);
86             if (nodeRefs.size() > 0)
87             {
88                 NodeRef descriptorNodeRef = nodeRefs.get(0);
89
90                 // set version edition
91
Serializable JavaDoc value = nodeService.getProperty(descriptorNodeRef, ContentModel.PROP_SYS_VERSION_EDITION);
92                 if (value == null)
93                 {
94                     String JavaDoc edition = systemProperties.getProperty("version.edition");
95                     Collection JavaDoc<String JavaDoc> editions = new ArrayList JavaDoc<String JavaDoc>();
96                     editions.add(edition);
97                     nodeService.setProperty(descriptorNodeRef, ContentModel.PROP_SYS_VERSION_EDITION, (Serializable JavaDoc)editions);
98                 }
99             }
100         }
101         
102         // done
103
String JavaDoc msg = I18NUtil.getMessage(MSG_SUCCESS);
104         return msg;
105     }
106     
107 }
108
Popular Tags