From a4e9b2fd6f0c2172fb979650e3639c7ad89c61f3 Mon Sep 17 00:00:00 2001 From: Britt Park Date: Wed, 15 Nov 2006 20:40:27 +0000 Subject: [PATCH] This is an action to undo a list of changes made in a user sandbox, relative to the staging sandbox. Turns out yesterday's revert action isn't quite what is wanted for this use case. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4366 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/action-services-context.xml | 9 ++ .../messages/action-config.properties | 4 + .../org/alfresco/repo/avm/AVMServiceImpl.java | 15 ++++ .../org/alfresco/repo/avm/AVMServiceTest.java | 48 ++++++++++ .../avm/actions/AVMUndoSandboxListAction.java | 87 +++++++++++++++++++ .../alfresco/service/cmr/avm/AVMService.java | 8 ++ 6 files changed, 171 insertions(+) create mode 100644 source/java/org/alfresco/repo/avm/actions/AVMUndoSandboxListAction.java diff --git a/config/alfresco/action-services-context.xml b/config/alfresco/action-services-context.xml index db79de5922..cd131c9bd6 100644 --- a/config/alfresco/action-services-context.xml +++ b/config/alfresco/action-services-context.xml @@ -444,4 +444,13 @@ false + + + + + + + false + + diff --git a/config/alfresco/messages/action-config.properties b/config/alfresco/messages/action-config.properties index 4f51e5c6fb..4f1cf4e20a 100644 --- a/config/alfresco/messages/action-config.properties +++ b/config/alfresco/messages/action-config.properties @@ -107,6 +107,10 @@ avm-revert-list.store.display-label=The name of the store being reverted, only n 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. +avm-undo-list.title=Make a list of Nodes in a store transparent to staging. +avm-undo-list.description=This acts as a mistake eraser for a user's sandbox. +avm-undo-list.node-list.display-label=The string encoded list of nodes to revert. + start-avm-workflow.title=Start a WCM Workflow start-avm-workflow.description=Starts a workflow expecting an AVM workflow package start-avm-workflow.store-name.display-label=Store name for start task diff --git a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java index 60b3bcf089..788a815564 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java @@ -439,6 +439,21 @@ public class AVMServiceImpl implements AVMService fAVMRepository.uncover(dirPath, name); } + /** + * Make name in dirPath transparent to what was underneath it. That is, this + * removes the offending node from its layered directory parent's direct ownership. + * @param dirPath The path to the layered directory. + * @param name The name of the item to flatten. + */ + public void flatten(String dirPath, String name) + { + if (dirPath == null || name == null) + { + throw new AVMBadArgumentException("Illegal null argument."); + } + fAVMRepository.flatten(dirPath, name); + } + /** * Get the Latest Version ID for an AVMStore. * @param repName The name of the AVMStore. diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index 941f3dee04..d2d94fd11c 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -34,6 +34,7 @@ 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.AVMUndoSandboxListAction; import org.alfresco.repo.avm.actions.SimpleAVMPromoteAction; import org.alfresco.repo.avm.actions.SimpleAVMSubmitAction; import org.alfresco.repo.avm.util.BulkLoader; @@ -282,6 +283,53 @@ public class AVMServiceTest extends AVMServiceTestBase fail(); } } + + /** + * Test the undo list action. + */ + public void testUndoListAction() + { + 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(), + AVMUndoSandboxListAction.NAME); + VersionPathStuffer stuffer = new VersionPathStuffer(); + stuffer.add(-1, "area:/a/b/c/bar"); + String nodeList = stuffer.toString(); + action.setParameterValue(AVMUndoSandboxListAction.PARAM_NODE_LIST, nodeList); + final AVMUndoSandboxListAction revert = (AVMUndoSandboxListAction)fContext.getBean("avm-undo-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()); + System.out.println(recursiveList("area", -1, true)); + System.out.println(recursiveList("main", -1, true)); + } + catch (Exception e) + { + e.printStackTrace(); + fail(); + } + } /** * Test the promote action. diff --git a/source/java/org/alfresco/repo/avm/actions/AVMUndoSandboxListAction.java b/source/java/org/alfresco/repo/avm/actions/AVMUndoSandboxListAction.java new file mode 100644 index 0000000000..fbec29615b --- /dev/null +++ b/source/java/org/alfresco/repo/avm/actions/AVMUndoSandboxListAction.java @@ -0,0 +1,87 @@ +/** + * + */ +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.repo.avm.util.VersionPathUnstuffer; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ParameterDefinition; +import org.alfresco.service.cmr.avm.AVMNodeDescriptor; +import org.alfresco.service.cmr.avm.AVMService; +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; + +/** + * Undos a list of changed nodes in a user sandbox. The set of nodes to undo is + * passed in as a packed string (Obtained by VersionPathStuffer). + * The actionedUponNodeRef is a dummy and can be null. + * @author britt + */ +public class AVMUndoSandboxListAction extends ActionExecuterAbstractBase +{ + private static Logger fgLogger = Logger.getLogger(AVMUndoSandboxListAction.class); + + public static final String NAME = "avm-undo-list"; + // The encoded list of nodes. + public static final String PARAM_NODE_LIST = "node-list"; + + /** + * The AVM Service reference. + */ + private AVMService fAVMService; + + public void setAvmService(AVMService service) + { + fAVMService = 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) + { + String packedNodes = (String)action.getParameterValue(PARAM_NODE_LIST); + VersionPathUnstuffer unstuffer = new VersionPathUnstuffer(packedNodes); + List> versionPaths = unstuffer.getVersionPaths(); + for (Pair item : versionPaths) + { + AVMNodeDescriptor desc = fAVMService.lookup(-1, item.getSecond(), true); + if (desc == null) + { + continue; + } + String [] parentChild = AVMNodeConverter.SplitBase(item.getSecond()); + if (parentChild.length != 2) + { + continue; + } + AVMNodeDescriptor parent = fAVMService.lookup(-1, parentChild[0], true); + if (parent.isLayeredDirectory()) + { + fAVMService.flatten(parentChild[0], parentChild[1]); + } + } + } + + /* (non-Javadoc) + * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List) + */ + @Override + protected void addParameterDefinitions(List paramList) + { + paramList.add( + new ParameterDefinitionImpl(PARAM_NODE_LIST, + DataTypeDefinition.TEXT, + true, + getParamDisplayLabel(PARAM_NODE_LIST))); + } +} diff --git a/source/java/org/alfresco/service/cmr/avm/AVMService.java b/source/java/org/alfresco/service/cmr/avm/AVMService.java index 00782224f2..619898a474 100644 --- a/source/java/org/alfresco/service/cmr/avm/AVMService.java +++ b/source/java/org/alfresco/service/cmr/avm/AVMService.java @@ -295,6 +295,14 @@ public interface AVMService */ public void uncover(String dirPath, String name); + /** + * Make name in dirPath transparent to what was underneath it. That is, this + * removes the offending node from its layered directory parent's direct ownership. + * @param dirPath The path to the layered directory. + * @param name The name of the item to flatten. + */ + public void flatten(String dirPath, String name); + /** * Get the latest version id of the AVMStore. * @param storeName The name of the AVMStore.