mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Checkpoint for AVMSyncService. Update (that's promote to use
preferred parlance or submit if you have a certain background) is substantially working, passing a handful of basic tests. Compare harmlessly returns no differences always, so Kev can program against it if he's so inclined. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3785 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -22,12 +22,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
|
||||
import org.alfresco.service.cmr.avm.AVMException;
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
import org.alfresco.service.cmr.avm.AVMNotFoundException;
|
||||
import org.alfresco.service.cmr.avm.AVMService;
|
||||
import org.alfresco.service.cmr.avm.AVMWrongTypeException;
|
||||
import org.alfresco.service.cmr.avmsync.AVMDifference;
|
||||
import org.alfresco.service.cmr.avmsync.AVMSyncException;
|
||||
import org.alfresco.service.cmr.avmsync.AVMSyncService;
|
||||
|
||||
/**
|
||||
@@ -85,17 +85,199 @@ public class AVMSyncServiceImpl implements AVMSyncService
|
||||
* will cause the transaction to roll back.
|
||||
* @param diffList A List of AVMDifference structs.
|
||||
* @param ignoreConflicts If this is true the update will skip those
|
||||
* AVMDifferences which are in conflict or for which the source is older than
|
||||
* AVMDifferences which are in conflict with
|
||||
* the destination.
|
||||
* @param ignoreOlder If this is true the update will skip those
|
||||
* AVMDifferences which have the source older than the destination.
|
||||
* @param overrideConflicts If this is true the update will override conflicting
|
||||
* AVMDifferences and replace the destination with the conflicting source.
|
||||
* @param overrideOlder If this is true the update will override AVMDifferences
|
||||
* in which the source is older than the destination and overwrite the destination.
|
||||
*/
|
||||
public void update(List<AVMDifference> diffList, boolean ignoreConflicts,
|
||||
public void update(List<AVMDifference> diffList, boolean ignoreConflicts, boolean ignoreOlder,
|
||||
boolean overrideConflicts, boolean overrideOlder)
|
||||
{
|
||||
// TODO Implement.
|
||||
for (AVMDifference diff : diffList)
|
||||
{
|
||||
if (!diff.isValid())
|
||||
{
|
||||
throw new AVMSyncException("Malformed AVMDifference.");
|
||||
}
|
||||
AVMNodeDescriptor srcDesc = fAVMService.lookup(diff.getSourceVersion(),
|
||||
diff.getSourcePath(), true);
|
||||
if (srcDesc == null)
|
||||
{
|
||||
throw new AVMSyncException("Source node not found: " + diff.getSourcePath());
|
||||
}
|
||||
String [] dstParts = AVMNodeConverter.SplitBase(diff.getDestinationPath());
|
||||
if (dstParts[0] == null || diff.getDestinationVersion() >= 0)
|
||||
{
|
||||
throw new AVMSyncException("Invalid destination node: " + diff.getDestinationPath());
|
||||
}
|
||||
AVMNodeDescriptor dstDesc = fAVMService.lookup(-1, diff.getDestinationPath(), true);
|
||||
int diffCode = AVMDifference.NEWER;
|
||||
if (dstDesc != null)
|
||||
{
|
||||
diffCode = compareOne(srcDesc, dstDesc);
|
||||
}
|
||||
switch (diffCode)
|
||||
{
|
||||
case AVMDifference.SAME :
|
||||
{
|
||||
continue;
|
||||
}
|
||||
case AVMDifference.NEWER :
|
||||
{
|
||||
if (dstDesc != null)
|
||||
{
|
||||
fAVMService.removeNode(dstParts[0], dstParts[1]);
|
||||
}
|
||||
fAVMService.link(dstParts[0], dstParts[1], srcDesc);
|
||||
continue;
|
||||
}
|
||||
case AVMDifference.OLDER :
|
||||
{
|
||||
if (overrideOlder)
|
||||
{
|
||||
fAVMService.removeNode(dstParts[0], dstParts[1]);
|
||||
fAVMService.link(dstParts[0], dstParts[1], srcDesc);
|
||||
continue;
|
||||
}
|
||||
if (ignoreOlder)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
throw new AVMSyncException("Older version prevents update.");
|
||||
}
|
||||
case AVMDifference.CONFLICT :
|
||||
{
|
||||
if (overrideConflicts)
|
||||
{
|
||||
fAVMService.removeNode(dstParts[0], dstParts[1]);
|
||||
fAVMService.link(dstParts[0], dstParts[1], srcDesc);
|
||||
continue;
|
||||
}
|
||||
if (ignoreConflicts)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
throw new AVMSyncException("Conflict prevents update.");
|
||||
}
|
||||
case AVMDifference.DIRECTORY :
|
||||
{
|
||||
if (ignoreConflicts)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
throw new AVMSyncException("Directory conflict prevents update.");
|
||||
}
|
||||
default :
|
||||
{
|
||||
throw new AVMSyncException("Invalid Differenc Code: Internal Error.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The workhorse of comparison and updating. Determine the versioning relationship
|
||||
* of two nodes.
|
||||
* @param srcDesc Descriptor for the source node.
|
||||
* @param dstDesc Descriptor for the destination node.
|
||||
* @return One of SAME, OLDER, NEWER, CONFLICT, DIRECTORY
|
||||
*/
|
||||
private int compareOne(AVMNodeDescriptor srcDesc, AVMNodeDescriptor dstDesc)
|
||||
{
|
||||
if (srcDesc.getId() == dstDesc.getId())
|
||||
{
|
||||
return AVMDifference.SAME;
|
||||
}
|
||||
// Matched directories that are not identical are operationally in conflict
|
||||
// but get their own special difference code.
|
||||
if (srcDesc.isDirectory() && dstDesc.isDirectory())
|
||||
{
|
||||
return AVMDifference.DIRECTORY;
|
||||
}
|
||||
// Check for mismatched fundamental types.
|
||||
if ((srcDesc.isDirectory() && dstDesc.isFile()) ||
|
||||
(srcDesc.isFile() && dstDesc.isDirectory()))
|
||||
{
|
||||
return AVMDifference.CONFLICT;
|
||||
}
|
||||
if (srcDesc.isDeleted() || dstDesc.isDeleted())
|
||||
{
|
||||
AVMNodeDescriptor common = fAVMService.getCommonAncestor(srcDesc, dstDesc);
|
||||
if (common == null)
|
||||
{
|
||||
return AVMDifference.CONFLICT;
|
||||
}
|
||||
if (common.getId() == srcDesc.getId())
|
||||
{
|
||||
return AVMDifference.OLDER;
|
||||
}
|
||||
if (common.getId() == dstDesc.getId())
|
||||
{
|
||||
return AVMDifference.NEWER;
|
||||
}
|
||||
// Must be a conflict.
|
||||
return AVMDifference.CONFLICT;
|
||||
}
|
||||
// At this point both source and destination are both some kind of file.
|
||||
if (srcDesc.isLayeredFile())
|
||||
{
|
||||
if (dstDesc.isPlainFile())
|
||||
{
|
||||
if (srcDesc.getIndirection().equals(dstDesc.getPath()))
|
||||
{
|
||||
return AVMDifference.SAME;
|
||||
}
|
||||
// We know that they are in conflict since they are of different types.
|
||||
return AVMDifference.CONFLICT;
|
||||
}
|
||||
// Destination is a layered file also.
|
||||
AVMNodeDescriptor common = fAVMService.getCommonAncestor(srcDesc, dstDesc);
|
||||
if (common == null)
|
||||
{
|
||||
return AVMDifference.CONFLICT;
|
||||
}
|
||||
if (common.getId() == srcDesc.getId())
|
||||
{
|
||||
return AVMDifference.OLDER;
|
||||
}
|
||||
if (common.getId() == dstDesc.getId())
|
||||
{
|
||||
return AVMDifference.NEWER;
|
||||
}
|
||||
// Finally we know they are in conflict.
|
||||
return AVMDifference.CONFLICT;
|
||||
}
|
||||
// Source is a plain file.
|
||||
if (dstDesc.isLayeredFile())
|
||||
{
|
||||
if (dstDesc.getIndirection().equals(srcDesc.getPath()))
|
||||
{
|
||||
return AVMDifference.SAME;
|
||||
}
|
||||
// Otherwise we know they are in conflict because they are of different type.
|
||||
return AVMDifference.CONFLICT;
|
||||
}
|
||||
// Destination is a plain file.
|
||||
AVMNodeDescriptor common = fAVMService.getCommonAncestor(srcDesc, dstDesc);
|
||||
// Conflict case.
|
||||
if (common == null)
|
||||
{
|
||||
return AVMDifference.CONFLICT;
|
||||
}
|
||||
if (common.getId() == srcDesc.getId())
|
||||
{
|
||||
return AVMDifference.OLDER;
|
||||
}
|
||||
if (common.getId() == dstDesc.getId())
|
||||
{
|
||||
return AVMDifference.NEWER;
|
||||
}
|
||||
// The must, finally, be in conflict.
|
||||
return AVMDifference.CONFLICT;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,48 +314,48 @@ public class AVMSyncServiceImpl implements AVMSyncService
|
||||
*/
|
||||
private void flatten(AVMNodeDescriptor layer, AVMNodeDescriptor underlying)
|
||||
{
|
||||
// First case: a layered directory.
|
||||
if (layer.isLayeredDirectory())
|
||||
if (!layer.isLayeredDirectory())
|
||||
{
|
||||
// layer and underlying must match.
|
||||
if (!layer.getIndirection().equals(underlying.getPath()))
|
||||
return;
|
||||
}
|
||||
// layer and underlying must match for flattening to be useful.
|
||||
if (!layer.getIndirection().equals(underlying.getPath()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// The underlying thing must be a directory.
|
||||
if (!underlying.isDirectory())
|
||||
{
|
||||
throw new AVMWrongTypeException("Underlying is not a directory: " + underlying);
|
||||
}
|
||||
Map<String, AVMNodeDescriptor> layerListing =
|
||||
fAVMService.getDirectoryListingDirect(-1, layer.getPath(), true);
|
||||
// If the layer is empty (directly, that is) we're done.
|
||||
if (layerListing.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Grab the listing
|
||||
Map<String, AVMNodeDescriptor> underListing =
|
||||
fAVMService.getDirectoryListing(-1, underlying.getPath(), true);
|
||||
for (String name : layerListing.keySet())
|
||||
{
|
||||
AVMNodeDescriptor topNode = layerListing.get(name);
|
||||
AVMNodeDescriptor bottomNode = underListing.get(name);
|
||||
if (bottomNode == null)
|
||||
{
|
||||
throw new AVMException("Layer and Underlying do not match.");
|
||||
continue;
|
||||
}
|
||||
// The underlying thing must be a directory.
|
||||
if (!underlying.isDirectory())
|
||||
// We've found an identity so flatten it.
|
||||
if (topNode.getId() == bottomNode.getId())
|
||||
{
|
||||
throw new AVMWrongTypeException("Underlying is not a directory: " + underlying);
|
||||
fAVMService.removeNode(layer.getPath(), name);
|
||||
fAVMService.uncover(layer.getPath(), name);
|
||||
}
|
||||
Map<String, AVMNodeDescriptor> layerListing =
|
||||
fAVMService.getDirectoryListingDirect(-1, layer.getPath(), true);
|
||||
// If the layer is empty (directly, that is) we're done.
|
||||
if (layerListing.size() == 0)
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Grab the listing
|
||||
Map<String, AVMNodeDescriptor> underListing =
|
||||
fAVMService.getDirectoryListing(-1, underlying.getPath(), true);
|
||||
for (String name : layerListing.keySet())
|
||||
{
|
||||
AVMNodeDescriptor topNode = layerListing.get(name);
|
||||
AVMNodeDescriptor bottomNode = underListing.get(name);
|
||||
if (bottomNode == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// We've found an identity so flatten it.
|
||||
if (topNode.getId() == bottomNode.getId())
|
||||
{
|
||||
fAVMService.removeNode(layer.getPath(), name);
|
||||
fAVMService.uncover(layer.getPath(), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise recursively flatten the children.
|
||||
flatten(topNode, bottomNode);
|
||||
}
|
||||
// Otherwise recursively flatten the children.
|
||||
flatten(topNode, bottomNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user