ALF-4128 : F99 transfer service (alien invader)

implementation check point - some testing complete.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21637 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2010-08-05 13:17:56 +00:00
parent 2c97a0e38b
commit ff2b31480d
11 changed files with 2384 additions and 796 deletions

View File

@@ -19,10 +19,12 @@
package org.alfresco.repo.transfer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import org.alfresco.repo.transfer.manifest.TransferManifestDeletedNode;
import org.alfresco.repo.transfer.manifest.TransferManifestHeader;
@@ -46,12 +48,11 @@ import org.apache.commons.logging.LogFactory;
* which exist in the target repository that do not exist in the source repository.
*
* If the transfer is not "sync" then this processor does nothing.
*
*/
public class RepoTertiaryManifestProcessorImpl extends AbstractManifestProcessorBase
{
private NodeService nodeService;
private CorrespondingNodeResolver nodeResolver;
private AlienProcessor alienProcessor;
private static final Log log = LogFactory.getLog(RepoTertiaryManifestProcessorImpl.class);
@@ -83,7 +84,7 @@ public class RepoTertiaryManifestProcessorImpl extends AbstractManifestProcessor
protected void processNode(TransferManifestNormalNode node)
{
NodeRef nodeRef = node.getNodeRef();
log.debug("processNode " + nodeRef);
log.debug("processNode : " + nodeRef);
if(isSync)
{
@@ -94,7 +95,10 @@ public class RepoTertiaryManifestProcessorImpl extends AbstractManifestProcessor
for(ChildAssociationRef ref : expectedChildren)
{
log.debug("expecting child" + ref);
if(log.isDebugEnabled())
{
log.debug("expecting child" + ref);
}
expectedChildNodeRefs.add(ref.getChildRef());
}
@@ -103,6 +107,7 @@ public class RepoTertiaryManifestProcessorImpl extends AbstractManifestProcessor
if(nodeService.exists(nodeRef))
{
log.debug("destination node exists");
/**
* yes this node exists in the destination.
*/
@@ -126,8 +131,10 @@ public class RepoTertiaryManifestProcessorImpl extends AbstractManifestProcessor
{
/**
* An unexpected child - if this node has been transferred then
* it needs to be deleted. If it is a local node then we don't
* touch it.
* it needs to be deleted.
*
* another repository then we have to prune the alien children
* rather than deleting it.
*/
log.debug("an unexpected child node:" + child);
if(nodeService.hasAspect(childNodeRef, TransferModel.ASPECT_TRANSFERRED))
@@ -141,10 +148,22 @@ public class RepoTertiaryManifestProcessorImpl extends AbstractManifestProcessor
if(manifestRepositoryId.equalsIgnoreCase(fromRepositoryId))
{
// Yes the manifest repository Id and the from repository Id match.
// Destination node needs to be deleted.
nodeService.deleteNode(childNodeRef);
log.debug("deleted node:" + childNodeRef);
if(nodeService.hasAspect(childNodeRef, TransferModel.ASPECT_ALIEN))
{
/**
* This node can't be deleted since it contains alien content
* it needs to be "pruned" of the transferring repo's content instead.
*/
log.debug("node to be deleted contains alien content so needs to be pruned." + childNodeRef);
alienProcessor.pruneNode(childNodeRef, fromRepositoryId);
//pruneNode(childNodeRef, fromRepositoryId);
}
else
{
// Destination node needs to be deleted.
nodeService.deleteNode(childNodeRef);
log.debug("deleted node:" + childNodeRef);
}
}
}
}
@@ -182,13 +201,169 @@ public class RepoTertiaryManifestProcessorImpl extends AbstractManifestProcessor
{
this.nodeService = nodeService;
}
// /**
// * Prune out the non aliens from the specified repository
// *
// * Need to walk the tree downwards pruning any aliens for this repository
// *
// * Also any folders remaining need to have their invaded by field rippled upwards since they may no
// * longer be invaded by the specified repository if all the alien children have been pruned.
// *
// * @param nodeRef the node to prune
// * @param fromRepositoryId the repository id of the nodes to prune.
// */
// private void pruneNode(NodeRef parentNodeRef, String fromRepositoryId)
// {
// Stack<NodeRef> nodesToPrune = new Stack<NodeRef>();
// Stack<NodeRef> foldersToRecalculate = new Stack<NodeRef>();
// nodesToPrune.add(parentNodeRef);
//
// while(!nodesToPrune.isEmpty())
// {
// /**
// * for all alien children
// *
// * if from the repo with no (other) aliens - delete
// *
// * if from the repo with multiple alien invasions - leave alone but process children
// */
// NodeRef currentNodeRef = nodesToPrune.pop();
//
// log.debug("pruneNode:" + currentNodeRef);
//
// if(nodeService.hasAspect(currentNodeRef, TransferModel.ASPECT_ALIEN))
// {
// // Yes this is an alien node
// List<String>invadedBy = (List<String>)nodeService.getProperty(currentNodeRef, TransferModel.PROP_INVADED_BY);
// if(invadedBy.contains(fromRepositoryId))
// {
// if(invadedBy.size() == 1)
// {
// // we are invaded by a single repository which must be fromRepositoryId
// log.debug("pruned - deleted node:" + currentNodeRef);
// nodeService.deleteNode(currentNodeRef);
// }
// else
// {
// log.debug("folder has multiple invaders");
// // multiple invasion - so it must be a folder
// //TODO replace with a more efficient query
// List<ChildAssociationRef> refs = nodeService.getChildAssocs(parentNodeRef);
// for(ChildAssociationRef ref : refs)
// {
// if(log.isDebugEnabled())
// {
// log.debug("will need to check child:" + ref);
// }
// nodesToPrune.push(ref.getChildRef());
//
// /**
// * This folder can't be deleted so its invaded flag needs to be re-calculated
// */
// if(!foldersToRecalculate.contains(ref.getParentRef()))
// {
// foldersToRecalculate.push(ref.getParentRef());
// }
// }
// }
// }
// else
// {
// /**
// * Current node has been invaded by another repository
// *
// * Need to check fromRepositoryId since its children may need to be pruned
// */
// nodeService.hasAspect(currentNodeRef, TransferModel.ASPECT_TRANSFERRED);
// {
// String fromRepoId = (String)nodeService.getProperty(currentNodeRef, TransferModel.PROP_FROM_REPOSITORY_ID);
// if(fromRepositoryId.equalsIgnoreCase(fromRepoId))
// {
// log.debug("folder is from the transferring repository");
// // invaded from somewhere else - so it must be a folder
// List<ChildAssociationRef> refs = nodeService.getChildAssocs(currentNodeRef);
// for(ChildAssociationRef ref : refs)
// {
// if(log.isDebugEnabled())
// {
// log.debug("will need to check child:" + ref);
// }
// nodesToPrune.push(ref.getChildRef());
//
// /**
// * This folder can't be deleted so its invaded flag needs to be re-calculated
// */
// if(!foldersToRecalculate.contains(ref.getParentRef()))
// {
// foldersToRecalculate.push(ref.getParentRef());
// }
// }
// }
// }
// }
// }
// else
// {
// // Current node does not contain alien nodes so it can be deleted.
// nodeService.hasAspect(currentNodeRef, TransferModel.ASPECT_TRANSFERRED);
// {
// String fromRepoId = (String)nodeService.getProperty(currentNodeRef, TransferModel.PROP_FROM_REPOSITORY_ID);
// if(fromRepositoryId.equalsIgnoreCase(fromRepoId))
// {
// // we are invaded by a single repository
// log.debug("pruned - deleted non alien node:" + currentNodeRef);
// nodeService.deleteNode(currentNodeRef);
// }
// }
// }
// }
//
// /**
// * Now ripple the "invadedBy" flag upwards.
// */
//
// while(!foldersToRecalculate.isEmpty())
// {
// NodeRef folderNodeRef = foldersToRecalculate.pop();
//
// log.debug("recalculate invadedBy :" + folderNodeRef);
//
// List<String>folderInvadedBy = (List<String>)nodeService.getProperty(folderNodeRef, TransferModel.PROP_INVADED_BY);
//
// boolean stillInvaded = false;
// //TODO need a more efficient query here
// List<ChildAssociationRef> refs = nodeService.getChildAssocs(folderNodeRef);
// for(ChildAssociationRef ref : refs)
// {
// NodeRef childNode = ref.getChildRef();
// List<String>childInvadedBy = (List<String>)nodeService.getProperty(childNode, TransferModel.PROP_INVADED_BY);
//
// if(childInvadedBy.contains(fromRepositoryId))
// {
// log.debug("folder is still invaded");
// stillInvaded = true;
// break;
// }
// }
//
// if(!stillInvaded)
// {
// List<String> newInvadedBy = new ArrayList<String>(folderInvadedBy);
// folderInvadedBy.remove(fromRepositoryId);
// nodeService.setProperty(folderNodeRef, TransferModel.PROP_INVADED_BY, (Serializable)newInvadedBy);
// }
// }
// log.debug("pruneNode: end");
// }
/**
* @param nodeResolver
* the nodeResolver to set
*/
public void setNodeResolver(CorrespondingNodeResolver nodeResolver)
public void setAlienProcessor(AlienProcessor alienProcessor)
{
this.nodeResolver = nodeResolver;
this.alienProcessor = alienProcessor;
}
public AlienProcessor getAlienProcessor()
{
return alienProcessor;
}
}