mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Made revert to version behave better. Now when a node is reverted a clone of
the version being reverted to is created. This clone has the previous head version as its ancestor and a wcm:reverted aspect applied. wcm:reverted contains wcm:revertedid, the node id that the reversion is a clone of. Revert to version is now a simple call to a new AVMService method, revert(). Propagated this to the remote API. Modified the the AVMRevertToVersionAction to use this mechanism. Though really the action isn't really needed now. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4824 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -34,6 +34,12 @@ public interface AVMNode
|
||||
* @param ancestor The ancestor to set.
|
||||
*/
|
||||
public void setAncestor(AVMNode ancestor);
|
||||
|
||||
/**
|
||||
* Change the ancestor of a node.
|
||||
* @param ancestor The ancestor node that should be set.
|
||||
*/
|
||||
public void changeAncestor(AVMNode ancestor);
|
||||
|
||||
/**
|
||||
* Get the ancestor of this node.
|
||||
|
@@ -121,6 +121,20 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
|
||||
AVMDAOs.Instance().fHistoryLinkDAO.save(link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the ancestor of this node.
|
||||
* @param ancestor The new ancestor to give it.
|
||||
*/
|
||||
public void changeAncestor(AVMNode ancestor)
|
||||
{
|
||||
HistoryLink old = AVMDAOs.Instance().fHistoryLinkDAO.getByDescendent(this);
|
||||
if (old != null)
|
||||
{
|
||||
AVMDAOs.Instance().fHistoryLinkDAO.delete(old);
|
||||
}
|
||||
setAncestor(ancestor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ancestor of this node.
|
||||
* @return The ancestor of this node.
|
||||
|
@@ -479,4 +479,12 @@ public class AVMRemoteLocal implements AVMRemote
|
||||
{
|
||||
fService.removeAspect(path, aspectName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.AVMRemote#revert(java.lang.String, org.alfresco.service.cmr.avm.AVMNodeDescriptor)
|
||||
*/
|
||||
public void revert(String path, AVMNodeDescriptor toRevertTo)
|
||||
{
|
||||
fService.revert(path, toRevertTo);
|
||||
}
|
||||
}
|
||||
|
@@ -999,4 +999,13 @@ public class AVMRemoteTransportService implements AVMRemoteTransport, Runnable
|
||||
fAuthService.validate(ticket);
|
||||
fAVMService.removeAspect(path, aspectName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.AVMRemoteTransport#revert(java.lang.String, java.lang.String, org.alfresco.service.cmr.avm.AVMNodeDescriptor)
|
||||
*/
|
||||
public void revert(String ticket, String path, AVMNodeDescriptor toRevertTo)
|
||||
{
|
||||
fAuthService.validate(ticket);
|
||||
fAVMService.revert(path, toRevertTo);
|
||||
}
|
||||
}
|
||||
|
@@ -2338,4 +2338,32 @@ public class AVMRepository
|
||||
fPurgeStoreTxnListener.storePurged(sourceName);
|
||||
fCreateStoreTxnListener.storeCreated(destName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert a head path to a given version. This works by cloning
|
||||
* the version to revert to, and then linking that new version into head.
|
||||
* The reverted version will have the previous head version as ancestor.
|
||||
* @param path The path to the parent directory.
|
||||
* @param name The name of the node.
|
||||
* @param toRevertTo The descriptor of the version to revert to.
|
||||
*/
|
||||
public void revert(String path, String name, AVMNodeDescriptor toRevertTo)
|
||||
{
|
||||
fLookupCount.set(1);
|
||||
try
|
||||
{
|
||||
String [] pathParts = SplitPath(path);
|
||||
AVMStore store = getAVMStoreByName(pathParts[0]);
|
||||
if (store == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Store not found: " + pathParts[0]);
|
||||
}
|
||||
fLookupCache.onWrite(pathParts[0]);
|
||||
store.revert(pathParts[1], name, toRevertTo);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fLookupCount.set(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -511,7 +511,7 @@ public class AVMServiceImpl implements AVMService
|
||||
String [] basePath = AVMNodeConverter.SplitBase(path);
|
||||
if (basePath[0] == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Cannot remove root node.");
|
||||
throw new AVMBadArgumentException("Cannot remove root node: " + path);
|
||||
}
|
||||
AlfrescoTransactionSupport.bindListener(fTransactionListener);
|
||||
fAVMRepository.remove(basePath[0], basePath[1]);
|
||||
@@ -1417,4 +1417,27 @@ public class AVMServiceImpl implements AVMService
|
||||
}
|
||||
fAVMRepository.renameStore(sourceName, destName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert a head path to a given version. This works by cloning
|
||||
* the version to revert to, and then linking that new version into head.
|
||||
* The reverted version will have the previous head version as ancestor.
|
||||
* @param path The path to the node to revert.
|
||||
* @param toRevertTo The descriptor of the version to revert to.
|
||||
* @throws AVMNotFoundException
|
||||
*/
|
||||
public void revert(String path, AVMNodeDescriptor toRevertTo)
|
||||
{
|
||||
if (path == null || toRevertTo == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Illegal Null Argument.");
|
||||
}
|
||||
String [] baseName = AVMNodeConverter.SplitBase(path);
|
||||
if (baseName.length != 2)
|
||||
{
|
||||
throw new AVMBadArgumentException("Cannot revert store root: " + path);
|
||||
}
|
||||
AlfrescoTransactionSupport.bindListener(fTransactionListener);
|
||||
fAVMRepository.revert(baseName[0], baseName[1], toRevertTo);
|
||||
}
|
||||
}
|
||||
|
@@ -109,7 +109,6 @@ public class AVMServiceTest extends AVMServiceTestBase
|
||||
};
|
||||
TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"),
|
||||
new TxnWork());
|
||||
assertEquals(toRevert.getId(), fService.lookup(-1, "main:/a/b/c/foo").getId());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@@ -454,4 +454,14 @@ public interface AVMStore
|
||||
* @param toLink The node to link.
|
||||
*/
|
||||
public void link(String parentPath, String name, AVMNodeDescriptor toLink);
|
||||
|
||||
/**
|
||||
* Revert a head path to a given version. This works by cloning
|
||||
* the version to revert to, and then linking that new version into head.
|
||||
* The reverted version will have the previous head version as ancestor.
|
||||
* @param path The path to the parent directory.
|
||||
* @param name The name of the node to revert.
|
||||
* @param toRevertTo The descriptor of the version to revert to.
|
||||
*/
|
||||
public void revert(String path, String name, AVMNodeDescriptor toRevertTo);
|
||||
}
|
@@ -30,6 +30,8 @@ import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.WCMModel;
|
||||
import org.alfresco.repo.avm.AVMAspectName;
|
||||
import org.alfresco.repo.avm.util.RawServices;
|
||||
import org.alfresco.repo.avm.util.SimplePath;
|
||||
import org.alfresco.repo.domain.DbAccessControlList;
|
||||
@@ -1305,4 +1307,46 @@ public class AVMStoreImpl implements AVMStore, Serializable
|
||||
DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode();
|
||||
dir.link(lPath, name, toLink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert a head path to a given version. This works by cloning
|
||||
* the version to revert to, and then linking that new version into head.
|
||||
* The reverted version will have the previous head version as ancestor.
|
||||
* @param path The path to the parent directory.
|
||||
* @param name The name of the node to revert.
|
||||
* @param toRevertTo The descriptor of the version to revert to.
|
||||
*/
|
||||
public void revert(String path, String name, AVMNodeDescriptor toRevertTo)
|
||||
{
|
||||
Lookup lPath = lookupDirectory(-1, path, true);
|
||||
if (lPath == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Path " + path + " not found.");
|
||||
}
|
||||
DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode();
|
||||
AVMNode child = dir.lookupChild(lPath, name, true);
|
||||
if (child == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Node not found: " + name);
|
||||
}
|
||||
AVMNode revertNode = AVMDAOs.Instance().fAVMNodeDAO.getByID(toRevertTo.getId());
|
||||
if (revertNode == null)
|
||||
{
|
||||
throw new AVMNotFoundException(toRevertTo.toString());
|
||||
}
|
||||
AVMNode toLink = revertNode.copy(lPath);
|
||||
dir.putChild(name, toLink);
|
||||
toLink.changeAncestor(child);
|
||||
toLink.setVersionID(child.getVersionID() + 1);
|
||||
if (AVMDAOs.Instance().fAVMAspectNameDAO.exists(toLink, WCMModel.ASPECT_REVERTED))
|
||||
{
|
||||
AVMDAOs.Instance().fAVMAspectNameDAO.delete(toLink, WCMModel.ASPECT_REVERTED);
|
||||
}
|
||||
AVMAspectName aspect = new AVMAspectNameImpl();
|
||||
aspect.setNode(toLink);
|
||||
aspect.setName(WCMModel.ASPECT_REVERTED);
|
||||
AVMDAOs.Instance().fAVMAspectNameDAO.save(aspect);
|
||||
PropertyValue value = new PropertyValue(null, toRevertTo.getId());
|
||||
toLink.setProperty(WCMModel.PROP_REVERTED_ID, value);
|
||||
}
|
||||
}
|
||||
|
@@ -3,10 +3,8 @@
|
||||
*/
|
||||
package org.alfresco.repo.avm.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
||||
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
@@ -14,8 +12,6 @@ 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.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;
|
||||
@@ -37,8 +33,6 @@ public class AVMRevertToVersionAction extends ActionExecuterAbstractBase
|
||||
|
||||
private AVMService fAVMService;
|
||||
|
||||
private AVMSyncService fAVMSyncService;
|
||||
|
||||
/**
|
||||
* Set the AVMService.
|
||||
*/
|
||||
@@ -47,14 +41,6 @@ public class AVMRevertToVersionAction extends ActionExecuterAbstractBase
|
||||
fAVMService = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the AVMSyncService.
|
||||
*/
|
||||
public void setAvmSyncService(AVMSyncService service)
|
||||
{
|
||||
fAVMSyncService = service;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@@ -65,19 +51,7 @@ public class AVMRevertToVersionAction extends ActionExecuterAbstractBase
|
||||
AVMNodeConverter.ToAVMVersionPath(actionedUponNodeRef);
|
||||
AVMNodeDescriptor toRevert =
|
||||
(AVMNodeDescriptor)action.getParameterValue(TOREVERT);
|
||||
List<Pair<Integer, String>> paths = fAVMService.getPaths(toRevert);
|
||||
if (paths.size() == 0)
|
||||
{
|
||||
fgLogger.error("Unable to find path for: " + toRevert);
|
||||
throw new AlfrescoRuntimeException("Could not find path for: " + toRevert);
|
||||
}
|
||||
AVMDifference diff = new AVMDifference(paths.get(0).getFirst(), paths.get(0).getSecond(),
|
||||
-1, versionPath.getSecond(),
|
||||
AVMDifference.NEWER);
|
||||
List<AVMDifference> diffs = new ArrayList<AVMDifference>(1);
|
||||
diffs.add(diff);
|
||||
String message = "Reverted " + versionPath.getSecond() + " to version in snapshot " + paths.get(0).getFirst() + ".";
|
||||
fAVMSyncService.update(diffs, null, false, false, true, true, "Reverted", message);
|
||||
fAVMService.revert(versionPath.getSecond(), toRevert);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
Reference in New Issue
Block a user