1 17 package org.alfresco.repo.admin.patch.impl; 18 19 import java.util.Collections ; 20 import java.util.List ; 21 import java.util.Properties ; 22 23 import org.alfresco.i18n.I18NUtil; 24 import org.alfresco.repo.admin.patch.AbstractPatch; 25 import org.alfresco.repo.importer.ImporterBootstrap; 26 import org.alfresco.service.cmr.admin.PatchException; 27 import org.alfresco.service.cmr.repository.NodeRef; 28 import org.alfresco.service.cmr.repository.NodeService; 29 import org.alfresco.service.cmr.repository.StoreRef; 30 import org.alfresco.service.cmr.search.SearchService; 31 import org.alfresco.service.namespace.NamespaceService; 32 33 43 public class GenericBootstrapPatch extends AbstractPatch 44 { 45 private static final String MSG_EXISTS = "patch.genericBootstrap.result.exists"; 46 private static final String MSG_CREATED = "patch.genericBootstrap.result.created"; 47 private static final String ERR_MULTIPLE_FOUND = "patch.genericBootstrap.err.multiple_found"; 48 49 private NamespaceService namespaceService; 50 private NodeService nodeService; 51 private SearchService searchService; 52 private ImporterBootstrap importerBootstrap; 53 private String checkPath; 54 private Properties bootstrapView; 55 56 public void setNamespaceService(NamespaceService namespaceService) 57 { 58 this.namespaceService = namespaceService; 59 } 60 61 public void setNodeService(NodeService nodeService) 62 { 63 this.nodeService = nodeService; 64 } 65 66 public void setSearchService(SearchService searchService) 67 { 68 this.searchService = searchService; 69 } 70 71 74 public void setImporterBootstrap(ImporterBootstrap importerBootstrap) 75 { 76 this.importerBootstrap = importerBootstrap; 77 } 78 79 85 public void setCheckPath(String checkPath) 86 { 87 this.checkPath = checkPath; 88 } 89 90 95 public void setBootstrapView(Properties bootstrapView) 96 { 97 this.bootstrapView = bootstrapView; 98 } 99 100 @Override 101 protected void checkProperties() 102 { 103 checkPropertyNotNull(namespaceService, "blah"); 104 checkPropertyNotNull(nodeService, "nodeService"); 105 checkPropertyNotNull(searchService, "searchService"); 106 checkPropertyNotNull(importerBootstrap, "importerBootstrap"); 107 checkPropertyNotNull(checkPath, "checkPath"); 108 checkPropertyNotNull(bootstrapView, "bootstrapView"); 109 super.checkProperties(); 111 } 112 113 @Override 114 protected String applyInternal() throws Exception 115 { 116 StoreRef storeRef = importerBootstrap.getStoreRef(); 117 NodeRef rootNodeRef = nodeService.getRootNode(storeRef); 118 List <NodeRef> results = searchService.selectNodes( 119 rootNodeRef, 120 checkPath, 121 null, 122 namespaceService, 123 false); 124 if (results.size() > 1) 125 { 126 throw new PatchException(ERR_MULTIPLE_FOUND, checkPath); 127 } 128 else if (results.size() == 1) 129 { 130 return I18NUtil.getMessage(MSG_EXISTS, checkPath); 132 133 } 134 String path = bootstrapView.getProperty("path"); 135 List <Properties > bootstrapViews = Collections.singletonList(bootstrapView); 136 importerBootstrap.setBootstrapViews(bootstrapViews); 138 importerBootstrap.setUseExistingStore(true); 140 importerBootstrap.bootstrap(); 141 return I18NUtil.getMessage(MSG_CREATED, path, rootNodeRef); 143 } 144 } 145 | Popular Tags |