Merged DEV/WCM-PERMISSIONS2 to HEAD

AVM folder diff (r9383-r9503)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9545 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-06-23 15:06:50 +00:00
parent 10240e71f4
commit e438c81d27
11 changed files with 1956 additions and 191 deletions

View File

@@ -100,6 +100,9 @@
<property name="permissionService"> <property name="permissionService">
<ref bean="permissionService"/> <ref bean="permissionService"/>
</property> </property>
<property name="avmSyncService">
<ref bean="avmSyncService"/>
</property>
</bean> </bean>
<!-- Bootstrap AVM Locking Service. --> <!-- Bootstrap AVM Locking Service. -->

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2008 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -43,85 +43,95 @@ public class AVMCrawlTestP extends AVMServiceTestBase
{ {
int n = 8; // Number of Threads. int n = 8; // Number of Threads.
int m = 2; // How many multiples of content to start with. int m = 2; // How many multiples of content to start with.
long runTime = 28800000; // 8 Hours. . try
fService.purgeStore("main");
BulkLoader loader = new BulkLoader();
loader.setAvmService(fService);
for (int i = 0; i < m; i++)
{ {
fService.createStore("d" + i); long runTime = 28800000; // 8 Hours. .
loader.recursiveLoad("source", "d" + i + ":/"); fService.purgeStore("main");
fService.createSnapshot("d" + i, null, null); BulkLoader loader = new BulkLoader();
} loader.setAvmService(fService);
long startTime = System.currentTimeMillis(); for (int i = 0; i < m; i++)
List<AVMCrawler> crawlers = new ArrayList<AVMCrawler>();
List<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < n; i++)
{
crawlers.add(new AVMCrawler(fService));
threads.add(new Thread(crawlers.get(i)));
threads.get(i).start();
}
while (true)
{
try
{ {
Thread.sleep(5000); fService.createStore("d" + i);
// Check that none of the crawlers has errored out. loader.recursiveLoad("source", "d" + i + ":/");
for (AVMCrawler crawler : crawlers) fService.createSnapshot("d" + i, null, null);
}
long startTime = System.currentTimeMillis();
List<AVMCrawler> crawlers = new ArrayList<AVMCrawler>();
List<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < n; i++)
{
crawlers.add(new AVMCrawler(fService));
threads.add(new Thread(crawlers.get(i)));
threads.get(i).start();
}
while (true)
{
try
{ {
if (crawler.getError()) Thread.sleep(5000);
// Check that none of the crawlers has errored out.
for (AVMCrawler crawler : crawlers)
{ {
for (AVMCrawler craw : crawlers) if (crawler.getError())
{ {
craw.setDone(); for (AVMCrawler craw : crawlers)
}
for (Thread thread : threads)
{
try
{ {
thread.join(); craw.setDone();
} }
catch (InterruptedException ie) for (Thread thread : threads)
{ {
// Do nothing. try
{
thread.join();
}
catch (InterruptedException ie)
{
// Do nothing.
}
} }
fail();
} }
fail();
} }
} }
catch (InterruptedException ie)
{
// Do nothing.
}
long now = System.currentTimeMillis();
if (now - startTime > runTime)
{
break;
}
} }
catch (InterruptedException ie) for (AVMCrawler crawler : crawlers)
{ {
// Do nothing. crawler.setDone();
} }
long now = System.currentTimeMillis(); for (Thread thread : threads)
if (now - startTime > runTime)
{ {
break; try
{
thread.join();
}
catch (InterruptedException ie)
{
// Do nothing.
}
} }
long ops = 0L;
for (AVMCrawler crawler : crawlers)
{
ops += crawler.getOpCount();
}
long time = System.currentTimeMillis() - startTime;
System.out.println("Ops/Sec: " + (ops * 1000L / time));
} }
for (AVMCrawler crawler : crawlers) finally
{ {
crawler.setDone(); for (int i = 0; i < m; i++)
}
for (Thread thread : threads)
{
try
{ {
thread.join(); if (fService.getStore("d" + i) != null) { fService.purgeStore("d" + i); }
}
catch (InterruptedException ie)
{
// Do nothing.
} }
} }
long ops = 0L;
for (AVMCrawler crawler : crawlers)
{
ops += crawler.getOpCount();
}
long time = System.currentTimeMillis() - startTime;
System.out.println("Ops/Sec: " + (ops * 1000L / time));
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2008 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -37,28 +37,39 @@ public class AVMScaleTestP extends AVMServiceTestBase
public void testScaling() public void testScaling()
{ {
int n = 250; // The number of BulkLoads to do. int n = 250; // The number of BulkLoads to do.
int futzCount = 10; // The number of post snapshot modifications to make after each load.
String load = "/Users/britt/hibernate-3.1"; // The tree of stuff to load. try
BulkLoader loader = new BulkLoader();
loader.setAvmService(fService);
loader.setPropertyCount(50);
BulkReader reader = new BulkReader();
reader.setAvmService(fService);
long lastTime = System.currentTimeMillis();
for (int i = 0; i < n; i++)
{ {
System.out.println("Round " + (i + 1)); int futzCount = 10; // The number of post snapshot modifications to make after each load.
fService.createStore("store" + i); String load = "config/alfresco"; // The tree of stuff to load.
loader.recursiveLoad(load, "store" + i + ":/"); BulkLoader loader = new BulkLoader();
fService.createSnapshot("store" + i, null, null); loader.setAvmService(fService);
long now = System.currentTimeMillis(); loader.setPropertyCount(50);
System.out.println("Load Time: " + (now - lastTime) + "ms"); BulkReader reader = new BulkReader();
lastTime = now; reader.setAvmService(fService);
reader.recursiveFutz("store" + i, "store" + i + ":/", futzCount); long lastTime = System.currentTimeMillis();
now = System.currentTimeMillis(); for (int i = 0; i < n; i++)
System.out.println("Read Time: " + (now - lastTime) + "ms"); {
System.out.flush(); System.out.println("Round " + (i + 1));
lastTime = now; fService.createStore("store" + i);
loader.recursiveLoad(load, "store" + i + ":/");
fService.createSnapshot("store" + i, null, null);
long now = System.currentTimeMillis();
System.out.println("Load Time: " + (now - lastTime) + "ms");
lastTime = now;
reader.recursiveFutz("store" + i, "store" + i + ":/", futzCount);
now = System.currentTimeMillis();
System.out.println("Read Time: " + (now - lastTime) + "ms");
System.out.flush();
lastTime = now;
}
}
finally
{
for (int i = 0; i < n; i++)
{
if (fService.getStore("store" + i) != null) { fService.purgeStore("store" + i); }
}
} }
} }
} }

View File

@@ -166,5 +166,7 @@ public class AVMServiceIndexTest extends AVMServiceTestBase
results = searchService.query(storeRef, "lucene", "PATH:\"//.\""); results = searchService.query(storeRef, "lucene", "PATH:\"//.\"");
assertEquals(4, results.length()); assertEquals(4, results.length());
results.close(); results.close();
fService.purgeStore("avmAsynchronousTest");
} }
} }

View File

@@ -27,19 +27,24 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.util.RemoteBulkLoader; import org.alfresco.repo.avm.util.RemoteBulkLoader;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMStoreDescriptor; import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
import org.alfresco.service.cmr.avmsync.AVMDifference; import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncException; import org.alfresco.service.cmr.avmsync.AVMSyncException;
import org.alfresco.service.cmr.avmsync.AVMSyncService; import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.remote.AVMRemote; import org.alfresco.service.cmr.remote.AVMRemote;
import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.NameMatcher; import org.alfresco.util.NameMatcher;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -291,50 +296,186 @@ public class AVMServiceLocalTest extends TestCase
} }
} }
/** //
* Test update to layered directory // Test updates to layered directories
*/ //
public void testSimpleUpdateLD() throws Exception
public void testSimpleUpdateLD1() throws Throwable
{
try
{
List<AVMDifference> diffs = fSyncService.compare(-1, "main:/", -1, "main:/", null);
assertEquals(0, diffs.size());
diffs = fSyncService.compare(-1, "layer:/", -1, "main:/", null);
assertEquals(0, diffs.size());
// create file f-a in main root dir
fService.createFile("main:/", "f-a").close();
diffs = fSyncService.compare(-1, "layer:/", -1, "main:/", null);
assertEquals("[layer:/f-a[-1] < main:/f-a[-1]]", diffs.toString());
assertEquals(1, diffs.size());
fService.createLayeredDirectory("main:/", "layer:/", "layer");
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals(0, diffs.size());
// create file f-b in main root dir
fService.createFile("main:/", "f-b").close();
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals(0, diffs.size());
// edit file f-b in layer
fService.getFileOutputStream("layer:/layer/f-b").close();
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals("[layer:/layer/f-b[-1] > main:/f-b[-1]]", diffs.toString());
assertEquals(1, diffs.size());
// update main from layer
fSyncService.update(diffs, null, false, false, false, false, null, null);
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals(0, diffs.size());
}
catch (Throwable t)
{
t.printStackTrace();
throw t;
}
}
public void testSimpleUpdateLD2() throws Throwable
{
try
{
// create directories base/d-a and file f-aa in main
fService.createDirectory("main:/", "base");
fService.createDirectory("main:/base", "d-a");
fService.createFile("main:/base/d-a", "f-aa").close();
List<AVMDifference> diffs = fSyncService.compare(-1, "layer" + ":/", -1, "main:/", null);
assertEquals("[layer:/base[-1] < main:/base[-1]]", diffs.toString());
assertEquals(1, diffs.size());
fService.createLayeredDirectory("main:/base", "layer:/", "layer-to-base");
diffs = fSyncService.compare(-1, "layer:/layer-to-base", -1, "main:/base", null);
assertEquals(0, diffs.size());
// edit file f-aa in main
fService.getFileOutputStream("main:/base/d-a/f-aa").close();
diffs = fSyncService.compare(-1, "layer:/layer-to-base", -1, "main:/base", null);
assertEquals(0, diffs.size());
// edit file f-aa in layer
fService.getFileOutputStream("layer:/layer-to-base/d-a/f-aa").close();
diffs = fSyncService.compare(-1, "layer:/layer-to-base", -1, "main:/base", null);
assertEquals("[layer:/layer-to-base/d-a/f-aa[-1] > main:/base/d-a/f-aa[-1]]", diffs.toString());
assertEquals(1, diffs.size());
// update main from layer
fSyncService.update(diffs, null, false, false, false, false, null, null);
diffs = fSyncService.compare(-1, "layer:/layer-to-base", -1, "main:/base", null);
assertEquals(0, diffs.size());
}
catch (Throwable t)
{
t.printStackTrace();
throw t;
}
}
public void testSimpleUpdateLD3() throws Throwable
{
try
{
fService.createDirectory("main:/", "base");
fService.createLayeredDirectory("main:/base", "layer:/", "layer-to-base");
List<AVMDifference> diffs = fSyncService.compare(-1, "layer:/layer-to-base", -1, "main:/base", null);
assertEquals(0, diffs.size());
// create directory d-a and file f-aa in layer
fService.createDirectory("layer:/layer-to-base", "d-a");
fService.createFile("layer:/layer-to-base/d-a", "f-aa").close();
diffs = fSyncService.compare(-1, "layer:/layer-to-base", -1, "main:/base", null);
assertEquals("[layer:/layer-to-base/d-a[-1] > "+"main:/base/d-a[-1]]", diffs.toString());
assertEquals(1, diffs.size());
// update main from layer
fSyncService.update(diffs, null, false, false, false, false, null, null);
diffs = fSyncService.compare(-1, "layer:/layer-to-base", -1, "main:/base", null);
assertEquals(0, diffs.size());
}
catch (Throwable t)
{
t.printStackTrace();
throw t;
}
}
public void testSimpleUpdateLD4() throws Exception
{ {
try try
{ {
fService.createLayeredDirectory("main:/", "layer:/", "layer"); fService.createLayeredDirectory("main:/", "layer:/", "layer");
// Create a directory. // create directory b and file foo in layer
fService.createDirectory("layer:/layer", "b"); fService.createDirectory("layer:/layer", "b");
// Create a file.
fService.createFile("layer:/layer/b", "foo").close(); fService.createFile("layer:/layer/b", "foo").close();
List<AVMDifference> diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null); List<AVMDifference> diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals(1, diffs.size()); assertEquals(1, diffs.size());
assertEquals("[layer:/layer/b[-1] > main:/b[-1]]", diffs.toString()); assertEquals("[layer:/layer/b[-1] > main:/b[-1]]", diffs.toString());
fService.createSnapshot("layer", null, null); fService.createSnapshot("layer", null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null); fSyncService.update(diffs, null, false, false, false, false, null, null);
fService.createSnapshot("main", null, null); fService.createSnapshot("main", null, null);
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null); diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals(0, diffs.size()); assertEquals(0, diffs.size());
fSyncService.flatten("layer:/layer", "main:/"); fSyncService.flatten("layer:/layer", "main:/");
recursiveList("layer"); recursiveList("layer");
recursiveList("main"); recursiveList("main");
fService.createStore("layer2"); fService.createStore("layer2");
fService.createLayeredDirectory("layer:/layer", "layer2:/", "layer"); fService.createLayeredDirectory("layer:/layer", "layer2:/", "layer");
// Create a directory. // create directory c and file foo in layer2
fService.createDirectory("layer2:/layer/", "c"); fService.createDirectory("layer2:/layer/", "c");
// Create a file.
fService.createFile("layer2:/layer/c", "foo").close(); fService.createFile("layer2:/layer/c", "foo").close();
fService.createSnapshot("layer2", null, null); fService.createSnapshot("layer2", null, null);
diffs = fSyncService.compare(-1, "layer2:/layer", -1, "layer:/layer", null); diffs = fSyncService.compare(-1, "layer2:/layer", -1, "layer:/layer", null);
assertEquals(1, diffs.size()); assertEquals(1, diffs.size());
assertEquals("[layer2:/layer/c[-1] > layer:/layer/c[-1]]", diffs.toString()); assertEquals("[layer2:/layer/c[-1] > layer:/layer/c[-1]]", diffs.toString());
fSyncService.update(diffs, null, false, false, false, false, null, null); fSyncService.update(diffs, null, false, false, false, false, null, null);
diffs = fSyncService.compare(-1, "layer2:/layer", -1, "layer:/layer", null); diffs = fSyncService.compare(-1, "layer2:/layer", -1, "layer:/layer", null);
assertEquals(0, diffs.size()); assertEquals(0, diffs.size());
fSyncService.flatten("layer2:/layer", "layer:/layer"); fSyncService.flatten("layer2:/layer", "layer:/layer");
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null); diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals(1, diffs.size()); assertEquals(1, diffs.size());
assertEquals("[layer:/layer/c[-1] > main:/c[-1]]", diffs.toString()); assertEquals("[layer:/layer/c[-1] > main:/c[-1]]", diffs.toString());
recursiveList("layer2"); recursiveList("layer2");
recursiveList("layer"); recursiveList("layer");
recursiveList("main"); recursiveList("main");
@@ -723,6 +864,145 @@ public class AVMServiceLocalTest extends TestCase
throw e; throw e;
} }
} }
/**
* Test file properties update ...
*/
public void testUpdateFileTitleAndDescription() throws Exception
{
try
{
fService.createLayeredDirectory("main:/", "layer:/", "layer");
fService.createDirectory("layer:/layer", "b");
fService.createFile("layer:/layer/b", "foo").close();
List<AVMDifference> diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals("[layer:/layer/b[-1] > main:/b[-1]]", diffs.toString());
fService.createSnapshot("layer", 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:/", null);
assertEquals(0, diffs.size());
fSyncService.flatten("layer:/layer", "main:/");
assertEquals(0, fService.getNodeProperties(-1, "main:/b/foo").size());
assertEquals(0, fService.getNodeProperties(-1, "layer:/layer/b/foo").size());
Map<QName, PropertyValue> properties = new HashMap<QName, PropertyValue>();
properties.put(ContentModel.PROP_TITLE, new PropertyValue(DataTypeDefinition.TEXT, "foo title"));
properties.put(ContentModel.PROP_DESCRIPTION, new PropertyValue(DataTypeDefinition.TEXT, "foo descrip"));
fService.setNodeProperties("layer:/layer/b/foo", properties);
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals("[layer:/layer/b/foo[-1] > main:/b/foo[-1]]", diffs.toString());
fService.createSnapshot("layer", 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:/", null);
assertEquals(0, diffs.size());
fSyncService.flatten("layer:/layer", "main:/");
assertEquals(2, fService.getNodeProperties(-1, "main:/b/foo").size());
assertEquals("foo title", fService.getNodeProperty(-1, "main:/b/foo", ContentModel.PROP_TITLE).getStringValue());
assertEquals("foo descrip", fService.getNodeProperty(-1, "main:/b/foo", ContentModel.PROP_DESCRIPTION).getStringValue());
}
catch (Exception e)
{
e.printStackTrace(System.err);
throw e;
}
}
/**
* Test directory properties update ...
*/
public void testUpdateDirectoryTitleAndDescription() throws Exception
{
try
{
fService.createLayeredDirectory("main:/", "layer:/", "layer");
fService.createDirectory("layer:/layer", "b");
fService.createFile("layer:/layer/b", "foo").close();
List<AVMDifference> diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals("[layer:/layer/b[-1] > main:/b[-1]]", diffs.toString());
fService.createSnapshot("layer", 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:/", null);
assertEquals(0, diffs.size());
fSyncService.flatten("layer:/layer", "main:/");
assertEquals(0, fService.getNodeProperties(-1, "main:/b").size());
assertEquals(0, fService.getNodeProperties(-1, "layer:/layer/b").size());
Map<QName, PropertyValue> properties = new HashMap<QName, PropertyValue>();
properties.put(ContentModel.PROP_TITLE, new PropertyValue(DataTypeDefinition.TEXT, "b title"));
properties.put(ContentModel.PROP_DESCRIPTION, new PropertyValue(DataTypeDefinition.TEXT, "b descrip"));
fService.setNodeProperties("layer:/layer/b", properties);
assertEquals(0, fService.getNodeProperties(-1, "main:/b").size());
assertEquals(2, fService.getNodeProperties(-1, "layer:/layer/b").size());
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals("[layer:/layer/b[-1] > main:/b[-1]]", diffs.toString());
fService.createSnapshot("layer", null, null);
fSyncService.update(diffs, null, false, false, false, false, null, null);
fService.createSnapshot("main", null, null);
assertEquals(2, fService.getNodeProperties(-1, "main:/b").size());
assertEquals(2, fService.getNodeProperties(-1, "layer:/layer/b").size());
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals(0, diffs.size());
fSyncService.flatten("layer:/layer", "main:/");
assertEquals(2, fService.getNodeProperties(-1, "main:/b").size());
assertEquals(2, fService.getNodeProperties(-1, "layer:/layer/b").size());
assertEquals("b title", fService.getNodeProperty(-1, "main:/b", ContentModel.PROP_TITLE).getStringValue());
assertEquals("b descrip", fService.getNodeProperty(-1, "main:/b", ContentModel.PROP_DESCRIPTION).getStringValue());
fService.setNodeProperty("layer:/layer/b", ContentModel.PROP_TITLE, new PropertyValue(DataTypeDefinition.TEXT, "b title2"));
fService.setNodeProperty("layer:/layer/b", ContentModel.PROP_DESCRIPTION, new PropertyValue(DataTypeDefinition.TEXT, "b descrip2"));
diffs = fSyncService.compare(-1, "layer:/layer", -1, "main:/", null);
assertEquals("[layer:/layer/b[-1] > main:/b[-1]]", diffs.toString());
fService.createSnapshot("layer", 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:/", null);
assertEquals(0, diffs.size());
fSyncService.flatten("layer:/layer", "main:/");
assertEquals(2, fService.getNodeProperties(-1, "main:/b").size());
assertEquals(2, fService.getNodeProperties(-1, "layer:/layer/b").size());
assertEquals("b title2", fService.getNodeProperty(-1, "main:/b", ContentModel.PROP_TITLE).getStringValue());
assertEquals("b descrip2", fService.getNodeProperty(-1, "main:/b", ContentModel.PROP_DESCRIPTION).getStringValue());
}
catch (Exception e)
{
e.printStackTrace(System.err);
throw e;
}
}
protected void recursiveContents(String path) protected void recursiveContents(String path)
{ {

View File

@@ -205,6 +205,10 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
finally
{
fService.purgeStore("I have spaces");
}
} }
public void testHeadPathsInLayers() throws Exception public void testHeadPathsInLayers() throws Exception
@@ -234,6 +238,11 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
finally
{
fService.purgeStore("user");
fService.purgeStore("sandbox");
}
} }
/** /**
@@ -280,6 +289,8 @@ public class AVMServiceTest extends AVMServiceTestBase
fLockingService.removeStoreLocks("main"); fLockingService.removeStoreLocks("main");
fLockingService.removeWebProject("main"); fLockingService.removeWebProject("main");
authService.authenticate("admin", "admin".toCharArray()); authService.authenticate("admin", "admin".toCharArray());
fService.purgeStore("test");
} }
} }
@@ -489,6 +500,10 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
finally
{
fService.purgeStore("layer");
}
} }
public void testBranchLayerSnapshot() throws Exception public void testBranchLayerSnapshot() throws Exception
@@ -524,6 +539,11 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
finally
{
fService.purgeStore("layer");
fService.purgeStore("branch");
}
} }
/** /**
@@ -1245,6 +1265,10 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
finally
{
fService.purgeStore("branch");
}
} }
/** /**
@@ -1266,6 +1290,10 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
finally
{
fService.purgeStore("foo");
}
} }
/** /**
@@ -1761,6 +1789,10 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(System.err); e.printStackTrace(System.err);
throw e; throw e;
} }
finally
{
fService.purgeStore("layer");
}
} }
/** /**
@@ -1810,6 +1842,10 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
finally
{
fService.purgeStore("area");
}
} }
/** /**
@@ -1858,6 +1894,10 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
} }
finally
{
fService.purgeStore("area");
}
} }
/** /**
@@ -1898,6 +1938,10 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(System.err); e.printStackTrace(System.err);
throw e; throw e;
} }
finally
{
fService.purgeStore("source");
}
} }
/** /**
@@ -1945,6 +1989,11 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(System.err); e.printStackTrace(System.err);
throw e; throw e;
} }
finally
{
fService.purgeStore("foo-staging");
fService.purgeStore("area");
}
} }
/** /**
@@ -2145,6 +2194,11 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(System.err); e.printStackTrace(System.err);
throw e; throw e;
} }
finally
{
fService.purgeStore("source");
fService.purgeStore("dest");
}
} }
/** /**
@@ -2394,6 +2448,10 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(System.err); e.printStackTrace(System.err);
throw e; throw e;
} }
finally
{
fService.purgeStore("layer");
}
} }
/** /**
@@ -3539,9 +3597,8 @@ public class AVMServiceTest extends AVMServiceTestBase
setupBasicTree(); setupBasicTree();
fService.createStore("second"); fService.createStore("second");
List<AVMStoreDescriptor> repos = fService.getStores(); List<AVMStoreDescriptor> repos = fService.getStores();
assertEquals(2, repos.size()); assertTrue(checkStoreExists("main", repos));
System.out.println(repos.get(0)); assertTrue(checkStoreExists("second", repos));
System.out.println(repos.get(1));
fService.createBranch(-1, "main:/", "second:/", "main"); fService.createBranch(-1, "main:/", "second:/", "main");
fService.createSnapshot("second", null, null); fService.createSnapshot("second", null, null);
System.out.println(recursiveList("second", -1, true)); System.out.println(recursiveList("second", -1, true));
@@ -3563,6 +3620,22 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(System.err); e.printStackTrace(System.err);
throw e; throw e;
} }
finally
{
fService.purgeStore("second");
}
}
private boolean checkStoreExists(String storeName, List<AVMStoreDescriptor> stores)
{
for (AVMStoreDescriptor store : stores)
{
if (store.getName().equals(storeName))
{
return true;
}
}
return false;
} }
/** /**
@@ -3627,6 +3700,10 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(System.err); e.printStackTrace(System.err);
throw e; throw e;
} }
finally
{
fService.purgeStore("second");
}
} }
/** /**
@@ -5154,7 +5231,6 @@ public class AVMServiceTest extends AVMServiceTestBase
fService.createStore("second"); fService.createStore("second");
fService.setStoreProperty("second", QName.createQName("", ".dns.alice"), new PropertyValue(null, "alice-space")); fService.setStoreProperty("second", QName.createQName("", ".dns.alice"), new PropertyValue(null, "alice-space"));
Map<String, Map<QName, PropertyValue>> matches = fService.queryStoresPropertyKeys(QName.createQName("", ".dns.%")); Map<String, Map<QName, PropertyValue>> matches = fService.queryStoresPropertyKeys(QName.createQName("", ".dns.%"));
assertEquals(2, matches.size());
assertEquals(1, matches.get("main").size()); assertEquals(1, matches.get("main").size());
assertEquals(1, matches.get("second").size()); assertEquals(1, matches.get("second").size());
assertEquals("alice-preview", matches.get("main").get(QName.createQName(null, ".dns.alice--preview")).getStringValue()); assertEquals("alice-preview", matches.get("main").get(QName.createQName(null, ".dns.alice--preview")).getStringValue());
@@ -5165,5 +5241,9 @@ public class AVMServiceTest extends AVMServiceTestBase
e.printStackTrace(System.err); e.printStackTrace(System.err);
} }
finally
{
fService.purgeStore("second");
}
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2008 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -24,10 +24,11 @@
package org.alfresco.repo.avm; package org.alfresco.repo.avm;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.search.AVMSnapShotTriggeredIndexingMethodInterceptor; import org.alfresco.repo.search.AVMSnapShotTriggeredIndexingMethodInterceptor;
@@ -35,7 +36,6 @@ import org.alfresco.repo.search.IndexerAndSearcher;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser; import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
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.avm.AVMStoreDescriptor;
import org.alfresco.service.cmr.avm.locking.AVMLockingService; import org.alfresco.service.cmr.avm.locking.AVMLockingService;
import org.alfresco.service.cmr.avmsync.AVMSyncService; import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.ContentWriter;
@@ -47,8 +47,6 @@ import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.springframework.context.support.FileSystemXmlApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext;
import junit.framework.TestCase;
/** /**
* Base class for AVMService tests. * Base class for AVMService tests.
* @author britt * @author britt
@@ -161,19 +159,17 @@ public class AVMServiceTestBase extends TestCase
} }
/** /**
* Cleanup after a test. Purge all stores. Move alf_data * Cleanup after a test. Purge main store.
* directory aside.
*/ */
@Override @Override
protected void tearDown() throws Exception protected void tearDown() throws Exception
{ {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
System.out.println("Timing: " + (now - fStartTime) + "ms"); System.out.println("Timing: " + (now - fStartTime) + "ms");
List<AVMStoreDescriptor> descriptors = fService.getStores();
for (AVMStoreDescriptor desc : descriptors) if (fService.getStore("main") != null) { fService.purgeStore("main"); }
{
fService.purgeStore(desc.getName()); // Move alf_data directory aside.
}
// fContext.close(); // fContext.close();
// File alfData = new File("alf_data"); // File alfData = new File("alf_data");
// File target = new File("alf_data" + now); // File target = new File("alf_data" + now);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2008 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -31,8 +31,9 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.alfresco.repo.domain.DbAccessControlList; import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.hibernate.DbAccessControlListImpl; import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.security.permissions.ACLCopyMode; import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.repo.security.permissions.ACLType;
import org.alfresco.service.cmr.avm.AVMBadArgumentException; import org.alfresco.service.cmr.avm.AVMBadArgumentException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMNotFoundException; import org.alfresco.service.cmr.avm.AVMNotFoundException;
@@ -40,6 +41,10 @@ import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avmsync.AVMDifference; import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncException; import org.alfresco.service.cmr.avmsync.AVMSyncException;
import org.alfresco.service.cmr.avmsync.AVMSyncService; import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.NameMatcher; import org.alfresco.util.NameMatcher;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -63,6 +68,11 @@ public class AVMSyncServiceImpl implements AVMSyncService
* The AVMRepository. * The AVMRepository.
*/ */
private AVMRepository fAVMRepository; private AVMRepository fAVMRepository;
/**
* The PermissionService
*/
private PermissionService fPermissionService;
/** /**
* Do nothing constructor. * Do nothing constructor.
@@ -84,6 +94,11 @@ public class AVMSyncServiceImpl implements AVMSyncService
{ {
fAVMRepository = avmRepository; fAVMRepository = avmRepository;
} }
public void setPermissionService(PermissionService service)
{
fPermissionService = service;
}
/** /**
* Get a difference list between two corresponding node trees. * Get a difference list between two corresponding node trees.
@@ -132,7 +147,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
else else
{ {
// Invoke the recursive implementation. // Invoke the recursive implementation.
compare(srcVersion, srcDesc, dstVersion, dstDesc, result, excluder); compare(srcVersion, srcDesc, dstVersion, dstDesc, result, excluder, true);
} }
return result; return result;
} }
@@ -146,7 +161,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
*/ */
private void compare(int srcVersion, AVMNodeDescriptor srcDesc, private void compare(int srcVersion, AVMNodeDescriptor srcDesc,
int dstVersion, AVMNodeDescriptor dstDesc, int dstVersion, AVMNodeDescriptor dstDesc,
List<AVMDifference> result, NameMatcher excluder) List<AVMDifference> result, NameMatcher excluder, boolean firstLevel)
{ {
// Determine how the source and destination nodes differ. // Determine how the source and destination nodes differ.
if (excluder != null && (excluder.matches(srcDesc.getPath()) || if (excluder != null && (excluder.matches(srcDesc.getPath()) ||
@@ -154,7 +169,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
{ {
return; return;
} }
int diffCode = compareOne(srcDesc, dstDesc); int diffCode = compareOne(srcDesc, dstDesc, false);
switch (diffCode) switch (diffCode)
{ {
case AVMDifference.SAME : case AVMDifference.SAME :
@@ -179,6 +194,33 @@ public class AVMSyncServiceImpl implements AVMSyncService
if (srcDesc.isLayeredDirectory() && if (srcDesc.isLayeredDirectory() &&
srcDesc.getIndirection().equals(dstDesc.getPath()) && srcVersion < 0 && dstVersion < 0) srcDesc.getIndirection().equals(dstDesc.getPath()) && srcVersion < 0 && dstVersion < 0)
{ {
// skip firstLevel (root)
if (! firstLevel)
{
// compare directory itself - eg. for an ACL change
int dirDiffCode = compareOne(srcDesc, dstDesc, true);
switch (dirDiffCode)
{
case AVMDifference.OLDER :
case AVMDifference.NEWER :
case AVMDifference.CONFLICT :
{
result.add(new AVMDifference(srcVersion, srcDesc.getPath(),
dstVersion, dstDesc.getPath(),
dirDiffCode));
return; // short circuit
}
case AVMDifference.SAME :
{
break;
}
default :
{
throw new AVMSyncException("Invalid Difference Code " + dirDiffCode + " - Internal Error.");
}
}
}
// Get only a direct listing, since that's all that can be different. // Get only a direct listing, since that's all that can be different.
Map<String, AVMNodeDescriptor> srcList = Map<String, AVMNodeDescriptor> srcList =
fAVMService.getDirectoryListingDirect(srcDesc, true); fAVMService.getDirectoryListingDirect(srcDesc, true);
@@ -213,7 +255,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
// Otherwise recursively invoke. // Otherwise recursively invoke.
compare(srcVersion, srcChild, compare(srcVersion, srcChild,
dstVersion, dstChild, dstVersion, dstChild,
result, excluder); result, excluder, false);
} }
return; return;
} }
@@ -221,6 +263,33 @@ public class AVMSyncServiceImpl implements AVMSyncService
if (dstDesc.isLayeredDirectory() && if (dstDesc.isLayeredDirectory() &&
dstDesc.getIndirection().equals(srcDesc.getPath()) && srcVersion < 0 && dstVersion < 0) dstDesc.getIndirection().equals(srcDesc.getPath()) && srcVersion < 0 && dstVersion < 0)
{ {
// skip firstLevel (root)
if (! firstLevel)
{
// compare directory itself - eg. for an ACL change
int dirDiffCode = compareOne(srcDesc, dstDesc, true);
switch (dirDiffCode)
{
case AVMDifference.OLDER :
case AVMDifference.NEWER :
case AVMDifference.CONFLICT :
{
result.add(new AVMDifference(srcVersion, srcDesc.getPath(),
dstVersion, dstDesc.getPath(),
dirDiffCode));
return; // short circuit
}
case AVMDifference.SAME :
{
break;
}
default :
{
throw new AVMSyncException("Invalid Difference Code " + dirDiffCode + " - Internal Error.");
}
}
}
// Get direct content of destination. // Get direct content of destination.
Map<String, AVMNodeDescriptor> dstList = Map<String, AVMNodeDescriptor> dstList =
fAVMService.getDirectoryListingDirect(dstDesc, true); fAVMService.getDirectoryListingDirect(dstDesc, true);
@@ -254,7 +323,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
// Otherwise, recursively invoke. // Otherwise, recursively invoke.
compare(srcVersion, srcChild, compare(srcVersion, srcChild,
dstVersion, dstChild, dstVersion, dstChild,
result, excluder); result, excluder, false);
} }
return; return;
} }
@@ -286,7 +355,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
// Otherwise recursive invocation. // Otherwise recursive invocation.
compare(srcVersion, srcChild, compare(srcVersion, srcChild,
dstVersion, dstChild, dstVersion, dstChild,
result, excluder); result, excluder, false);
} }
// Iterate over the destination. // Iterate over the destination.
for (String name : dstList.keySet()) for (String name : dstList.keySet())
@@ -312,7 +381,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
} }
default : default :
{ {
throw new AVMSyncException("Invalid Difference Code, Internal Error."); throw new AVMSyncException("Invalid Difference Code " + diffCode + " - Internal Error.");
} }
} }
} }
@@ -404,73 +473,15 @@ public class AVMSyncServiceImpl implements AVMSyncService
int diffCode = AVMDifference.NEWER; int diffCode = AVMDifference.NEWER;
if (dstDesc != null) if (dstDesc != null)
{ {
diffCode = compareOne(srcDesc, dstDesc); diffCode = compareOne(srcDesc, dstDesc, false);
} }
// Keep track of stores updated so that they can all be snapshotted // Keep track of stores updated so that they can all be snapshotted
// at end of update. // at end of update.
String dstPath = diff.getDestinationPath(); String dstPath = diff.getDestinationPath();
destStores.add(dstPath.substring(0, dstPath.indexOf(':'))); destStores.add(dstPath.substring(0, dstPath.indexOf(':')));
// Dispatch.
switch (diffCode) dispatchUpdate(diffCode, dstParts[0], dstParts[1], excluder, srcDesc, dstDesc,
{ ignoreConflicts, ignoreOlder, overrideConflicts, overrideOlder);
case AVMDifference.SAME :
{
// Nada to do.
continue;
}
case AVMDifference.NEWER :
{
// You can't delete what isn't there.
linkIn(dstParts[0], dstParts[1], srcDesc, excluder, dstDesc != null && !dstDesc.isDeleted());
continue;
}
case AVMDifference.OLDER :
{
// You can force it.
if (overrideOlder)
{
linkIn(dstParts[0], dstParts[1], srcDesc, excluder, !dstDesc.isDeleted());
continue;
}
// You can ignore it.
if (ignoreOlder)
{
continue;
}
// Or it's an error.
throw new AVMSyncException("Older version prevents update.");
}
case AVMDifference.CONFLICT :
{
// You can force it.
if (overrideConflicts)
{
linkIn(dstParts[0], dstParts[1], srcDesc, excluder, true);
continue;
}
// You can ignore it.
if (ignoreConflicts)
{
continue;
}
// Or it's an error.
throw new AVMSyncException("Conflict prevents update.");
}
case AVMDifference.DIRECTORY :
{
// You can only ignore this.
if (ignoreConflicts)
{
continue;
}
// Otherwise it's an error.
throw new AVMSyncException("Directory conflict prevents update.");
}
default :
{
throw new AVMSyncException("Invalid Difference Code: Internal Error.");
}
}
} }
for (String storeName : destStores) for (String storeName : destStores)
{ {
@@ -481,6 +492,75 @@ public class AVMSyncServiceImpl implements AVMSyncService
fgLogger.debug("Raw Update: " + (System.currentTimeMillis() - start)); fgLogger.debug("Raw Update: " + (System.currentTimeMillis() - start));
} }
} }
private void dispatchUpdate(int diffCode, String parentPath, String name, NameMatcher excluder, AVMNodeDescriptor srcDesc, AVMNodeDescriptor dstDesc,
boolean ignoreConflicts, boolean ignoreOlder, boolean overrideConflicts, boolean overrideOlder)
{
// Dispatch.
switch (diffCode)
{
case AVMDifference.SAME :
{
// Nada to do.
return;
}
case AVMDifference.NEWER :
{
// You can't delete what isn't there.
linkIn(parentPath, name, srcDesc, excluder, dstDesc != null && !dstDesc.isDeleted());
return;
}
case AVMDifference.OLDER :
{
// You can force it.
if (overrideOlder)
{
linkIn(parentPath, name, srcDesc, excluder, !dstDesc.isDeleted());
return;
}
// You can ignore it.
if (ignoreOlder)
{
return;
}
// Or it's an error.
throw new AVMSyncException("Older version prevents update.");
}
case AVMDifference.CONFLICT :
{
// You can force it.
if (overrideConflicts)
{
linkIn(parentPath, name, srcDesc, excluder, true);
return;
}
// You can ignore it.
if (ignoreConflicts)
{
return;
}
// Or it's an error.
throw new AVMSyncException("Conflict prevents update.");
}
case AVMDifference.DIRECTORY :
{
int dirDiffCode = compareOne(srcDesc, dstDesc, true);
if (dirDiffCode == AVMDifference.DIRECTORY)
{
// error
throw new AVMSyncException("Unexpected diff code: " + dirDiffCode);
}
dispatchUpdate(dirDiffCode, parentPath, name, excluder, srcDesc, dstDesc,
ignoreConflicts, ignoreOlder, overrideConflicts, overrideOlder);
return;
}
default :
{
throw new AVMSyncException("Invalid Difference Code " + diffCode + " - Internal Error.");
}
}
}
/** /**
* Do the actual work of connecting nodes to the destination tree. * Do the actual work of connecting nodes to the destination tree.
@@ -609,7 +689,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
recursiveCopy(newParentDesc, entry.getKey(), entry.getValue(), excluder); recursiveCopy(newParentDesc, entry.getKey(), entry.getValue(), excluder);
} }
} }
/** /**
* The workhorse of comparison and updating. Determine the versioning relationship * The workhorse of comparison and updating. Determine the versioning relationship
* of two nodes. * of two nodes.
@@ -617,7 +697,7 @@ public class AVMSyncServiceImpl implements AVMSyncService
* @param dstDesc Descriptor for the destination node. * @param dstDesc Descriptor for the destination node.
* @return One of SAME, OLDER, NEWER, CONFLICT, DIRECTORY * @return One of SAME, OLDER, NEWER, CONFLICT, DIRECTORY
*/ */
private int compareOne(AVMNodeDescriptor srcDesc, AVMNodeDescriptor dstDesc) private int compareOne(AVMNodeDescriptor srcDesc, AVMNodeDescriptor dstDesc, boolean compareDir)
{ {
if (srcDesc == null) if (srcDesc == null)
{ {
@@ -625,21 +705,17 @@ public class AVMSyncServiceImpl implements AVMSyncService
} }
if (srcDesc.getId() == dstDesc.getId()) if (srcDesc.getId() == dstDesc.getId())
{ {
// Identical
return AVMDifference.SAME; return AVMDifference.SAME;
} }
// Matched directories that are not identical are nominally in conflict
// but get their own special difference code for comparison logic. The DIRECTORY
// difference code never gets returned to callers of compare.
if (srcDesc.isDirectory() && dstDesc.isDirectory())
{
return AVMDifference.DIRECTORY;
}
// Check for mismatched fundamental types. // Check for mismatched fundamental types.
if ((srcDesc.isDirectory() && dstDesc.isFile()) || if ((srcDesc.isDirectory() && dstDesc.isFile()) ||
(srcDesc.isFile() && dstDesc.isDirectory())) (srcDesc.isFile() && dstDesc.isDirectory()))
{ {
return AVMDifference.CONFLICT; return AVMDifference.CONFLICT;
} }
// A deleted node on either side means uniform handling because // A deleted node on either side means uniform handling because
// a deleted node can be the descendent of any other type of node. // a deleted node can be the descendent of any other type of node.
if (srcDesc.isDeleted() || dstDesc.isDeleted()) if (srcDesc.isDeleted() || dstDesc.isDeleted())
@@ -660,6 +736,58 @@ public class AVMSyncServiceImpl implements AVMSyncService
// Must be a conflict. // Must be a conflict.
return AVMDifference.CONFLICT; return AVMDifference.CONFLICT;
} }
if (srcDesc.isDirectory() && dstDesc.isDirectory())
{
// Both source and destination are both some kind of directory.
if (! compareDir)
{
// note: the DIRECTORY difference code never gets returned to external callers of compare.
return AVMDifference.DIRECTORY;
}
else
{
// Matched directories that are not identical should be compared (initially) based on ACLs to see if they're newer, older or in conflict
if ((srcDesc.isLayeredDirectory() && srcDesc.getIndirection().equals(dstDesc.getPath())) ||
(dstDesc.isLayeredDirectory() && dstDesc.getIndirection().equals(srcDesc.getPath())))
{
// Either: Source is a layered directory and points at the destination plain/layered directory
// Or: Destination is a layered directory and points at the source plain directory
// Check properties (eg. title/description)
if (compareNodeProps(srcDesc, dstDesc) == AVMDifference.SAME)
{
// Check ACLs
int dirDiffCode = compareACLs(srcDesc, dstDesc);
if (dirDiffCode != AVMDifference.CONFLICT)
{
return dirDiffCode;
}
}
// drop through to check common ancestor
}
// Check common ancestor
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;
}
// They must, finally, be in conflict.
return AVMDifference.CONFLICT;
}
}
// At this point both source and destination are both some kind of file. // At this point both source and destination are both some kind of file.
if (srcDesc.isLayeredFile()) if (srcDesc.isLayeredFile())
{ {
@@ -722,6 +850,156 @@ public class AVMSyncServiceImpl implements AVMSyncService
// The must, finally, be in conflict. // The must, finally, be in conflict.
return AVMDifference.CONFLICT; return AVMDifference.CONFLICT;
} }
// compare node properties
private int compareNodeProps(AVMNodeDescriptor srcDesc, AVMNodeDescriptor dstDesc)
{
Map<QName, PropertyValue> srcProps = fAVMService.getNodeProperties(srcDesc);
Map<QName, PropertyValue> dstProps = fAVMService.getNodeProperties(dstDesc);
if (srcProps.size() == dstProps.size())
{
for (Map.Entry<QName, PropertyValue> srcEntry : srcProps.entrySet())
{
PropertyValue srcValue = srcEntry.getValue();
PropertyValue dstValue = dstProps.get(srcEntry.getKey());
if ((srcValue == null) && (dstValue == null))
{
continue;
}
else if ((srcValue != null) && (dstValue != null) &&
(srcValue.equals(dstValue)))
{
continue;
}
else
{
return AVMDifference.CONFLICT;
}
}
return AVMDifference.SAME;
}
return AVMDifference.CONFLICT;
}
// compare ACLs
private int compareACLs(AVMNodeDescriptor srcDesc, AVMNodeDescriptor dstDesc)
{
DbAccessControlList srcAcl = getACL(srcDesc.getPath());
DbAccessControlList dstAcl = getACL(dstDesc.getPath());
if ((srcAcl == null) && (dstAcl == null))
{
return AVMDifference.SAME;
}
else if (srcAcl != null)
{
if ((dstAcl != null) && (srcAcl.getAclId() == dstAcl.getAclId()))
{
return AVMDifference.SAME;
}
if (srcAcl.getAclType().equals(ACLType.LAYERED))
{
if ((dstAcl == null) || dstAcl.getAclType().equals(ACLType.SHARED) || dstAcl.getAclType().equals(ACLType.LAYERED) || dstAcl.getAclType().equals(ACLType.DEFINING))
{
return AVMDifference.SAME;
}
else
{
// TODO review
throw new AVMSyncException("srcAcl type: " + srcAcl.getAclType() + ", unexpected dstAcl type: " + dstAcl.getAclType());
}
}
else if (srcAcl.getAclType().equals(ACLType.DEFINING))
{
if ((dstAcl == null) || dstAcl.getAclType().equals(ACLType.SHARED) || dstAcl.getAclType().equals(ACLType.LAYERED))
{
return AVMDifference.NEWER;
}
else if (dstAcl.getAclType().equals(ACLType.DEFINING))
{
// compare ACEs
NodeRef srcNodeRef = AVMNodeConverter.ToNodeRef(-1, srcDesc.getPath());
Set<AccessPermission> srcSet = fPermissionService.getAllSetPermissions(srcNodeRef);
NodeRef dstNodeRef = AVMNodeConverter.ToNodeRef(-1, dstDesc.getPath());
Set<AccessPermission> dstSet = fPermissionService.getAllSetPermissions(dstNodeRef);
if (srcSet.size() == dstSet.size())
{
boolean same = true;
for (AccessPermission srcPerm : srcSet)
{
if (! dstSet.contains(srcPerm))
{
same = false;
break;
}
}
if (same)
{
return AVMDifference.SAME;
}
}
}
else
{
// TODO review
throw new AVMSyncException("srcAcl type: " + srcAcl.getAclType() + ", unexpected dstAcl type: " + dstAcl.getAclType());
}
}
else if (srcAcl.getAclType().equals(ACLType.SHARED))
{
if ((dstAcl == null) || dstAcl.getAclType().equals(ACLType.SHARED))
{
// compare ACEs
NodeRef srcNodeRef = AVMNodeConverter.ToNodeRef(-1, srcDesc.getPath());
Set<AccessPermission> srcSet = fPermissionService.getAllSetPermissions(srcNodeRef);
NodeRef dstNodeRef = AVMNodeConverter.ToNodeRef(-1, dstDesc.getPath());
Set<AccessPermission> dstSet = fPermissionService.getAllSetPermissions(dstNodeRef);
if (srcSet.size() == dstSet.size())
{
boolean same = true;
for (AccessPermission srcPerm : srcSet)
{
if (! dstSet.contains(srcPerm))
{
same = false;
break;
}
}
if (same)
{
return AVMDifference.SAME;
}
}
return AVMDifference.CONFLICT;
}
else
{
// TODO review
throw new AVMSyncException("srcAcl type: " + srcAcl.getAclType() + ", unexpected dstAcl type: " + dstAcl.getAclType());
}
}
}
else if (srcAcl == null)
{
if (dstAcl != null)
{
return AVMDifference.SAME;
}
}
return AVMDifference.CONFLICT;
}
/** /**
* Flattens a layer so that all all nodes under and including * Flattens a layer so that all all nodes under and including

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2008 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -50,6 +50,9 @@ public class AvmBootstrap extends AbstractLifecycleBean
private AVMRepository avmRepository; private AVMRepository avmRepository;
private PermissionService permissionService; private PermissionService permissionService;
private AVMSyncServiceImpl avmSyncService;
public AvmBootstrap() public AvmBootstrap()
{ {
@@ -70,6 +73,11 @@ public class AvmBootstrap extends AbstractLifecycleBean
{ {
permissionService = service; permissionService = service;
} }
public void setAvmSyncService(AVMSyncServiceImpl service)
{
avmSyncService = service;
}
/** /**
* Provide a list of {@link Issuer issuers} to bootstrap on context initialization. * Provide a list of {@link Issuer issuers} to bootstrap on context initialization.
@@ -93,6 +101,7 @@ public class AvmBootstrap extends AbstractLifecycleBean
} }
avmLockingAwareService.init(); avmLockingAwareService.init();
avmRepository.setPermissionService(permissionService); avmRepository.setPermissionService(permissionService);
avmSyncService.setPermissionService(permissionService);
} }
/** NO-OP */ /** NO-OP */

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2008 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@@ -26,7 +26,6 @@ package org.alfresco.repo.domain.hibernate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -220,6 +219,7 @@ public abstract class AbstractPermissionsDaoComponentImpl implements Permissions
default: default:
// Force a copy on write if one is required // Force a copy on write if one is required
getACLDAO(nodeRef).forceCopy(nodeRef); getACLDAO(nodeRef).forceCopy(nodeRef);
acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
return new CreationReport(acl, Collections.<AclChange> emptyList()); return new CreationReport(acl, Collections.<AclChange> emptyList());
} }
} }