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:
Britt Park
2007-01-14 00:56:55 +00:00
parent 6d2dbe50e2
commit 0adccaeca8
17 changed files with 200 additions and 32 deletions

View File

@@ -458,9 +458,6 @@
</bean> </bean>
<bean id="avm-revert-to-version" class="org.alfresco.repo.avm.actions.AVMRevertToVersionAction" parent = "action-executer"> <bean id="avm-revert-to-version" class="org.alfresco.repo.avm.actions.AVMRevertToVersionAction" parent = "action-executer">
<property name="avmSyncService">
<ref bean="avmSyncService"/>
</property>
<property name="avmService"> <property name="avmService">
<ref bean="avmService"/> <ref bean="avmService"/>
</property> </property>

View File

@@ -64,4 +64,18 @@
</types> </types>
<aspects>
<!-- Captures the node that a node was reverted from. -->
<aspect name="wcm:reverted">
<title>Contains a reference to the node that this node was reverted from.</title>
<properties>
<property name="wcm:revertedid">
<title>The id of the node this was reverted from.</title>
<type>d:long</type>
<mandatory>true</mandatory>
</property>
</properties>
</aspect>
</aspects>
</model> </model>

View File

@@ -36,4 +36,8 @@ public interface WCMModel
static final QName TYPE_AVM_PLAIN_FOLDER = QName.createQName(NamespaceService.WCM_MODEL_1_0_URI, "avmplainfolder"); static final QName TYPE_AVM_PLAIN_FOLDER = QName.createQName(NamespaceService.WCM_MODEL_1_0_URI, "avmplainfolder");
static final QName TYPE_AVM_LAYERED_FOLDER = QName.createQName(NamespaceService.WCM_MODEL_1_0_URI, "avmlayeredfolder"); static final QName TYPE_AVM_LAYERED_FOLDER = QName.createQName(NamespaceService.WCM_MODEL_1_0_URI, "avmlayeredfolder");
static final QName PROP_AVM_DIR_INDIRECTION = QName.createQName(NamespaceService.WCM_MODEL_1_0_URI, "avmdirindirection"); static final QName PROP_AVM_DIR_INDIRECTION = QName.createQName(NamespaceService.WCM_MODEL_1_0_URI, "avmdirindirection");
// Reverted Aspect.
static final QName ASPECT_REVERTED = QName.createQName(NamespaceService.WCM_MODEL_1_0_URI, "reverted");
static final QName PROP_REVERTED_ID = QName.createQName(NamespaceService.WCM_MODEL_1_0_URI, "revertedid");
} }

View File

@@ -35,6 +35,12 @@ public interface AVMNode
*/ */
public void setAncestor(AVMNode ancestor); 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. * Get the ancestor of this node.
* @return The ancestor of this node. * @return The ancestor of this node.

View File

@@ -121,6 +121,20 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
AVMDAOs.Instance().fHistoryLinkDAO.save(link); 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. * Get the ancestor of this node.
* @return The ancestor of this node. * @return The ancestor of this node.

View File

@@ -479,4 +479,12 @@ public class AVMRemoteLocal implements AVMRemote
{ {
fService.removeAspect(path, aspectName); 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);
}
} }

View File

@@ -999,4 +999,13 @@ public class AVMRemoteTransportService implements AVMRemoteTransport, Runnable
fAuthService.validate(ticket); fAuthService.validate(ticket);
fAVMService.removeAspect(path, aspectName); 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);
}
} }

View File

@@ -2338,4 +2338,32 @@ public class AVMRepository
fPurgeStoreTxnListener.storePurged(sourceName); fPurgeStoreTxnListener.storePurged(sourceName);
fCreateStoreTxnListener.storeCreated(destName); 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);
}
}
} }

View File

@@ -511,7 +511,7 @@ public class AVMServiceImpl implements AVMService
String [] basePath = AVMNodeConverter.SplitBase(path); String [] basePath = AVMNodeConverter.SplitBase(path);
if (basePath[0] == null) if (basePath[0] == null)
{ {
throw new AVMBadArgumentException("Cannot remove root node."); throw new AVMBadArgumentException("Cannot remove root node: " + path);
} }
AlfrescoTransactionSupport.bindListener(fTransactionListener); AlfrescoTransactionSupport.bindListener(fTransactionListener);
fAVMRepository.remove(basePath[0], basePath[1]); fAVMRepository.remove(basePath[0], basePath[1]);
@@ -1417,4 +1417,27 @@ public class AVMServiceImpl implements AVMService
} }
fAVMRepository.renameStore(sourceName, destName); 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);
}
} }

View File

@@ -109,7 +109,6 @@ public class AVMServiceTest extends AVMServiceTestBase
}; };
TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"), TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"),
new TxnWork()); new TxnWork());
assertEquals(toRevert.getId(), fService.lookup(-1, "main:/a/b/c/foo").getId());
} }
catch (Exception e) catch (Exception e)
{ {

View File

@@ -454,4 +454,14 @@ public interface AVMStore
* @param toLink The node to link. * @param toLink The node to link.
*/ */
public void link(String parentPath, String name, AVMNodeDescriptor toLink); 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);
} }

View File

@@ -30,6 +30,8 @@ import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import org.alfresco.model.ContentModel; 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.RawServices;
import org.alfresco.repo.avm.util.SimplePath; import org.alfresco.repo.avm.util.SimplePath;
import org.alfresco.repo.domain.DbAccessControlList; import org.alfresco.repo.domain.DbAccessControlList;
@@ -1305,4 +1307,46 @@ public class AVMStoreImpl implements AVMStore, Serializable
DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode();
dir.link(lPath, name, toLink); 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);
}
} }

View File

@@ -3,10 +3,8 @@
*/ */
package org.alfresco.repo.avm.actions; package org.alfresco.repo.avm.actions;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.action.ParameterDefinitionImpl; import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.avm.AVMNodeConverter; 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.action.ParameterDefinition;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMService; 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.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
@@ -37,8 +33,6 @@ public class AVMRevertToVersionAction extends ActionExecuterAbstractBase
private AVMService fAVMService; private AVMService fAVMService;
private AVMSyncService fAVMSyncService;
/** /**
* Set the AVMService. * Set the AVMService.
*/ */
@@ -47,14 +41,6 @@ public class AVMRevertToVersionAction extends ActionExecuterAbstractBase
fAVMService = service; fAVMService = service;
} }
/**
* Set the AVMSyncService.
*/
public void setAvmSyncService(AVMSyncService service)
{
fAVMSyncService = service;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) * @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); AVMNodeConverter.ToAVMVersionPath(actionedUponNodeRef);
AVMNodeDescriptor toRevert = AVMNodeDescriptor toRevert =
(AVMNodeDescriptor)action.getParameterValue(TOREVERT); (AVMNodeDescriptor)action.getParameterValue(TOREVERT);
List<Pair<Integer, String>> paths = fAVMService.getPaths(toRevert); fAVMService.revert(versionPath.getSecond(), 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);
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@@ -483,4 +483,12 @@ public class AVMRemoteImpl implements AVMRemote
{ {
fTransport.removeAspect(ClientTicketHolder.GetTicket(), path, aspectName); fTransport.removeAspect(ClientTicketHolder.GetTicket(), 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)
{
fTransport.revert(ClientTicketHolder.GetTicket(), path, toRevertTo);
}
} }

View File

@@ -800,4 +800,14 @@ public interface AVMService
* @throws AVMExistsException * @throws AVMExistsException
*/ */
public void renameStore(String sourceName, String destName); public void renameStore(String sourceName, String 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);
} }

View File

@@ -443,4 +443,14 @@ public interface AVMRemote
* @throws AVMNotFoundException * @throws AVMNotFoundException
*/ */
public boolean hasAspect(int version, String path, QName aspectName); public boolean hasAspect(int version, String path, QName aspectName);
/**
* 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);
} }

View File

@@ -461,4 +461,14 @@ public interface AVMRemoteTransport
* @throws AVMNotFoundException * @throws AVMNotFoundException
*/ */
public boolean hasAspect(String ticket, int version, String path, QName aspectName); public boolean hasAspect(String ticket, int version, String path, QName aspectName);
/**
* 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 ticket, String path, AVMNodeDescriptor toRevertTo);
} }