This checkin does two things:

1. Refines the semantics of ghost creation, so that they only appear when
warranted.
2. Implements a mechanism for filtering out files which should not appear in comparison
results or be pushed along by updates.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4525 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-12-05 22:26:02 +00:00
parent b89caeb3e5
commit 8b65510d6f
20 changed files with 304 additions and 129 deletions

View File

@@ -471,7 +471,8 @@ public class AVMInterpreter
List<AVMDifference> diffs = fSyncService.compare(Integer.parseInt(command[2]),
command[1],
Integer.parseInt(command[4]),
command[3]);
command[3],
null);
for (AVMDifference diff : diffs)
{
out.println(diff);
@@ -487,7 +488,7 @@ public class AVMInterpreter
-1, command[3], AVMDifference.NEWER);
List<AVMDifference> diffs = new ArrayList<AVMDifference>();
diffs.add(diff);
fSyncService.update(diffs, false, false, false, false, null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
}
else if (command[0].equals("resetLayer"))
{

View File

@@ -38,7 +38,6 @@ import org.alfresco.repo.avm.actions.AVMUndoSandboxListAction;
import org.alfresco.repo.avm.actions.SimpleAVMPromoteAction;
import org.alfresco.repo.avm.actions.SimpleAVMSubmitAction;
import org.alfresco.repo.avm.util.BulkLoader;
import org.alfresco.repo.avm.util.VersionPathStuffer;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.TransactionUtil;
@@ -61,6 +60,7 @@ import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.GUID;
import org.alfresco.util.NameMatcher;
import org.alfresco.util.Pair;
/**
@@ -209,13 +209,13 @@ public class AVMServiceTest extends AVMServiceTestBase
diffs.add(new AVMDifference(-1, "layer:/a/b/c/foo",
-1, "main:/a/b/c/foo",
AVMDifference.NEWER));
fSyncService.update(diffs, false, false, false, false, null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
fSyncService.flatten("layer:/a", "main:/a");
AVMNodeDescriptor b = fService.lookup(-1, "layer:/a/b");
assertTrue(b.isLayeredDirectory());
AVMNodeDescriptor c = fService.lookup(-1, "layer:/a/b/c");
assertTrue(c.isPlainDirectory());
assertEquals(1, fSyncService.compare(-1, "layer:/a", -1, "main:/a").size());
assertEquals(1, fSyncService.compare(-1, "layer:/a", -1, "main:/a", null).size());
}
catch (Exception e)
{
@@ -260,11 +260,11 @@ public class AVMServiceTest extends AVMServiceTestBase
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");
List<AVMDifference> diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a", null);
assertEquals(1, diffs.size());
fSyncService.update(diffs, false, false, false, false, null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
fService.getFileOutputStream("area:/a/b/c/bar").close();
diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a");
diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a", null);
assertEquals(1, diffs.size());
final ActionImpl action = new ActionImpl(null,
GUID.generate(),
@@ -289,7 +289,7 @@ public class AVMServiceTest extends AVMServiceTestBase
};
TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"),
new TxnWork());
diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a");
diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a", null);
assertEquals(0, diffs.size());
System.out.println(recursiveList("area", -1, true));
System.out.println(recursiveList("main", -1, true));
@@ -312,11 +312,11 @@ public class AVMServiceTest extends AVMServiceTestBase
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");
List<AVMDifference> diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a", null);
assertEquals(1, diffs.size());
fSyncService.update(diffs, false, false, false, false, null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
fService.getFileOutputStream("area:/a/b/c/bar").close();
diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a");
diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a", null);
assertEquals(1, diffs.size());
final ActionImpl action = new ActionImpl(null,
GUID.generate(),
@@ -336,7 +336,7 @@ public class AVMServiceTest extends AVMServiceTestBase
};
TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"),
new TxnWork());
diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a");
diffs = fSyncService.compare(-1, "area:/a", -1, "main:/a", null);
assertEquals(0, diffs.size());
System.out.println(recursiveList("area", -1, true));
System.out.println(recursiveList("main", -1, true));
@@ -378,7 +378,7 @@ public class AVMServiceTest extends AVMServiceTestBase
};
TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"),
new TxnWork());
assertEquals(0, fSyncService.compare(-1, "source:/appBase", -1, "main:/appBase").size());
assertEquals(0, fSyncService.compare(-1, "source:/appBase", -1, "main:/appBase", null).size());
}
catch (Exception e)
{
@@ -396,15 +396,15 @@ public class AVMServiceTest extends AVMServiceTestBase
{
setupBasicTree();
fService.createAVMStore("staging");
List<AVMDifference> diffs = fSyncService.compare(-1, "main:/", -1, "staging:/");
List<AVMDifference> diffs = fSyncService.compare(-1, "main:/", -1, "staging:/", null);
assertEquals(2, diffs.size());
List<AVMDifference> noodle = new ArrayList<AVMDifference>();
noodle.add(new AVMDifference(-1, "main:/a/b/c/foo", -1, "staging:/a/b/c/foo",
AVMDifference.NEWER));
noodle.add(new AVMDifference(-1, "main:/d", -1, "staging:/d",
AVMDifference.NEWER));
fSyncService.update(noodle, false, false, false, false, null, null);
diffs = fSyncService.compare(-1, "main:/", -1, "staging:/");
fSyncService.update(noodle, null, false, false, false, false, null, null);
diffs = fSyncService.compare(-1, "main:/", -1, "staging:/", null);
assertEquals(1, diffs.size());
assertEquals("main:/a/b/c/bar", diffs.get(0).getSourcePath());
}
@@ -437,7 +437,7 @@ public class AVMServiceTest extends AVMServiceTestBase
fService.getFileOutputStream("area:/appBase/a/b/c/foo").close();
fService.removeNode("area:/appBase/a/b/c/bar");
List<AVMDifference> diffs =
fSyncService.compare(-1, "area:/appBase", -1, "foo-staging:/appBase");
fSyncService.compare(-1, "area:/appBase", -1, "foo-staging:/appBase", null);
assertEquals(3, diffs.size());
final SimpleAVMSubmitAction action = (SimpleAVMSubmitAction)fContext.getBean("simple-avm-submit");
class TxnWork implements TransactionUtil.TransactionWork<Object>
@@ -452,7 +452,7 @@ public class AVMServiceTest extends AVMServiceTestBase
TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"),
worker);
diffs =
fSyncService.compare(-1, "area:/appBase", -1, "foo-staging:/appBase");
fSyncService.compare(-1, "area:/appBase", -1, "foo-staging:/appBase", null);
assertEquals(0, diffs.size());
}
catch (Exception e)
@@ -504,17 +504,17 @@ public class AVMServiceTest extends AVMServiceTestBase
loader.recursiveLoad("config/alfresco/extension", "source:/");
int version2 = fService.createSnapshot("source", null, null);
List<AVMDifference> diffs =
fSyncService.compare(version1, "source:/", -1, "dest:/");
fSyncService.compare(version1, "source:/", -1, "dest:/", null);
fService.createSnapshot("dest", null, null);
assertEquals(1, diffs.size());
fSyncService.update(diffs, false, false, false, false, null, null);
diffs = fSyncService.compare(version1, "source:/", -1, "dest:/");
fSyncService.update(diffs, null, false, false, false, false, null, null);
diffs = fSyncService.compare(version1, "source:/", -1, "dest:/", null);
assertEquals(0, diffs.size());
diffs = fSyncService.compare(version2, "source:/", -1, "dest:/");
diffs = fSyncService.compare(version2, "source:/", -1, "dest:/", null);
assertEquals(1, diffs.size());
fSyncService.update(diffs, false, false, false, false, null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
fService.createSnapshot("dest", null, null);
diffs = fSyncService.compare(version2, "source:/", -1, "dest:/");
diffs = fSyncService.compare(version2, "source:/", -1, "dest:/", null);
assertEquals(0, diffs.size());
}
catch (Exception e)
@@ -539,11 +539,11 @@ public class AVMServiceTest extends AVMServiceTestBase
fService.getFileOutputStream("branch:/branch/a/b/c/foo").close();
fService.removeNode("branch:/branch/a/b/c", "bar");
List<AVMDifference> diffs =
fSyncService.compare(-1, "branch:/branch", -1, "main:/");
fSyncService.compare(-1, "branch:/branch", -1, "main:/", null);
assertEquals(3, diffs.size());
// Now update.
fSyncService.update(diffs, false, false, false, false, null, null);
diffs = fSyncService.compare(-1, "branch:/branch", -1, "main:/");
fSyncService.update(diffs, null, false, false, false, false, null, null);
diffs = fSyncService.compare(-1, "branch:/branch", -1, "main:/", null);
assertEquals(0, diffs.size());
fService.getFileOutputStream("branch:/branch/a/b/fing").close();
assertTrue(fService.lookup(-1, "branch:/branch/a/b/fing").getId() !=
@@ -591,12 +591,12 @@ public class AVMServiceTest extends AVMServiceTestBase
fService.createAVMStore("layer");
fService.createLayeredDirectory("main:/", "layer:/", "layer");
loader.recursiveLoad("config/alfresco/bootstrap", "layer:/layer");
List<AVMDifference> diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/");
List<AVMDifference> diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals(1, diffs.size());
fService.createSnapshot("layer", null, null);
fSyncService.update(diffs, false, false, false, false, null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
fService.createSnapshot("main", null, null);
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/");
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals(0, diffs.size());
fSyncService.flatten("layer:/layer", "main:/");
System.out.println("Layer:");
@@ -607,13 +607,13 @@ public class AVMServiceTest extends AVMServiceTestBase
fService.createLayeredDirectory("layer:/layer", "layer2:/", "layer");
loader.recursiveLoad("config/alfresco/bootstrap", "layer2:/layer/bootstrap");
fService.createSnapshot("layer2", null, null);
diffs = fSyncService.compare(-1, "layer2:/layer", -1, "layer:/layer");
diffs = fSyncService.compare(-1, "layer2:/layer", -1, "layer:/layer", null);
assertEquals(1, diffs.size());
fSyncService.update(diffs, false, false, false, false, null, null);
diffs = fSyncService.compare(-1, "layer2:/layer", -1, "layer:/layer");
fSyncService.update(diffs, null, false, false, false, false, null, null);
diffs = fSyncService.compare(-1, "layer2:/layer", -1, "layer:/layer", null);
assertEquals(0, diffs.size());
fSyncService.flatten("layer2:/layer", "layer:/layer");
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/");
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals(1, diffs.size());
System.out.println("Layer2:");
System.out.println(recursiveList("layer2", -1, true));
@@ -647,13 +647,13 @@ public class AVMServiceTest extends AVMServiceTestBase
System.out.println(recursiveList("main", -1, true));
// Do a compare.
List<AVMDifference> diffs =
fSyncService.compare(-1, "main:/layer", -1, "main:/a");
fSyncService.compare(-1, "main:/layer", -1, "main:/a", null);
for (AVMDifference diff : diffs)
{
System.out.println(diff);
}
// Update.
fSyncService.update(diffs, false, false, false, false, null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
System.out.println(recursiveList("main", -1, true));
// Flatten.
fSyncService.flatten("main:/layer", "main:/a");
@@ -701,14 +701,17 @@ public class AVMServiceTest extends AVMServiceTestBase
{
try
{
NameMatcher excluder = (NameMatcher)fContext.getBean("globalPathExcluder");
setupBasicTree();
// Try branch to branch update.
fService.createBranch(-1, "main:/a", "main:/", "abranch");
fService.createFile("main:/abranch", "monkey").close();
fService.createFile("main:/abranch", "#foo").close();
fService.createFile("main:/abranch", "figs.tmp").close();
fService.getFileOutputStream("main:/abranch/b/c/foo").close();
System.out.println(recursiveList("main", -1, true));
List<AVMDifference> cmp =
fSyncService.compare(-1, "main:/abranch", -1, "main:/a");
fSyncService.compare(-1, "main:/abranch", -1, "main:/a", excluder);
for (AVMDifference diff : cmp)
{
System.out.println(diff);
@@ -721,7 +724,7 @@ public class AVMServiceTest extends AVMServiceTestBase
diffs.add(new AVMDifference(-1, "main:/abranch/b/c/foo",
-1, "main:/a/b/c/foo",
AVMDifference.NEWER));
fSyncService.update(diffs, false, false, false, false, null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
fService.createSnapshot("main", null, null);
System.out.println(recursiveList("main", -1, true));
assertEquals(fService.lookup(-1, "main:/abranch/monkey").getId(),
@@ -732,7 +735,7 @@ public class AVMServiceTest extends AVMServiceTestBase
fService.removeNode("main:/abranch", "monkey");
System.out.println(recursiveList("main", -1, true));
cmp =
fSyncService.compare(-1, "main:/abranch", -1, "main:/a");
fSyncService.compare(-1, "main:/abranch", -1, "main:/a", excluder);
for (AVMDifference diff : cmp)
{
System.out.println(diff);
@@ -742,8 +745,8 @@ public class AVMServiceTest extends AVMServiceTestBase
diffs.add(new AVMDifference(-1, "main:/abranch/monkey",
-1, "main:/a/monkey",
AVMDifference.NEWER));
fSyncService.update(diffs, false, false, false, false, null, null);
assertEquals(0, fSyncService.compare(-1, "main:/abranch", -1, "main:/a").size());
fSyncService.update(diffs, null, false, false, false, false, null, null);
assertEquals(0, fSyncService.compare(-1, "main:/abranch", -1, "main:/a", excluder).size());
fService.createSnapshot("main", null, null);
System.out.println(recursiveList("main", -1, true));
assertEquals(fService.lookup(-1, "main:/abranch/monkey", true).getId(),
@@ -751,7 +754,7 @@ public class AVMServiceTest extends AVMServiceTestBase
// Try one that should fail.
fService.createFile("main:/abranch", "monkey").close();
cmp =
fSyncService.compare(-1, "main:/abranch", -1, "main:/a");
fSyncService.compare(-1, "main:/abranch", -1, "main:/a", excluder);
for (AVMDifference diff : cmp)
{
System.out.println(diff);
@@ -763,7 +766,7 @@ public class AVMServiceTest extends AVMServiceTestBase
AVMDifference.NEWER));
try
{
fSyncService.update(diffs, false, false, false, false, null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
fail();
}
catch (AVMSyncException se)
@@ -776,8 +779,8 @@ public class AVMServiceTest extends AVMServiceTestBase
diffs.add(new AVMDifference(-1, "main:/a/monkey",
-1, "main:/abranch/monkey",
AVMDifference.NEWER));
fSyncService.update(diffs, false, false, true, false, null, null);
assertEquals(0, fSyncService.compare(-1, "main:/abranch", -1, "main:/a").size());
fSyncService.update(diffs, null, false, false, true, false, null, null);
assertEquals(0, fSyncService.compare(-1, "main:/abranch", -1, "main:/a", excluder).size());
fService.createSnapshot("main", null, null);
System.out.println(recursiveList("main", -1, true));
assertEquals(fService.lookup(-1, "main:/a/monkey", true).getId(),
@@ -790,7 +793,7 @@ public class AVMServiceTest extends AVMServiceTestBase
fService.createFile("main:/layer", "monkey").close();
fService.getFileOutputStream("main:/layer/b/c/foo").close();
cmp =
fSyncService.compare(-1, "main:/layer", -1, "main:/a");
fSyncService.compare(-1, "main:/layer", -1, "main:/a", excluder);
for (AVMDifference diff : cmp)
{
System.out.println(diff);
@@ -804,8 +807,8 @@ public class AVMServiceTest extends AVMServiceTestBase
diffs.add(new AVMDifference(-1, "main:/layer/b/c/foo",
-1, "main:/a/b/c/foo",
AVMDifference.NEWER));
fSyncService.update(diffs, false, false, false, false, null, null);
assertEquals(0, fSyncService.compare(-1, "main:/layer", -1, "main:/a").size());
fSyncService.update(diffs, null, false, false, false, false, null, null);
assertEquals(0, fSyncService.compare(-1, "main:/layer", -1, "main:/a", excluder).size());
fService.createSnapshot("main", null, null);
System.out.println(recursiveList("main", -1, true));
assertEquals(fService.lookup(-1, "main:/layer/monkey").getId(),
@@ -816,7 +819,7 @@ public class AVMServiceTest extends AVMServiceTestBase
fService.removeNode("main:/layer", "monkey");
System.out.println(recursiveList("main", -1, true));
cmp =
fSyncService.compare(-1, "main:/layer", -1, "main:/a");
fSyncService.compare(-1, "main:/layer", -1, "main:/a", excluder);
for (AVMDifference diff : cmp)
{
System.out.println(diff);
@@ -826,8 +829,8 @@ public class AVMServiceTest extends AVMServiceTestBase
diffs.add(new AVMDifference(-1, "main:/layer/monkey",
-1, "main:/a/monkey",
AVMDifference.NEWER));
fSyncService.update(diffs, false, false, false, false, null, null);
assertEquals(0, fSyncService.compare(-1, "main:/layer", -1, "main:/a").size());
fSyncService.update(diffs, null, false, false, false, false, null, null);
assertEquals(0, fSyncService.compare(-1, "main:/layer", -1, "main:/a", excluder).size());
fService.createSnapshot("main", null, null);
System.out.println(recursiveList("main", -1, true));
assertEquals(fService.lookup(-1, "main:/layer/monkey", true).getId(),
@@ -835,7 +838,7 @@ public class AVMServiceTest extends AVMServiceTestBase
// Try one that should fail.
fService.createFile("main:/layer", "monkey").close();
cmp =
fSyncService.compare(-1, "main:/layer", -1, "main:/a");
fSyncService.compare(-1, "main:/layer", -1, "main:/a", excluder);
for (AVMDifference diff : cmp)
{
System.out.println(diff);
@@ -847,7 +850,7 @@ public class AVMServiceTest extends AVMServiceTestBase
AVMDifference.NEWER));
try
{
fSyncService.update(diffs, false, false, false, false, null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
fail();
}
catch (AVMSyncException se)
@@ -860,8 +863,8 @@ public class AVMServiceTest extends AVMServiceTestBase
diffs.add(new AVMDifference(-1, "main:/a/monkey",
-1, "main:/layer/monkey",
AVMDifference.NEWER));
fSyncService.update(diffs, false, false, true, false, null, null);
assertEquals(0, fSyncService.compare(-1, "main:/layer", -1, "main:/a").size());
fSyncService.update(diffs, null, false, false, true, false, null, null);
assertEquals(0, fSyncService.compare(-1, "main:/layer", -1, "main:/a", excluder).size());
fService.createSnapshot("main", null, null);
System.out.println(recursiveList("main", -1, true));
assertEquals(fService.lookup(-1, "main:/a/monkey", true).getId(),

View File

@@ -24,16 +24,14 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
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;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.NameMatcher;
import org.apache.log4j.Logger;
/**
@@ -83,11 +81,13 @@ public class AVMSyncServiceImpl implements AVMSyncService
* @param srcPath The avm path to the source tree.
* @param dstVersion The version id for the destination tree.
* @param dstPath The avm path to the destination tree.
* @param excluder A NameMatcher used to exclude files from consideration.
* @return A List of AVMDifference structs which can be used for
* the update operation.
*/
public List<AVMDifference> compare(int srcVersion, String srcPath,
int dstVersion, String dstPath)
int dstVersion, String dstPath,
NameMatcher excluder)
{
if (srcPath == null || dstPath == null)
{
@@ -110,7 +110,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
else
{
// Invoke the recursive implementation.
compare(srcVersion, srcDesc, dstVersion, dstDesc, result);
compare(srcVersion, srcDesc, dstVersion, dstDesc, result, excluder);
}
return result;
}
@@ -124,9 +124,14 @@ public class AVMSyncServiceImpl implements AVMSyncService
*/
private void compare(int srcVersion, AVMNodeDescriptor srcDesc,
int dstVersion, AVMNodeDescriptor dstDesc,
List<AVMDifference> result)
List<AVMDifference> result, NameMatcher excluder)
{
// Determine how the source and destination nodes differ.
if (excluder != null && (excluder.matches(srcDesc.getPath()) ||
excluder.matches(dstDesc.getPath())))
{
return;
}
int diffCode = compareOne(srcDesc, dstDesc);
switch (diffCode)
{
@@ -168,19 +173,25 @@ public class AVMSyncServiceImpl implements AVMSyncService
{
AVMNodeDescriptor srcChild = srcList.get(name);
AVMNodeDescriptor dstChild = dstList.get(name);
String dstPath = AVMNodeConverter.ExtendAVMPath(dstDesc.getPath(), name);
if (excluder != null && (excluder.matches(srcChild.getPath()) ||
excluder.matches(dstPath)))
{
continue;
}
if (dstChild == null)
{
// A missing destination child means the source is NEWER.
result.add(new AVMDifference(srcVersion, srcChild.getPath(),
dstVersion,
AVMNodeConverter.ExtendAVMPath(dstDesc.getPath(), name),
AVMDifference.NEWER));
dstVersion,
dstPath,
AVMDifference.NEWER));
continue;
}
// Otherwise recursively invoke.
compare(srcVersion, srcChild,
dstVersion, dstChild,
result);
result, excluder);
}
return;
}
@@ -203,11 +214,17 @@ public class AVMSyncServiceImpl implements AVMSyncService
{
AVMNodeDescriptor dstChild = dstList.get(name);
AVMNodeDescriptor srcChild = srcList.get(name);
String srcPath = AVMNodeConverter.ExtendAVMPath(srcDesc.getPath(), name);
if (excluder != null && (excluder.matches(srcPath) ||
excluder.matches(dstChild.getPath())))
{
continue;
}
if (srcChild == null)
{
// Missing means the source is older.
result.add(new AVMDifference(srcVersion,
AVMNodeConverter.ExtendAVMPath(srcDesc.getPath(), name),
srcPath,
dstVersion, dstChild.getPath(),
AVMDifference.OLDER));
continue;
@@ -215,7 +232,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
// Otherwise, recursively invoke.
compare(srcVersion, srcChild,
dstVersion, dstChild,
result);
result, excluder);
}
return;
}
@@ -229,19 +246,25 @@ public class AVMSyncServiceImpl implements AVMSyncService
{
AVMNodeDescriptor srcChild = srcList.get(name);
AVMNodeDescriptor dstChild = dstList.get(name);
String dstPath = AVMNodeConverter.ExtendAVMPath(dstDesc.getPath(), name);
if (excluder != null && (excluder.matches(srcChild.getPath()) ||
excluder.matches(dstPath)))
{
continue;
}
if (dstChild == null)
{
// Not found in the destination means NEWER.
result.add(new AVMDifference(srcVersion, srcChild.getPath(),
dstVersion,
AVMNodeConverter.ExtendAVMPath(dstDesc.getPath(), name),
dstPath,
AVMDifference.NEWER));
continue;
}
// Otherwise recursive invocation.
compare(srcVersion, srcChild,
dstVersion, dstChild,
result);
result, excluder);
}
// Iterate over the destination.
for (String name : dstList.keySet())
@@ -251,9 +274,15 @@ public class AVMSyncServiceImpl implements AVMSyncService
continue;
}
AVMNodeDescriptor dstChild = dstList.get(name);
String srcPath = AVMNodeConverter.ExtendAVMPath(srcDesc.getPath(), name);
if (excluder != null && (excluder.matches(srcPath) ||
excluder.matches(dstChild.getPath())))
{
continue;
}
// An entry not found in the source is OLDER.
result.add(new AVMDifference(srcVersion,
AVMNodeConverter.ExtendAVMPath(srcDesc.getPath(), name),
srcPath,
dstVersion, dstChild.getPath(),
AVMDifference.OLDER));
}
@@ -272,6 +301,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
* which the source of an AVMDifference is older than the destination
* will cause the transaction to roll back.
* @param diffList A List of AVMDifference structs.
* @param excluder A possibly null name matcher to exclude unwanted updates.
* @param ignoreConflicts If this is true the update will skip those
* AVMDifferences which are in conflict with
* the destination.
@@ -284,13 +314,19 @@ public class AVMSyncServiceImpl implements AVMSyncService
* @param description Full update blurb.
* in which the source is older than the destination and overwrite the destination.
*/
public void update(List<AVMDifference> diffList, boolean ignoreConflicts, boolean ignoreOlder,
public void update(List<AVMDifference> diffList,
NameMatcher excluder, boolean ignoreConflicts, boolean ignoreOlder,
boolean overrideConflicts, boolean overrideOlder, String tag, String description)
{
Map<String, Integer> storeVersions = new HashMap<String, Integer>();
Set<String> destStores = new HashSet<String>();
for (AVMDifference diff : diffList)
{
if (excluder != null && (excluder.matches(diff.getSourcePath()) ||
excluder.matches(diff.getDestinationPath())))
{
continue;
}
if (!diff.isValid())
{
throw new AVMSyncException("Malformed AVMDifference.");
@@ -317,10 +353,6 @@ public class AVMSyncServiceImpl implements AVMSyncService
}
AVMNodeDescriptor srcDesc = fAVMService.lookup(version,
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)
{
@@ -350,7 +382,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
case AVMDifference.NEWER :
{
// You can't delete what isn't there.
linkIn(dstParts[0], dstParts[1], srcDesc, dstDesc != null);
linkIn(dstParts[0], dstParts[1], srcDesc, excluder, dstDesc != null);
continue;
}
case AVMDifference.OLDER :
@@ -358,7 +390,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
// You can force it.
if (overrideOlder)
{
linkIn(dstParts[0], dstParts[1], srcDesc, !dstDesc.isDeleted());
linkIn(dstParts[0], dstParts[1], srcDesc, excluder, !dstDesc.isDeleted());
continue;
}
// You can ignore it.
@@ -374,7 +406,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
// You can force it.
if (overrideConflicts)
{
linkIn(dstParts[0], dstParts[1], srcDesc, true);
linkIn(dstParts[0], dstParts[1], srcDesc, excluder, true);
continue;
}
// You can ignore it.
@@ -414,7 +446,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
* @param toLink The node descriptor.
* @param removeFirst Whether to do a removeNode before linking in.
*/
private void linkIn(String parentPath, String name, AVMNodeDescriptor toLink, boolean removeFirst)
private void linkIn(String parentPath, String name, AVMNodeDescriptor toLink, NameMatcher excluder, boolean removeFirst)
{
// This is a delete.
if (toLink == null)
@@ -429,7 +461,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
}
if (toLink.isLayeredDirectory() && !toLink.isPrimary())
{
recursiveCopy(parentPath, name, toLink);
recursiveCopy(parentPath, name, toLink, excluder);
return;
}
fAVMService.link(parentPath, name, toLink);
@@ -441,7 +473,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
* @param name The name to give it.
* @param toCopy The it to put.
*/
private void recursiveCopy(String parentPath, String name, AVMNodeDescriptor toCopy)
private void recursiveCopy(String parentPath, String name, AVMNodeDescriptor toCopy, NameMatcher excluder)
{
fAVMService.createDirectory(parentPath, name);
String newParentPath = AVMNodeConverter.ExtendAVMPath(parentPath, name);
@@ -451,7 +483,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
fAVMService.getDirectoryListing(toCopy, true);
for (Map.Entry<String, AVMNodeDescriptor> entry : children.entrySet())
{
recursiveCopy(parentDesc, entry.getKey(), entry.getValue());
recursiveCopy(parentDesc, entry.getKey(), entry.getValue(), excluder);
}
}
@@ -461,8 +493,14 @@ public class AVMSyncServiceImpl implements AVMSyncService
* @param name The name to link in.
* @param toCopy The node to link in.
*/
private void recursiveCopy(AVMNodeDescriptor parent, String name, AVMNodeDescriptor toCopy)
private void recursiveCopy(AVMNodeDescriptor parent, String name, AVMNodeDescriptor toCopy, NameMatcher excluder)
{
String newPath = AVMNodeConverter.ExtendAVMPath(parent.getPath(), name);
if (excluder != null && (excluder.matches(newPath) ||
excluder.matches(toCopy.getPath())))
{
return;
}
// If it's a file or deleted simply link it in.
if (toCopy.isFile() || toCopy.isDeleted() || toCopy.isPlainDirectory())
{
@@ -477,7 +515,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
fAVMService.getDirectoryListing(toCopy, true);
for (Map.Entry<String, AVMNodeDescriptor> entry : children.entrySet())
{
recursiveCopy(newParentDesc, entry.getKey(), entry.getValue());
recursiveCopy(newParentDesc, entry.getKey(), entry.getValue(), excluder);
}
}

View File

@@ -9,6 +9,7 @@ import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.remote.AVMSyncServiceTransport;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.util.NameMatcher;
/**
* Server side implementation of the remote wrapper of AVMSyncService.
@@ -47,10 +48,10 @@ public class AVMSyncServiceTransportImpl implements AVMSyncServiceTransport
* @see org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport#compare(java.lang.String, int, java.lang.String, int, java.lang.String)
*/
public List<AVMDifference> compare(String ticket, int srcVersion,
String srcPath, int dstVersion, String dstPath)
String srcPath, int dstVersion, String dstPath, NameMatcher excluder)
{
fAuthenticationService.validate(ticket);
return fSyncService.compare(srcVersion, srcPath, dstVersion, dstPath);
return fSyncService.compare(srcVersion, srcPath, dstVersion, dstPath, excluder);
}
/* (non-Javadoc)
@@ -74,12 +75,12 @@ public class AVMSyncServiceTransportImpl implements AVMSyncServiceTransport
/* (non-Javadoc)
* @see org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport#update(java.lang.String, java.util.List, boolean, boolean, boolean, boolean, java.lang.String, java.lang.String)
*/
public void update(String ticket, List<AVMDifference> diffList,
public void update(String ticket, List<AVMDifference> diffList, NameMatcher excluder,
boolean ignoreConflicts, boolean ignoreOlder,
boolean overrideConflicts, boolean overrideOlder, String tag,
String description)
{
fAuthenticationService.validate(ticket);
fSyncService.update(diffList, ignoreConflicts, ignoreOlder, overrideConflicts, overrideOlder, tag, description);
fSyncService.update(diffList, excluder, ignoreConflicts, ignoreOlder, overrideConflicts, overrideOlder, tag, description);
}
}

View File

@@ -199,14 +199,14 @@ public class AVMTestRemote extends TestCase
fAVMRemote.createAVMStore("broo");
// Create a branch.
fAVMRemote.createBranch(-1, "froo:/a", "broo:/", "a");
List<AVMDifference> diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a");
List<AVMDifference> diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a", null);
assertEquals(0, diffs.size());
fAVMRemote.createFile("froo:/a", "bar").close();
diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a");
diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a", null);
assertEquals(1, diffs.size());
// Update.
fAVMSync.update(diffs, false, false, false, false, "flippy", "Stuff");
diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a");
fAVMSync.update(diffs, null, false, false, false, false, "flippy", "Stuff");
diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a", null);
assertEquals(0, diffs.size());
}
catch (Exception e)

View File

@@ -555,6 +555,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
ChildKey key = new ChildKey(this, name);
ChildEntry entry = AVMDAOs.Instance().fChildEntryDAO.get(key);
AVMNode child = null;
boolean indirect = false;
if (entry != null)
{
child = entry.getChild();
@@ -567,13 +568,21 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec
else
{
child = lookupChild(lPath, name, false);
indirect = true;
}
if (child != null && (indirect || child.getStoreNew() == null || child.getAncestor() != null))
{
AVMNode ghost = new DeletedNodeImpl(lPath.getAVMStore().getAVMRepository().issueID(),
lPath.getAVMStore());
AVMDAOs.Instance().fAVMNodeDAO.save(ghost);
AVMDAOs.Instance().fAVMNodeDAO.flush();
ghost.setAncestor(child);
this.putChild(name, ghost);
}
else
{
AVMDAOs.Instance().fAVMNodeDAO.flush();
}
AVMNode ghost = new DeletedNodeImpl(lPath.getAVMStore().getAVMRepository().issueID(),
lPath.getAVMStore());
AVMDAOs.Instance().fAVMNodeDAO.save(ghost);
AVMDAOs.Instance().fAVMNodeDAO.flush();
ghost.setAncestor(child);
this.putChild(name, ghost);
}
/**

View File

@@ -229,13 +229,20 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory
{
return;
}
AVMNode ghost = new DeletedNodeImpl(lPath.getAVMStore().getAVMRepository().issueID(),
lPath.getAVMStore());
AVMDAOs.Instance().fChildEntryDAO.delete(entry);
AVMDAOs.Instance().fAVMNodeDAO.save(ghost);
AVMDAOs.Instance().fAVMNodeDAO.flush();
ghost.setAncestor(child);
putChild(name, ghost);
if (child.getStoreNew() == null || child.getAncestor() != null)
{
AVMNode ghost = new DeletedNodeImpl(lPath.getAVMStore().getAVMRepository().issueID(),
lPath.getAVMStore());
AVMDAOs.Instance().fAVMNodeDAO.save(ghost);
AVMDAOs.Instance().fAVMNodeDAO.flush();
ghost.setAncestor(child);
putChild(name, ghost);
}
else
{
AVMDAOs.Instance().fAVMNodeDAO.flush();
}
}
}

View File

@@ -68,11 +68,11 @@ public class AVMRevertListAction extends ActionExecuterAbstractBase
{
List<AVMDifference> diffSet =
fSyncService.compare(revertVersion, item.getSecond(),
-1, item.getSecond());
-1, item.getSecond(), null);
diffs.addAll(diffSet);
}
String message = "Reverted to version " + revertVersion;
fSyncService.update(diffs, false, false, true, true, message, message);
fSyncService.update(diffs, null, false, false, true, true, message, message);
if (!(Boolean)action.getParameterValue(PARAM_FLATTEN))
{
return;

View File

@@ -54,9 +54,9 @@ public class AVMRevertStoreAction extends ActionExecuterAbstractBase
int revertVersion = (Integer)action.getParameterValue(PARAM_VERSION);
List<AVMDifference> diffs =
fSyncService.compare(revertVersion, pathVersion.getSecond(),
-1, pathVersion.getSecond());
-1, pathVersion.getSecond(), null);
String message = "Reverted to Version " + revertVersion + ".";
fSyncService.update(diffs, false, false, true, true, message, message);
fSyncService.update(diffs, null, false, false, true, true, message, message);
}
/* (non-Javadoc)

View File

@@ -89,10 +89,10 @@ public class SimpleAVMPromoteAction extends ActionExecuterAbstractBase
String targetPath = targetStoreName + ":" + storePath[1];
// Find the differences.
List<AVMDifference> diffs =
fAVMSyncService.compare(version, path, -1, targetPath);
fAVMSyncService.compare(version, path, -1, targetPath, null);
// TODO fix update comments at some point.
// Do the promote.
fAVMSyncService.update(diffs, true, true, false, false, null, null);
fAVMSyncService.update(diffs, null, true, true, false, false, null, null);
// Flatten the source on top of the destination.
fAVMSyncService.flatten(storePath[0] + ":/appBase",
targetStoreName + ":/appBase");

View File

@@ -31,6 +31,7 @@ import org.alfresco.service.cmr.avmsync.AVMSyncException;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.NameMatcher;
import org.alfresco.util.Pair;
import org.apache.log4j.Logger;
@@ -55,6 +56,11 @@ public class SimpleAVMSubmitAction extends ActionExecuterAbstractBase
*/
private AVMSyncService fAVMSyncService;
/**
* The Excluding NameMatcher.
*/
private NameMatcher fExcluder;
/**
* Default constructor.
*/
@@ -81,6 +87,16 @@ public class SimpleAVMSubmitAction extends ActionExecuterAbstractBase
fAVMSyncService = avmSyncService;
}
// TODO This should be a parameter of the action execution really.
/**
* Set the excluder.
* @param excluder
*/
public void setExcluder(NameMatcher excluder)
{
fExcluder = excluder;
}
/**
* Perform the action. The NodeRef must be an AVM NodeRef.
* @param action Don't actually need anything from this here.
@@ -114,10 +130,10 @@ public class SimpleAVMSubmitAction extends ActionExecuterAbstractBase
String avmDest = websiteName + "-staging:" + storePath[1];
// Get the difference between source and destination.
List<AVMDifference> diffs =
fAVMSyncService.compare(version, path, -1, avmDest);
fAVMSyncService.compare(version, path, -1, avmDest, fExcluder);
// TODO fix update comments at some point.
// Do the update.
fAVMSyncService.update(diffs, false, false, true, true,
fAVMSyncService.update(diffs, fExcluder, false, false, true, true,
"Submit of item: " + AVMNodeConverter.SplitBase(path)[1], null);
// Cleanup by flattening the source relative to the destination.
AVMDAOs.Instance().fAVMNodeDAO.flush();

View File

@@ -0,0 +1,57 @@
/**
*
*/
package org.alfresco.repo.avm.util;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.util.NameMatcher;
/**
* NameMatcher that matches a list of extensions (case insensitively).
* @author britt
*/
public class FileExtensionNameMatcher implements NameMatcher
{
/**
* The extensions to match.
*/
private List<String> fExtensions;
/**
* Default constructor.
*/
public FileExtensionNameMatcher()
{
fExtensions = new ArrayList<String>();
}
/**
* Set the extensions case insensitively.
* @param extensions
*/
public void setExtensions(List<String> extensions)
{
for (String extension : extensions)
{
fExtensions.add(extension.toLowerCase());
}
}
/* (non-Javadoc)
* @see org.alfresco.util.NameMatcher#matches(java.lang.String)
*/
public boolean matches(String name)
{
String lcName = name.toLowerCase();
for (String ext : fExtensions)
{
if (lcName.endsWith(ext))
{
return true;
}
}
return false;
}
}

View File

@@ -78,10 +78,10 @@ public class AVMSubmitHandler extends JBPMSpringActionHandler
getStringValue();
String avmDest = webSiteName + "-staging:" + storePath[1];
List<AVMDifference> diffs =
fAVMSyncService.compare(-1, avmSource, -1, avmDest);
fAVMSyncService.compare(-1, avmSource, -1, avmDest, null);
// TODO fix update comments if needed.
// Ignore conflicts and older nodes for now.
fAVMSyncService.update(diffs, true, true, false, false, null, null);
fAVMSyncService.update(diffs, null, true, true, false, false, null, null);
// Now flatten out the source.
fAVMSyncService.flatten(avmSource, avmDest);
}

View File

@@ -59,8 +59,8 @@ public class AVMSubmitPackageHandler extends JBPMSpringActionHandler implements
AVMNodeDescriptor pkgDesc = fAVMService.lookup(pkgPath.getFirst(), pkgPath.getSecond());
String targetPath = pkgDesc.getIndirection();
List<AVMDifference> diff = fAVMSyncService.compare(pkgPath.getFirst(), pkgPath.getSecond(), -1, targetPath);
fAVMSyncService.update(diff, true, true, false, false, null, null);
List<AVMDifference> diff = fAVMSyncService.compare(pkgPath.getFirst(), pkgPath.getSecond(), -1, targetPath, null);
fAVMSyncService.update(diff, null, true, true, false, false, null, null);
String from = (String)executionContext.getContextInstance().getVariable("wf_from");
fAVMSyncService.flatten(from, targetPath);