From a06fc74aef0ad8c58590b5ca6c54b3244a204b6d Mon Sep 17 00:00:00 2001 From: Britt Park Date: Wed, 13 Sep 2006 05:45:24 +0000 Subject: [PATCH] The outside hooks for AVMSyncService are in place and the implementation of the simplest method, resetLayer is done. Also fixed goofy merge induced bug in DbNodeServiceImpl. Can we make merging a punishment for naughty Alfrescans? git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3778 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/public-services-context.xml | 76 ++++++++--- .../org/alfresco/repo/avm/AVMInterpreter.java | 4 - .../org/alfresco/repo/avm/AVMServiceTest.java | 25 ++++ .../alfresco/repo/avm/AVMServiceTestBase.java | 6 + .../alfresco/repo/avm/AVMSyncServiceImpl.java | 121 ++++++++++++++++++ .../repo/node/db/DbNodeServiceImpl.java | 6 - .../service/ServiceDescriptorRegistry.java | 10 ++ .../org/alfresco/service/ServiceRegistry.java | 9 ++ .../service/cmr/avmsync/AVMDifference.java | 97 +++++++++++++- ...vmSyncService.java => AVMSyncService.java} | 2 +- 10 files changed, 329 insertions(+), 27 deletions(-) create mode 100644 source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java rename source/java/org/alfresco/service/cmr/avmsync/{AvmSyncService.java => AVMSyncService.java} (98%) diff --git a/config/alfresco/public-services-context.xml b/config/alfresco/public-services-context.xml index 4b5432d7fc..6427584fa1 100644 --- a/config/alfresco/public-services-context.xml +++ b/config/alfresco/public-services-context.xml @@ -1012,21 +1012,21 @@ - - - org.alfresco.service.cmr.avm.AVMService - - - - - - - - - - - - + + + org.alfresco.service.cmr.avm.AVMService + + + + + + + + + + + + org.alfresco.service.cmr.avm.AVMService @@ -1052,6 +1052,52 @@ + + + + + + + + + + + org.alfresco.service.cmr.avmsync.AVMSyncService + + + AVM Tree Synchronization Service + + + + + + + + + + ${server.transaction.mode.readOnly} + ${server.transaction.mode.default} + ${server.transaction.mode.default} + ${server.transaction.mode.default} + + + + + + + org.alfresco.service.cmr.avmsync.AVMSyncService + + + + + + + + + + + + diff --git a/source/java/org/alfresco/repo/avm/AVMInterpreter.java b/source/java/org/alfresco/repo/avm/AVMInterpreter.java index 6adc908307..dc4fd62480 100644 --- a/source/java/org/alfresco/repo/avm/AVMInterpreter.java +++ b/source/java/org/alfresco/repo/avm/AVMInterpreter.java @@ -34,9 +34,7 @@ import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.avm.AVMStoreDescriptor; import org.alfresco.service.cmr.avm.VersionDescriptor; -import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.namespace.QName; -import org.apache.log4j.Logger; import org.springframework.context.support.FileSystemXmlApplicationContext; /** @@ -45,8 +43,6 @@ import org.springframework.context.support.FileSystemXmlApplicationContext; */ public class AVMInterpreter { - private static Logger fgLogger = Logger.getLogger(AVMInterpreter.class); - /** * The service interface. */ diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index b84ecd32f7..ea1a1fa5d9 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -2516,4 +2516,29 @@ public class AVMServiceTest extends AVMServiceTestBase fail(); } } + + /** + * Test AVMSyncService resetLayer. + */ + public void testResetLayer() + { + try + { + setupBasicTree(); + fService.createLayeredDirectory("main:/a", "main:/", "layer"); + fService.createFile("main:/layer", "figs").close(); + assertFalse(recursiveContents("main:/a", -1, true).equals( + recursiveContents("main:/layer", -1, true))); + System.out.println(recursiveList("main", -1, true)); + fSyncService.resetLayer("main:/layer"); + assertEquals(recursiveContents("main:/a", -1, true), + recursiveContents("main:/layer", -1, true)); + System.out.println(recursiveList("main", -1, true)); + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } } diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTestBase.java b/source/java/org/alfresco/repo/avm/AVMServiceTestBase.java index 6aa6c56fc4..dc3098e0d0 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTestBase.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTestBase.java @@ -27,6 +27,7 @@ import java.util.TreeMap; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.avm.AVMStoreDescriptor; +import org.alfresco.service.cmr.avmsync.AVMSyncService; import org.springframework.context.support.FileSystemXmlApplicationContext; import junit.framework.TestCase; @@ -47,6 +48,10 @@ public class AVMServiceTestBase extends TestCase */ protected static OrphanReaper fReaper; + /** + * The AVMSyncService. + */ + protected static AVMSyncService fSyncService; /** * The application context. */ @@ -70,6 +75,7 @@ public class AVMServiceTestBase extends TestCase fContext = new FileSystemXmlApplicationContext("config/alfresco/avm-test-context.xml"); fService = (AVMService)fContext.getBean("AVMService"); fReaper = (OrphanReaper)fContext.getBean("orphanReaper"); + fSyncService = (AVMSyncService)fContext.getBean("AVMSyncService"); } fService.createAVMStore("main"); fStartTime = System.currentTimeMillis(); diff --git a/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java new file mode 100644 index 0000000000..92811b552a --- /dev/null +++ b/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2006 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ + +package org.alfresco.repo.avm; + +import java.util.List; + +import org.alfresco.service.cmr.avm.AVMNodeDescriptor; +import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.avmsync.AVMDifference; +import org.alfresco.service.cmr.avmsync.AVMSyncService; + +/** + * This implements APIs that allow comparison and synchronization + * of node trees as well as cumulative operations on layers to + * support various content production models. + * @author britt + */ +public class AVMSyncServiceImpl implements AVMSyncService +{ + /** + * The AVMService. + */ + private AVMService fAVMService; + + /** + * Do nothing constructor. + */ + public AVMSyncServiceImpl() + { + } + + /** + * Set the AVM Service. For Spring. For now, at least, + * it's important to wire this using the unintercepted AVMServiceImpl, + * as AVMServiceImpl uses Runtime Exceptions for handling valid states + * that should not cause rollbacks. + * @param avmService The AVMService reference. + */ + public void setAvmService(AVMService avmService) + { + fAVMService = avmService; + } + + /** + * Get a difference list between two corresponding node trees. + * @param srcVersion The version id for the source tree. + * @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. + * @return A List of AVMDifference structs which can be used for + * the update operation. + */ + public List compare(int srcVersion, String srcPath, + int dstVersion, String dstPath) + { + // TODO Implement. + return null; + } + + /** + * Updates the destination nodes in the AVMDifferences + * with the source nodes. Normally any conflicts or cases in + * 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 ignoreConflicts If this is true the update will skip those + * AVMDifferences which are in conflict or for which the source is older than + * the destination. + * @param overrideConflicts If this is true the update will override conflicting + * AVMDifferences and replace the destination with the conflicting source. + * @param overrideOlder If this is true the update will override AVMDifferences + * in which the source is older than the destination and overwrite the destination. + */ + public void update(List diffList, boolean ignoreConflicts, + boolean overrideConflicts, boolean overrideOlder) + { + // TODO Implement. + } + + /** + * Flattens a layer so that all all nodes under and including + * layerPath become translucent to any nodes in the + * corresponding location under and including underlyingPath + * that are the same version. + * @param layerPath The overlying layer path. + * @param underlyingPath The underlying path. + */ + public void flatten(String layerPath, String underlyingPath) + { + // TODO Implement. + } + + /** + * Takes a layer, deletes it and recreates it pointing at the same underlying + * node. Any changes in the layer are lost (except to history if the layer has been + * snapshotted.) + * @param layerPath + */ + public void resetLayer(String layerPath) + { + AVMNodeDescriptor desc = fAVMService.lookup(-1, layerPath); + String [] parts = AVMNodeConverter.SplitBase(layerPath); + fAVMService.removeNode(parts[0], parts[1]); + fAVMService.createLayeredDirectory(desc.getIndirection(), parts[0], parts[1]); + } +} diff --git a/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java b/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java index de3710f9ae..9d4d3abd81 100644 --- a/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java +++ b/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java @@ -83,7 +83,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl private static Log logger = LogFactory.getLog(DbNodeServiceImpl.class); private static Log loggerPaths = LogFactory.getLog(DbNodeServiceImpl.class.getName() + ".paths"); - private DictionaryService dictionaryService; private NodeDaoService nodeDaoService; private StoreArchiveMap storeArchiveMap; private NodeService avmNodeService; @@ -93,11 +92,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl storeArchiveMap = new StoreArchiveMap(); // in case it is not set } - public void setDictionaryService(DictionaryService dictionaryService) - { - this.dictionaryService = dictionaryService; - } - public void setNodeDaoService(NodeDaoService nodeDaoService) { this.nodeDaoService = nodeDaoService; diff --git a/source/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java b/source/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java index 2b79b96556..c5f4e42070 100644 --- a/source/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java +++ b/source/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java @@ -27,6 +27,7 @@ import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.audit.AuditService; import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.avmsync.AVMSyncService; import org.alfresco.service.cmr.coci.CheckOutCheckInService; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.lock.LockService; @@ -341,4 +342,13 @@ public class ServiceDescriptorRegistry { return (AVMService)getService(AVM_SERVICE); } + + /** + * Get the AVM Sync Service. + * @return The AVM Sync Service. + */ + public AVMSyncService getAVMSyncService() + { + return (AVMSyncService)getService(AVM_SYNC_SERVICE); + } } diff --git a/source/java/org/alfresco/service/ServiceRegistry.java b/source/java/org/alfresco/service/ServiceRegistry.java index c363684352..eaa0796af9 100644 --- a/source/java/org/alfresco/service/ServiceRegistry.java +++ b/source/java/org/alfresco/service/ServiceRegistry.java @@ -21,6 +21,7 @@ import java.util.Collection; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.audit.AuditService; import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.avmsync.AVMSyncService; import org.alfresco.service.cmr.coci.CheckOutCheckInService; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.lock.LockService; @@ -88,6 +89,7 @@ public interface ServiceRegistry static final QName WORKFLOW_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "WorkflowService"); static final QName AUDIT_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AuditService"); static final QName AVM_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AVMService"); + static final QName AVM_SYNC_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AVMSyncService"); /** * Get the list of services provided by the Repository @@ -280,4 +282,11 @@ public interface ServiceRegistry */ @NotAuditable AVMService getAVMService(); + + /** + * Get the AVM Sync Service. + * @return The AVM Sync Service. + */ + @NotAuditable + AVMSyncService getAVMSyncService(); } diff --git a/source/java/org/alfresco/service/cmr/avmsync/AVMDifference.java b/source/java/org/alfresco/service/cmr/avmsync/AVMDifference.java index 2e3acf20e1..ffc1168fe3 100644 --- a/source/java/org/alfresco/service/cmr/avmsync/AVMDifference.java +++ b/source/java/org/alfresco/service/cmr/avmsync/AVMDifference.java @@ -17,12 +17,107 @@ package org.alfresco.service.cmr.avmsync; +import java.io.Serializable; + /** * Represents the difference between corresponding nodes * in parallel avm node trees. It it indicates for the difference * whether the source is older, newer, or in conflict with the destination. * @author britt */ -public class AVMDifference +public class AVMDifference implements Serializable { + private static final long serialVersionUID = -589722861571724954L; + + public static final int NEWER = 0; + public static final int OLDER = 1; + public static final int CONFLICT = 2; + + /** + * Version number of the source node. + */ + private int fSourceVersion; + + /** + * Path of the source node. + */ + private String fSourcePath; + + /** + * Version number of the destination node. + */ + private int fDestVersion; + + /** + * Path of the destination node. + */ + private String fDestPath; + + /** + * The difference code. + */ + private int fDiffCode; + + /** + * Make one up. + * @param srcVersion The source version. + * @param srcPath the source path. + * @param dstVersion The destination version. + * @param dstPath The destination path. + * @param diffCode The difference code, NEWER, OLDER, CONFLICT + */ + public AVMDifference(int srcVersion, String srcPath, + int dstVersion, String dstPath, int diffCode) + { + fSourceVersion = srcVersion; + fSourcePath = srcPath; + fDestVersion = dstVersion; + fDestPath = dstPath; + fDiffCode = diffCode; + } + + /** + * Get the source version number. + * @return The source version number. + */ + public int getSourceVersion() + { + return fSourceVersion; + } + + /** + * Get the source path. + * @return The source path. + */ + public String getSourcePath() + { + return fSourcePath; + } + + /** + * Get the destination version number. + * @return The destination version number. + */ + public int getDestinationVersion() + { + return fDestVersion; + } + + /** + * Get the destination path. + * @return The destination path. + */ + public String getDestinationPath() + { + return fDestPath; + } + + /** + * Get the difference code, NEWER, OLDER, CONFLICT. + * @return The difference code. + */ + public int getDifferenceCode() + { + return fDiffCode; + } } diff --git a/source/java/org/alfresco/service/cmr/avmsync/AvmSyncService.java b/source/java/org/alfresco/service/cmr/avmsync/AVMSyncService.java similarity index 98% rename from source/java/org/alfresco/service/cmr/avmsync/AvmSyncService.java rename to source/java/org/alfresco/service/cmr/avmsync/AVMSyncService.java index 0f91cc96ea..3e9f7c39d9 100644 --- a/source/java/org/alfresco/service/cmr/avmsync/AvmSyncService.java +++ b/source/java/org/alfresco/service/cmr/avmsync/AVMSyncService.java @@ -24,7 +24,7 @@ import java.util.List; * corresponding avm node trees. * @author britt */ -public interface AvmSyncService +public interface AVMSyncService { /** * Get a difference list between two corresponding node trees.