diff --git a/source/java/org/alfresco/repo/transfer/AbstractTransferProgressMonitor.java b/source/java/org/alfresco/repo/transfer/AbstractTransferProgressMonitor.java
new file mode 100644
index 0000000000..036e1bfb0a
--- /dev/null
+++ b/source/java/org/alfresco/repo/transfer/AbstractTransferProgressMonitor.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (C) 2009-2010 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+
+package org.alfresco.repo.transfer;
+
+import java.io.Writer;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.alfresco.repo.transaction.RetryingTransactionHelper;
+import org.alfresco.repo.transfer.reportd.XMLTransferDestinationReportWriter;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.repository.Path;
+import org.alfresco.service.cmr.transfer.TransferException;
+import org.alfresco.service.cmr.transfer.TransferProgress;
+import org.alfresco.service.cmr.transfer.TransferProgress.Status;
+import org.alfresco.service.transaction.TransactionService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author brian
+ *
+ */
+public abstract class AbstractTransferProgressMonitor implements TransferProgressMonitor
+{
+ private static final Log log = LogFactory.getLog(AbstractTransferProgressMonitor.class);
+
+ protected static final String MSG_TRANSFER_NOT_FOUND = "transfer_service.receiver.transfer_not_found";
+ protected static final String MSG_TRANSFER_CANCELLED = "transfer_service.receiver.transfer_cancelled";
+
+ private Map transferLogWriters = new TreeMap();
+ private TransactionService transactionService;
+
+ public void setTransactionService(TransactionService transactionService)
+ {
+ this.transactionService = transactionService;
+ }
+
+
+
+ @Override
+ public TransferProgress getProgress(final String transferId) throws TransferException
+ {
+ return transactionService.getRetryingTransactionHelper().doInTransaction(
+ new RetryingTransactionHelper.RetryingTransactionCallback()
+ {
+ public TransferProgress execute() throws Throwable
+ {
+ return getProgressInternal(transferId);
+ }
+ }, false, true);
+ }
+
+ protected abstract TransferProgress getProgressInternal(String transferId);
+
+ @Override
+ public void updateProgress(final String transferId, final int currPos, final int endPos) throws TransferException
+ {
+ transactionService.getRetryingTransactionHelper().doInTransaction(
+ new RetryingTransactionHelper.RetryingTransactionCallback()
+ {
+ public Void execute() throws Throwable
+ {
+ updateProgressInternal(transferId, currPos, endPos);
+ return null;
+ }
+ }, false, true);
+ }
+
+
+ protected abstract void updateProgressInternal(String transferId, int currPos, int endPos);
+
+
+ @Override
+ public void updateProgress(final String transferId, final int currPos) throws TransferException
+ {
+ transactionService.getRetryingTransactionHelper().doInTransaction(
+ new RetryingTransactionHelper.RetryingTransactionCallback()
+ {
+ public Void execute() throws Throwable
+ {
+ updateProgressInternal(transferId, currPos);
+ return null;
+ }
+ }, false, true);
+ }
+
+ protected abstract void updateProgressInternal(String transferId, int currPos);
+
+ @Override
+ public final void updateStatus(final String transferId, final Status status) throws TransferException
+ {
+ Status currentStatus = getProgress(transferId).getStatus();
+
+ //If the transfer has already reached a terminal state then we don't allow any further change
+ if (!TransferProgress.getTerminalStatuses().contains(currentStatus))
+ {
+ transactionService.getRetryingTransactionHelper().doInTransaction(
+ new RetryingTransactionHelper.RetryingTransactionCallback()
+ {
+ public Void execute() throws Throwable
+ {
+ TransferDestinationReportWriter writer = getLogWriter(transferId);
+ writer.writeChangeState(status.toString());
+ updateStatusInternal(transferId, status);
+ //If the transfer has now reached a terminal state then the make sure that the log channel is
+ //closed for it (if one was open).
+ if (TransferProgress.getTerminalStatuses().contains(status))
+ {
+ log.debug("closing destination transfer report");
+ writer.endTransferReport();
+ transferLogWriters.remove(transferId);
+ }
+ return null;
+ }
+ }, false, true);
+ }
+ }
+
+ protected abstract void updateStatusInternal(String transferId, Status status);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.alfresco.repo.transfer.TransferProgressMonitor#log(java.lang.String, java.lang.Object)
+ */
+ public void logComment(final String transferId, final Object obj)
+ {
+ TransferDestinationReportWriter writer = getLogWriter(transferId);
+ writer.writeComment(obj.toString());
+ }
+
+ public void logException(final String transferId, final Object obj, final Throwable ex)
+ {
+ TransferDestinationReportWriter writer = getLogWriter(transferId);
+ writer.writeComment(obj.toString());
+ if (ex != null)
+ {
+ transactionService.getRetryingTransactionHelper().doInTransaction(
+ new RetryingTransactionHelper.RetryingTransactionCallback()
+ {
+ public Void execute() throws Throwable
+ {
+ storeError(transferId, ex);
+ return null;
+ }
+ }, false, true);
+ writer.writeException(ex);
+ }
+ }
+
+ protected abstract void storeError(String transferId, Throwable error);
+
+ @Override
+ public void logCreated(String transferId,
+ NodeRef sourceNode,
+ NodeRef destNode,
+ NodeRef parentNodeRef,
+ Path parentPath,
+ boolean orphan)
+ {
+ TransferDestinationReportWriter writer = getLogWriter(transferId);
+ writer.writeCreated(sourceNode, destNode, parentNodeRef, parentPath);
+ }
+
+ @Override
+ public void logUpdated(String transferId, NodeRef sourceNodeRef,
+ NodeRef destNodeRef, Path path)
+ {
+ TransferDestinationReportWriter writer = getLogWriter(transferId);
+ writer.writeUpdated(sourceNodeRef, destNodeRef, path);
+ }
+
+ @Override
+ public void logMoved(String transferId, NodeRef sourceNodeRef,
+ NodeRef destNodeRef, Path oldPath, NodeRef newParentNodeRef, Path newPath)
+ {
+ TransferDestinationReportWriter writer = getLogWriter(transferId);
+ writer.writeMoved(sourceNodeRef, destNodeRef, oldPath, newParentNodeRef, newPath);
+ }
+
+ @Override
+ public void logDeleted(String transferId,
+ NodeRef sourceNodeRef,
+ NodeRef destNodeRef,
+ Path oldPath)
+ {
+ TransferDestinationReportWriter writer = getLogWriter(transferId);
+ writer.writeDeleted(sourceNodeRef, destNodeRef, oldPath);
+ }
+
+ private TransferDestinationReportWriter getLogWriter(String transferId)
+ {
+ TransferDestinationReportWriter writer = this.transferLogWriters.get(transferId);
+ if (writer == null)
+ {
+ writer = new XMLTransferDestinationReportWriter();
+ writer.startTransferReport("UTF-8", createUnderlyingLogWriter(transferId));
+ transferLogWriters.put(transferId, writer);
+ }
+ return writer;
+ }
+
+ protected abstract Writer createUnderlyingLogWriter(String transferId);
+}
diff --git a/source/java/org/alfresco/repo/transfer/RepoTransferProgressMonitorImpl.java b/source/java/org/alfresco/repo/transfer/RepoTransferProgressMonitorImpl.java
index e50b440469..eb08487c7d 100644
--- a/source/java/org/alfresco/repo/transfer/RepoTransferProgressMonitorImpl.java
+++ b/source/java/org/alfresco/repo/transfer/RepoTransferProgressMonitorImpl.java
@@ -1,183 +1,86 @@
/*
- * Copyright (C) 2009-2010 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
+ * Copyright (C) 2009-2010 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see .
*/
package org.alfresco.repo.transfer;
import java.io.InputStream;
+import java.io.Writer;
import java.nio.channels.Channels;
-import java.util.Map;
-import java.util.TreeMap;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
-import org.alfresco.repo.transaction.RetryingTransactionHelper;
-import org.alfresco.repo.transfer.reportd.XMLTransferDestinationReportWriter;
-import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.transfer.TransferException;
import org.alfresco.service.cmr.transfer.TransferProgress;
import org.alfresco.service.cmr.transfer.TransferProgress.Status;
-import org.alfresco.service.transaction.TransactionService;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* @author brian
*
*/
-public class RepoTransferProgressMonitorImpl implements TransferProgressMonitor
+public class RepoTransferProgressMonitorImpl extends AbstractTransferProgressMonitor
{
- private static final Log log = LogFactory.getLog(RepoTransferProgressMonitorImpl.class);
-
- private static final String MSG_TRANSFER_NOT_FOUND = "transfer_service.receiver.transfer_not_found";
- private static final String MSG_TRANSFER_CANCELLED = "transfer_service.receiver.transfer_cancelled";
-
private NodeService nodeService;
private ContentService contentService;
- private TransactionService transactionService;
- //private Map transferLogWriters = new TreeMap();
- private Map transferLogWriters = new TreeMap();
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.transfer.TransferProgressMonitor#getProgress(java.lang.String)
*/
- public TransferProgress getProgress(final String transferId)
+ public TransferProgress getProgressInternal(final String transferId)
{
- return transactionService.getRetryingTransactionHelper().doInTransaction(
- new RetryingTransactionHelper.RetryingTransactionCallback()
- {
- public TransferProgress execute() throws Throwable
- {
- NodeRef nodeRef = getTransferRecord(transferId);
+ NodeRef nodeRef = getTransferRecord(transferId);
- TransferProgress progress = new TransferProgress();
- progress.setStatus(TransferProgress.Status.valueOf((String) nodeService.getProperty(nodeRef,
- TransferModel.PROP_TRANSFER_STATUS)));
- progress.setCurrentPosition((Integer) nodeService.getProperty(nodeRef,
- TransferModel.PROP_PROGRESS_POSITION));
- progress.setEndPosition((Integer) nodeService.getProperty(nodeRef,
- TransferModel.PROP_PROGRESS_ENDPOINT));
- progress.setError((Throwable) nodeService.getProperty(nodeRef,
- TransferModel.PROP_TRANSFER_ERROR));
- return progress;
- }
- }, false, true);
+ TransferProgress progress = new TransferProgress();
+ progress.setStatus(TransferProgress.Status.valueOf((String) nodeService.getProperty(nodeRef,
+ TransferModel.PROP_TRANSFER_STATUS)));
+ progress.setCurrentPosition((Integer) nodeService.getProperty(nodeRef,
+ TransferModel.PROP_PROGRESS_POSITION));
+ progress.setEndPosition((Integer) nodeService.getProperty(nodeRef,
+ TransferModel.PROP_PROGRESS_ENDPOINT));
+ progress.setError((Throwable) nodeService.getProperty(nodeRef,
+ TransferModel.PROP_TRANSFER_ERROR));
+ return progress;
}
- /*
- * (non-Javadoc)
- *
- * @see org.alfresco.repo.transfer.TransferProgressMonitor#log(java.lang.String, java.lang.Object)
- */
- public void logComment(final String transferId, final Object obj)
+ public void storeError(final String transferId, final Throwable ex)
{
- TransferDestinationReportWriter writer = getLogWriter(transferId);
- writer.writeComment(obj.toString());
- }
-
- public void logException(final String transferId, final Object obj, final Throwable ex)
- {
- transactionService.getRetryingTransactionHelper().doInTransaction(
- new RetryingTransactionHelper.RetryingTransactionCallback