1 17 package org.alfresco.repo.admin.patch.impl; 18 19 import java.io.Serializable ; 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.List ; 23 import java.util.Properties ; 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 40 public class DescriptorUpdatePatch extends AbstractPatch 41 { 42 private static final String 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 72 protected String applyInternal() throws Exception 73 { 74 StoreRef storeRef = systemBootstrap.getStoreRef(); 76 Properties systemProperties = systemBootstrap.getConfiguration(); 77 78 if (nodeService.exists(storeRef)) 80 { 81 String path = systemProperties.getProperty("system.descriptor.current.childname"); 83 String searchPath = "/" + path; 84 NodeRef rootNodeRef = nodeService.getRootNode(storeRef); 85 List <NodeRef> nodeRefs = searchService.selectNodes(rootNodeRef, searchPath, null, namespaceService, false); 86 if (nodeRefs.size() > 0) 87 { 88 NodeRef descriptorNodeRef = nodeRefs.get(0); 89 90 Serializable value = nodeService.getProperty(descriptorNodeRef, ContentModel.PROP_SYS_VERSION_EDITION); 92 if (value == null) 93 { 94 String edition = systemProperties.getProperty("version.edition"); 95 Collection <String > editions = new ArrayList <String >(); 96 editions.add(edition); 97 nodeService.setProperty(descriptorNodeRef, ContentModel.PROP_SYS_VERSION_EDITION, (Serializable )editions); 98 } 99 } 100 } 101 102 String msg = I18NUtil.getMessage(MSG_SUCCESS); 104 return msg; 105 } 106 107 } 108 | Popular Tags |