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
This commit is contained in:
Britt Park
2006-11-15 20:40:27 +00:00
parent 2cab072bc1
commit a4e9b2fd6f
6 changed files with 171 additions and 0 deletions

View File

@@ -444,4 +444,13 @@
<value>false</value> <value>false</value>
</property> </property>
</bean> </bean>
<bean id="avm-undo-list" class="org.alfresco.repo.avm.actions.AVMUndoSandboxListAction" parent="action-executer">
<property name="avmService">
<ref bean="avmService"/>
</property>
<property name="publicAction">
<value>false</value>
</property>
</bean>
</beans> </beans>

View File

@@ -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.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-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.title=Start a WCM Workflow
start-avm-workflow.description=Starts a workflow expecting an AVM workflow package start-avm-workflow.description=Starts a workflow expecting an AVM workflow package
start-avm-workflow.store-name.display-label=Store name for start task start-avm-workflow.store-name.display-label=Store name for start task

View File

@@ -439,6 +439,21 @@ public class AVMServiceImpl implements AVMService
fAVMRepository.uncover(dirPath, name); 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. * Get the Latest Version ID for an AVMStore.
* @param repName The name of the AVMStore. * @param repName The name of the AVMStore.

View File

@@ -34,6 +34,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.model.WCMModel; import org.alfresco.model.WCMModel;
import org.alfresco.repo.action.ActionImpl; import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.avm.actions.AVMRevertListAction; 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.SimpleAVMPromoteAction;
import org.alfresco.repo.avm.actions.SimpleAVMSubmitAction; import org.alfresco.repo.avm.actions.SimpleAVMSubmitAction;
import org.alfresco.repo.avm.util.BulkLoader; import org.alfresco.repo.avm.util.BulkLoader;
@@ -283,6 +284,53 @@ public class AVMServiceTest extends AVMServiceTestBase
} }
} }
/**
* 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<AVMDifference> 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<Object>
{
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. * Test the promote action.
*/ */

View File

@@ -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<Pair<Integer, String>> versionPaths = unstuffer.getVersionPaths();
for (Pair<Integer, String> 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<ParameterDefinition> paramList)
{
paramList.add(
new ParameterDefinitionImpl(PARAM_NODE_LIST,
DataTypeDefinition.TEXT,
true,
getParamDisplayLabel(PARAM_NODE_LIST)));
}
}

View File

@@ -295,6 +295,14 @@ public interface AVMService
*/ */
public void uncover(String dirPath, String name); 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. * Get the latest version id of the AVMStore.
* @param storeName The name of the AVMStore. * @param storeName The name of the AVMStore.