Simple promote action (moves changed content from sandbox to sandbox).

Fixed various pathetic flaws in SimpleAVMSubmitAction.
AVMSyncService.flatten() silently ignores harmless do nothing calls.
Cleared up small episode of Eclipse Add Import Tourette's. ;)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3900 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-09-22 22:34:20 +00:00
parent 13ed2707b2
commit 4707762604
7 changed files with 186 additions and 16 deletions

View File

@@ -351,7 +351,7 @@ public class AVMRepository
String dstName)
{
// This is about as ugly as it gets.
if (dstPath.indexOf(srcPath + srcName) == 0)
if ((dstPath + "/").indexOf(srcPath + srcName + "/") == 0)
{
throw new AVMCycleException("Cyclic rename.");
}

View File

@@ -31,6 +31,8 @@ import java.util.Set;
import java.util.TreeMap;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.avm.actions.SimpleAVMPromoteAction;
import org.alfresco.repo.avm.actions.SimpleAVMSubmitAction;
import org.alfresco.repo.avm.util.BulkLoader;
import org.alfresco.repo.domain.PropertyValue;
@@ -53,6 +55,7 @@ import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.GUID;
/**
* Big test of AVM behavior.
@@ -60,6 +63,45 @@ import org.alfresco.service.transaction.TransactionService;
*/
public class AVMServiceTest extends AVMServiceTestBase
{
/**
* Test the promote action.
*/
public void testPromoteAction()
{
try
{
setupBasicTree();
fService.createDirectory("main:/", "appBase");
fService.rename("main:/", "a", "main:/appBase", "a");
fService.rename("main:/", "d", "main:/appBase", "d");
fService.createSnapshot("main");
fService.createAVMStore("source");
fService.createLayeredDirectory("main:/appBase", "source:/", "appBase");
fService.getFileOutputStream("source:/appBase/a/b/c/foo").close();
final ActionImpl action = new ActionImpl(AVMNodeConverter.ToNodeRef(-1, "source:/appBase/a"),
GUID.generate(),
SimpleAVMPromoteAction.NAME);
action.setParameterValue(SimpleAVMPromoteAction.PARAM_TARGET_STORE, "main");
final SimpleAVMPromoteAction promote = (SimpleAVMPromoteAction)fContext.getBean("simple-avm-promote");
class TxnWork implements TransactionUtil.TransactionWork<Object>
{
public Object doWork() throws Exception
{
promote.execute(action, AVMNodeConverter.ToNodeRef(-1, "source:/appBase/a"));
return null;
}
};
TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"),
new TxnWork());
assertEquals(0, fSyncService.compare(-1, "source:/appBase", -1, "main:/appBase").size());
}
catch (Exception e)
{
e.printStackTrace(System.err);
fail();
}
}
/**
* Test a noodle update.
*/
@@ -96,28 +138,28 @@ public class AVMServiceTest extends AVMServiceTestBase
try
{
fService.createAVMStore("foo-staging");
fService.createDirectory("foo-staging:/", "layer");
fService.createDirectory("foo-staging:/layer", "a");
fService.createDirectory("foo-staging:/layer/a","b");
fService.createDirectory("foo-staging:/layer/a/b", "c");
fService.createFile("foo-staging:/layer/a/b/c", "foo").close();
fService.createFile("foo-staging:/layer/a/b/c", "bar").close();
fService.createDirectory("foo-staging:/", "appBase");
fService.createDirectory("foo-staging:/appBase", "a");
fService.createDirectory("foo-staging:/appBase/a","b");
fService.createDirectory("foo-staging:/appBase/a/b", "c");
fService.createFile("foo-staging:/appBase/a/b/c", "foo").close();
fService.createFile("foo-staging:/appBase/a/b/c", "bar").close();
fService.createAVMStore("area");
fService.setStoreProperty("area", QName.createQName(null, ".website.name"),
new PropertyValue(null, "foo"));
fService.createLayeredDirectory("foo-staging:/layer", "area:/", "layer");
fService.createFile("area:/layer", "figs").close();
fService.getFileOutputStream("area:/layer/a/b/c/foo").close();
fService.removeNode("area:/layer/a/b/c/bar");
fService.createLayeredDirectory("foo-staging:/appBase", "area:/", "appBase");
fService.createFile("area:/appBase", "figs").close();
fService.getFileOutputStream("area:/appBase/a/b/c/foo").close();
fService.removeNode("area:/appBase/a/b/c/bar");
List<AVMDifference> diffs =
fSyncService.compare(-1, "area:/layer", -1, "foo-staging:/layer");
fSyncService.compare(-1, "area:/appBase", -1, "foo-staging:/appBase");
assertEquals(3, diffs.size());
final SimpleAVMSubmitAction action = (SimpleAVMSubmitAction)fContext.getBean("simple-avm-submit");
class TxnWork implements TransactionUtil.TransactionWork<Object>
{
public Object doWork() throws Exception
{
action.execute(null, AVMNodeConverter.ToNodeRef(-1, "area:/layer"));
action.execute(null, AVMNodeConverter.ToNodeRef(-1, "area:/appBase"));
return null;
}
};
@@ -125,7 +167,7 @@ public class AVMServiceTest extends AVMServiceTestBase
TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"),
worker);
diffs =
fSyncService.compare(-1, "area:/layer", -1, "foo-staging:/layer");
fSyncService.compare(-1, "area:/appBase", -1, "foo-staging:/appBase");
assertEquals(0, diffs.size());
}
catch (Exception e)

View File

@@ -594,7 +594,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
{
throw new AVMBadArgumentException("Illegal null path.");
}
AVMNodeDescriptor layerNode = fAVMService.lookup(-1, layerPath);
AVMNodeDescriptor layerNode = fAVMService.lookup(-1, layerPath, true);
if (layerNode == null)
{
throw new AVMNotFoundException("Not found: " + layerPath);

View File

@@ -0,0 +1,111 @@
/*
* Copyright (C) 2006 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.avm.actions;
import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncException;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* An ActionExecuter that promotes content from one store to another.
* The NodeRef argument is in the source AVMStore. The 'target-store'
* mandatory argument is the name of the destination store.
* @author britt
*/
public class SimpleAVMPromoteAction extends ActionExecuterAbstractBase
{
public static final String NAME = "simple-avm-promote";
public static final String PARAM_TARGET_STORE = "target-store";
/**
* The AVMSyncService instance.
*/
private AVMSyncService fAVMSyncService;
/**
* Default constructor.
*/
public SimpleAVMPromoteAction()
{
super();
}
/**
* Set the AVMSyncService instance.
* @param avmSyncService
*/
public void setAvmSyncService(AVMSyncService avmSyncService)
{
fAVMSyncService = avmSyncService;
}
/**
* Do a promotion of an asset from one sandbox to another.
* Takes a mandatory parameter 'target-store' which is the name of the
* target AVMStore.
* @param action The source of parameters.
* @param actionedUponNodeRef The source AVM NodeRef.
*/
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
String targetStoreName = (String)action.getParameterValue(PARAM_TARGET_STORE);
// Crack the NodeRef.
Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(actionedUponNodeRef);
int version = (Integer)avmVersionPath[0];
String path = (String)avmVersionPath[1];
// Get store name and path parts.
String [] storePath = path.split(":");
if (storePath.length != 2)
{
throw new AVMSyncException("Malformed source path: " + path);
}
// Compute the corresponding target path.
String targetPath = targetStoreName + ":" + storePath[1];
// Find the differences.
List<AVMDifference> diffs =
fAVMSyncService.compare(version, path, -1, targetPath);
// Do the promote.
fAVMSyncService.update(diffs, true, true, false, false);
// Flatten the source on top of the destination.
fAVMSyncService.flatten(storePath[0] + ":/appBase",
targetStoreName + ":/appBase");
}
/**
* Define needed parameters.
* @param paramList The List of ParameterDefinitions to add to.
*/
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_TARGET_STORE,
DataTypeDefinition.TEXT,
true,
getParamDisplayLabel(PARAM_TARGET_STORE)));
}
}

View File

@@ -26,6 +26,7 @@ import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncException;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
@@ -92,6 +93,10 @@ public class SimpleAVMSubmitAction extends ActionExecuterAbstractBase
String path = (String)avmVersionPath[1];
// Get store name and path parts.
String [] storePath = path.split(":");
if (storePath.length != 2)
{
throw new AVMSyncException("Malformed source path " + path);
}
// Get the .website.name property.
PropertyValue wsProp =
fAVMService.getStoreProperty(storePath[0],
@@ -111,7 +116,7 @@ public class SimpleAVMSubmitAction extends ActionExecuterAbstractBase
// Do the update.
fAVMSyncService.update(diffs, true, true, false, false);
// Cleanup by flattening the source relative to the destination.
fAVMSyncService.flatten(path, avmDest);
fAVMSyncService.flatten(storePath[0] + ":/appBase", websiteName + "-staging:/appBase");
}
/**