Merge V1.2.0 BRANCH to HEAD

svn merge -r 2519:2565 svn://www.alfresco.org/alfresco/BRANCHES/V1.2.0/root HEAD/root


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2566 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-03-22 12:23:43 +00:00
parent 9fe16d5ae3
commit 506e408ca7
29 changed files with 725 additions and 182 deletions

View File

@@ -37,6 +37,15 @@ import org.apache.commons.logging.LogFactory;
*/
public abstract class AbstractPatch implements Patch
{
/**
* I18N message when properties nto set.
* <ul>
* <li>{0} = property name</li>
* <li>{1} = patch instance</li>
* </ul>
*/
public static final String ERR_PROPERTY_NOT_SET = "patch.general.property_not_set";
private static Log logger = LogFactory.getLog(AbstractPatch.class);
private String id;
@@ -215,30 +224,38 @@ public abstract class AbstractPatch implements Patch
{
return ((this.fixesFromSchema <= version) && (version <= fixesToSchema));
}
/**
* Performs a null check on the supplied value.
*
* @param value value to check
* @param name name of the property to report
*/
protected final void checkPropertyNotNull(Object value, String name)
{
if (value == null)
{
throw new PatchException(ERR_PROPERTY_NOT_SET, "bootstrapView", this);
}
}
/**
* Check that the schema version properties have been set appropriately
* Check that the schema version properties have been set appropriately.
* Derived classes can override this method to perform their own validation provided
* that this method is called by the derived class.
*/
private void checkProperties()
protected void checkProperties()
{
// check that the necessary properties have been set
if (id == null || description == null)
{
throw new AlfrescoRuntimeException(
"Patch properties 'id', 'fixesFromSchema' and 'description' have not all been set on this patch: \n" +
" patch: " + this);
}
else if (fixesFromSchema == -1 || fixesToSchema == -1 || targetSchema == -1)
checkPropertyNotNull(id, "id");
checkPropertyNotNull(description, "description");
checkPropertyNotNull(transactionService, "transactionService");
if (fixesFromSchema == -1 || fixesToSchema == -1 || targetSchema == -1)
{
throw new AlfrescoRuntimeException(
"Patch properties 'fixesFromSchema', 'fixesToSchema' and 'targetSchema' have not all been set on this patch: \n" +
" patch: " + this);
}
else if (transactionService == null)
{
throw new AlfrescoRuntimeException("'transactionService' property has not been set: \n" +
" patch: " + this);
}
}
/**

View File

@@ -0,0 +1,144 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.admin.patch.impl;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.importer.ImporterBootstrap;
import org.alfresco.service.cmr.admin.PatchException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
/**
* Generic patch that uses existing {@link org.alfresco.repo.importer.ImporterBootstrap importers}
* to import snippets into the system. These snippets would otherwise have been bootstrapped by
* a clean install.
* <p>
* By providing this class with a bootstrap view and an importer, it can check whether the path
* exists and perform the import if it doesn't.
*
* @author Derek Hulley
*/
public class GenericBootstrapPatch extends AbstractPatch
{
private static final String MSG_EXISTS = "patch.genericBootstrap.result.exists";
private static final String MSG_CREATED = "patch.genericBootstrap.result.created";
private static final String ERR_MULTIPLE_FOUND = "patch.genericBootstrap.err.multiple_found";
private NamespaceService namespaceService;
private NodeService nodeService;
private SearchService searchService;
private ImporterBootstrap importerBootstrap;
private String checkPath;
private Properties bootstrapView;
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
/**
* @param importerBootstrap the bootstrap bean that performs the user store bootstrap
*/
public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
{
this.importerBootstrap = importerBootstrap;
}
/**
* Set the XPath statement that must be executed to check whether the import data is
* already present or not.
*
* @param checkPath an XPath statement
*/
public void setCheckPath(String checkPath)
{
this.checkPath = checkPath;
}
/**
* @see ImporterBootstrap#setBootstrapViews(List)
*
* @param bootstrapView the bootstrap location
*/
public void setBootstrapView(Properties bootstrapView)
{
this.bootstrapView = bootstrapView;
}
@Override
protected void checkProperties()
{
checkPropertyNotNull(namespaceService, "blah");
checkPropertyNotNull(nodeService, "nodeService");
checkPropertyNotNull(searchService, "searchService");
checkPropertyNotNull(importerBootstrap, "importerBootstrap");
checkPropertyNotNull(checkPath, "checkPath");
checkPropertyNotNull(bootstrapView, "bootstrapView");
// fulfil contract of override
super.checkProperties();
}
@Override
protected String applyInternal() throws Exception
{
StoreRef storeRef = importerBootstrap.getStoreRef();
NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
List<NodeRef> results = searchService.selectNodes(
rootNodeRef,
checkPath,
null,
namespaceService,
false);
if (results.size() > 1)
{
throw new PatchException(ERR_MULTIPLE_FOUND, checkPath);
}
else if (results.size() == 1)
{
// nothing to do - it exsists
return I18NUtil.getMessage(MSG_EXISTS, checkPath);
}
String path = bootstrapView.getProperty("path");
List<Properties> bootstrapViews = Collections.singletonList(bootstrapView);
// modify the bootstrapper
importerBootstrap.setBootstrapViews(bootstrapViews);
importerBootstrap.setUseExistingStore(true); // allow import into existing store
importerBootstrap.bootstrap();
// done
return I18NUtil.getMessage(MSG_CREATED, path, rootNodeRef);
}
}