diff --git a/source/java/org/alfresco/repo/content/replication/ReplicatingContentStore.java b/source/java/org/alfresco/repo/content/replication/ReplicatingContentStore.java index 849da16858..001db78b9c 100644 --- a/source/java/org/alfresco/repo/content/replication/ReplicatingContentStore.java +++ b/source/java/org/alfresco/repo/content/replication/ReplicatingContentStore.java @@ -36,6 +36,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.content.AbstractContentStore; import org.alfresco.repo.content.ContentContext; +import org.alfresco.repo.content.ContentExistsException; import org.alfresco.repo.content.ContentStore; import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.service.cmr.repository.ContentIOException; @@ -441,8 +442,9 @@ public class ReplicatingContentStore extends AbstractContentStore { public void run() { - for (ContentStore store : stores) + for (int i = 0; i < stores.size(); i++) { + ContentStore store = stores.get(i); try { // replicate the content to the store - we know the URL that we want to write to @@ -457,22 +459,37 @@ public class ReplicatingContentStore extends AbstractContentStore if (logger.isDebugEnabled()) { logger.debug("Replicated content to store: \n" + - " url: " + contentUrl + "\n" + - " to store: " + store); + " Content: " + writer + "\n" + + " Store: " + store + "\n" + + " Number: " + i); } } catch (UnsupportedOperationException e) { throw new ContentIOException( "Unable to replicate content. The target store doesn't support replication: \n" + - " Content: " + writer.getContentUrl() + "\n" + - " To Store: " + store); + " Content: " + writer + "\n" + + " Store: " + store + "\n" + + " Number: " + i, + e); + } + catch (ContentExistsException e) + { + throw new ContentIOException( + "Content replication failed. " + + "The content URL already exists in the target (secondary) store: \n" + + " Content: " + writer + "\n" + + " Store: " + store + "\n" + + " Number: " + i); } catch (Throwable e) { - throw new ContentIOException("Content replication failed: \n" + - " url: " + writer.getContentUrl() + "\n" + - " to store: " + store); + throw new ContentIOException( + "Content replication failed: \n" + + " Content: " + writer + "\n" + + " Store: " + store + "\n" + + " Number: " + i, + e); } } } diff --git a/source/java/org/alfresco/repo/content/replication/ReplicatingContentStoreTest.java b/source/java/org/alfresco/repo/content/replication/ReplicatingContentStoreTest.java index 5e4128a9bf..4abbe7ce0e 100644 --- a/source/java/org/alfresco/repo/content/replication/ReplicatingContentStoreTest.java +++ b/source/java/org/alfresco/repo/content/replication/ReplicatingContentStoreTest.java @@ -36,6 +36,7 @@ import org.alfresco.repo.content.AbstractWritableContentStoreTest; import org.alfresco.repo.content.ContentContext; import org.alfresco.repo.content.ContentStore; import org.alfresco.repo.content.filestore.FileContentStore; +import org.alfresco.service.cmr.repository.ContentIOException; import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.util.GUID; @@ -198,4 +199,28 @@ public class ReplicatingContentStoreTest extends AbstractWritableContentStoreTes // this time, it must have been replicated to the primary store checkForReplication(true, false, contentUrl, SOME_CONTENT); } + + public void testTargetContentUrlExists() + { + replicatingStore.setOutbound(true); + replicatingStore.setInbound(false); + // pick a secondary store and write some content to it + ContentStore secondaryStore = secondaryStores.get(2); + ContentWriter secondaryWriter = secondaryStore.getWriter(ContentContext.NULL_CONTEXT); + secondaryWriter.putContent("Content for secondary"); + String secondaryContentUrl = secondaryWriter.getContentUrl(); + + // Now write to the primary store + ContentWriter replicatingWriter = replicatingStore.getWriter(new ContentContext(null, secondaryContentUrl)); + String replicatingContent = "Content for primary"; + try + { + replicatingWriter.putContent(replicatingContent); + fail("Replication should fail when the secondary store already has the content"); + } + catch (ContentIOException e) + { + // Expected + } + } }