From 965d55de147cf1876300766460699b7308499cf5 Mon Sep 17 00:00:00 2001 From: Britt Park Date: Tue, 14 Nov 2006 20:06:27 +0000 Subject: [PATCH] A Revert action that should serve for both reverting a staging store or reverting picked content in a users sandbox. It has a test that works and everything. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4357 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/action-services-context.xml | 8 ++ .../messages/action-config.properties | 11 +- .../org/alfresco/repo/avm/AVMServiceTest.java | 54 +++++++- .../repo/avm/actions/AVMRevertListAction.java | 126 ++++++++++++++++++ 4 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 source/java/org/alfresco/repo/avm/actions/AVMRevertListAction.java diff --git a/config/alfresco/action-services-context.xml b/config/alfresco/action-services-context.xml index 779f01c5bd..db79de5922 100644 --- a/config/alfresco/action-services-context.xml +++ b/config/alfresco/action-services-context.xml @@ -436,4 +436,12 @@ + + + + + + false + + diff --git a/config/alfresco/messages/action-config.properties b/config/alfresco/messages/action-config.properties index de34139cdb..4f51e5c6fb 100644 --- a/config/alfresco/messages/action-config.properties +++ b/config/alfresco/messages/action-config.properties @@ -96,7 +96,16 @@ simple-avm-promote.target-store.display-label=The name of the target AVM store. avm-revert-store.title=Revert a Single Node in a store. avm-revert-store.description=This reverts all nodes including and below the argument node to a previous version. -avm-revert-store.version.display-lable=The version to revert to. +avm-revert-store.version.display-label=The version to revert to. + +avm-revert-list.title=Revert a List of Nodes in a store. +avm-revert-list.description=This reverts all the nodes included in the list. +avm-revert-list.version.display-label=The version to revert to. +avm-revert-list.node-list.display-label=The string encoded list of nodes to revert. +avm-revert-list.flatten.display-label=Whether to flatten to a staging store after revert. +avm-revert-list.store.display-label=The name of the store being reverted, only needed if flattening. +avm-revert-list.staging.display-label=The name of the staging store to flatten to. +avm-revert-list.flatten-path.display-label=The store relative path that should be flattened. start-avm-workflow.title=Start a WCM Workflow start-avm-workflow.description=Starts a workflow expecting an AVM workflow package diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index b8711a324a..7b87a5101c 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -33,9 +33,11 @@ import java.util.TreeMap; import org.alfresco.model.ContentModel; import org.alfresco.model.WCMModel; import org.alfresco.repo.action.ActionImpl; +import org.alfresco.repo.avm.actions.AVMRevertListAction; 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.avm.util.VersionPathStuffer; import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.transaction.TransactionUtil; @@ -229,6 +231,56 @@ public class AVMServiceTest extends AVMServiceTestBase } } + /** + * Test the revert list action. + */ + public void testRevertListAction() + { + try + { + setupBasicTree(); + fService.createAVMStore("area"); + fService.createLayeredDirectory("main:/a", "area:/", "a"); + fService.getFileOutputStream("area:/a/b/c/foo").close(); + List diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a"); + assertEquals(1, diffs.size()); + fSyncService.update(diffs, false, false, false, false, null, null); + fService.getFileOutputStream("area:/a/b/c/bar").close(); + diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a"); + assertEquals(1, diffs.size()); + final ActionImpl action = new ActionImpl(null, + GUID.generate(), + AVMRevertListAction.NAME); + VersionPathStuffer stuffer = new VersionPathStuffer(); + stuffer.add(-1, "area:/a/b"); + String nodeList = stuffer.toString(); + action.setParameterValue(AVMRevertListAction.PARAM_VERSION, 1); + action.setParameterValue(AVMRevertListAction.PARAM_NODE_LIST, nodeList); + action.setParameterValue(AVMRevertListAction.PARAM_FLATTEN, true); + action.setParameterValue(AVMRevertListAction.PARAM_STORE, "area"); + action.setParameterValue(AVMRevertListAction.PARAM_STAGING, "main"); + action.setParameterValue(AVMRevertListAction.PARAM_FLATTEN_PATH, "/a"); + final AVMRevertListAction revert = (AVMRevertListAction)fContext.getBean("avm-revert-list"); + class TxnWork implements TransactionUtil.TransactionWork + { + public Object doWork() throws Exception + { + revert.execute(action, null); + return null; + } + }; + TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"), + new TxnWork()); + diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a"); + assertEquals(0, diffs.size()); + } + catch (Exception e) + { + e.printStackTrace(); + fail(); + } + } + /** * Test the promote action. */ @@ -258,7 +310,7 @@ public class AVMServiceTest extends AVMServiceTestBase } }; TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"), - new TxnWork()); + new TxnWork()); assertEquals(0, fSyncService.compare(-1, "source:/appBase", -1, "main:/appBase").size()); } catch (Exception e) diff --git a/source/java/org/alfresco/repo/avm/actions/AVMRevertListAction.java b/source/java/org/alfresco/repo/avm/actions/AVMRevertListAction.java new file mode 100644 index 0000000000..56a5aac67d --- /dev/null +++ b/source/java/org/alfresco/repo/avm/actions/AVMRevertListAction.java @@ -0,0 +1,126 @@ +/** + * + */ +package org.alfresco.repo.avm.actions; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.repo.action.ParameterDefinitionImpl; +import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; +import org.alfresco.repo.avm.util.VersionPathUnstuffer; +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.AVMSyncService; +import org.alfresco.service.cmr.dictionary.DataTypeDefinition; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.util.Pair; +import org.apache.log4j.Logger; + +/** + * This action handles reverting a selected set of nodes to a particular version. + * The set of of nodes is passed in as a packed string (Obtained by VersionPathStuffer). + * The actionedUponNodeRef is a dummy and can be null. + * @author britt + */ +public class AVMRevertListAction extends ActionExecuterAbstractBase +{ + private static Logger fgLogger = Logger.getLogger(AVMRevertListAction.class); + + public static final String NAME = "avm-revert-list"; + // The version to revert to. + public static final String PARAM_VERSION = "version"; + // The encoded list of nodes. + public static final String PARAM_NODE_LIST = "node-list"; + // Flag for whether we should flatten after revert. + public static final String PARAM_FLATTEN = "flatten"; + // If we are flattening, then this holds the staging store name. + public static final String PARAM_STAGING = "staging"; + // If we are flattening, then this holds the reverted store's name + public static final String PARAM_STORE = "store"; + // If we are flattening, then this holds the path "/foo/bar/baz" to flatten. + public static final String PARAM_FLATTEN_PATH = "flatten-path"; + + /** + * The sync service. + */ + private AVMSyncService fSyncService; + + /** + * Set the sync service. + */ + public void setAvmSyncService(AVMSyncService service) + { + fSyncService = service; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + protected void executeImpl(Action action, NodeRef actionedUponNodeRef) + { + int revertVersion = (Integer)action.getParameterValue(PARAM_VERSION); + String packedNodes = (String)action.getParameterValue(PARAM_NODE_LIST); + VersionPathUnstuffer unstuffer = new VersionPathUnstuffer(packedNodes); + List> versionPaths = unstuffer.getVersionPaths(); + List diffs = new ArrayList(); + for (Pair item : versionPaths) + { + List diffSet = + fSyncService.compare(revertVersion, item.getSecond(), + -1, item.getSecond()); + diffs.addAll(diffSet); + } + String message = "Reverted to version " + revertVersion; + fSyncService.update(diffs, false, false, true, true, message, message); + if (!(Boolean)action.getParameterValue(PARAM_FLATTEN)) + { + return; + } + String storeName = (String)action.getParameterValue(PARAM_STORE); + String flattenPath = (String)action.getParameterValue(PARAM_FLATTEN_PATH); + String stagingName = (String)action.getParameterValue(PARAM_STAGING); + fSyncService.flatten(storeName + ":" + flattenPath, + stagingName + ":" + flattenPath); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List) + */ + @Override + protected void addParameterDefinitions(List paramList) + { + paramList.add( + new ParameterDefinitionImpl(PARAM_VERSION, + DataTypeDefinition.INT, + true, + getParamDisplayLabel(PARAM_VERSION))); + paramList.add( + new ParameterDefinitionImpl(PARAM_NODE_LIST, + DataTypeDefinition.TEXT, + true, + getParamDisplayLabel(PARAM_NODE_LIST))); + paramList.add( + new ParameterDefinitionImpl(PARAM_FLATTEN, + DataTypeDefinition.BOOLEAN, + false, + getParamDisplayLabel(PARAM_FLATTEN))); + paramList.add( + new ParameterDefinitionImpl(PARAM_STAGING, + DataTypeDefinition.TEXT, + false, + getParamDisplayLabel(PARAM_STAGING))); + paramList.add( + new ParameterDefinitionImpl(PARAM_STORE, + DataTypeDefinition.TEXT, + false, + getParamDisplayLabel(PARAM_STORE))); + paramList.add( + new ParameterDefinitionImpl(PARAM_FLATTEN_PATH, + DataTypeDefinition.TEXT, + false, + getParamDisplayLabel(PARAM_FLATTEN_PATH))); + } +}