mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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
This commit is contained in:
@@ -436,4 +436,12 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="avm-revert-list" class="org.alfresco.repo.avm.actions.AVMRevertListAction" parent="action-executer">
|
||||||
|
<property name="avmSyncService">
|
||||||
|
<ref bean="avmSyncService"/>
|
||||||
|
</property>
|
||||||
|
<property name="publicAction">
|
||||||
|
<value>false</value>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -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.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.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.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
|
||||||
|
@@ -33,9 +33,11 @@ import java.util.TreeMap;
|
|||||||
import org.alfresco.model.ContentModel;
|
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.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;
|
||||||
|
import org.alfresco.repo.avm.util.VersionPathStuffer;
|
||||||
import org.alfresco.repo.domain.PropertyValue;
|
import org.alfresco.repo.domain.PropertyValue;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
import org.alfresco.repo.transaction.TransactionUtil;
|
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<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(),
|
||||||
|
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<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());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the promote action.
|
* Test the promote action.
|
||||||
*/
|
*/
|
||||||
|
@@ -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<Pair<Integer, String>> versionPaths = unstuffer.getVersionPaths();
|
||||||
|
List<AVMDifference> diffs = new ArrayList<AVMDifference>();
|
||||||
|
for (Pair<Integer, String> item : versionPaths)
|
||||||
|
{
|
||||||
|
List<AVMDifference> 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<ParameterDefinition> 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)));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user