Search in sources :

Example 1 with TransferDefinition

use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.

the class ScriptTransferService method transferReadOnly.

/**
 * Transfer a set of nodes, with no callback.
 * <p>
 * Nodes are to be locked read only on target.
 *
 * @param targetName the name of the target to transfer to
 * @param nodesToTransfer the nodes to transfer - Java Script Array of either ScriptNodes, NodeRef or String
 * @return node ref of transfer report.
 */
@SuppressWarnings("unchecked")
public ScriptNode transferReadOnly(String targetName, Object nodesToTransfer) {
    Object nodesObject = valueConverter.convertValueForJava(nodesToTransfer);
    TransferDefinition toTransfer = new TransferDefinition();
    toTransfer.setReadOnly(true);
    toTransfer.setExcludedAspects(excludedAspects);
    Collection<NodeRef> nodeCollection = new ArrayList<NodeRef>();
    if (nodesObject instanceof Collection) {
        for (Object value : (Collection) nodesObject) {
            if (value instanceof NodeRef) {
                nodeCollection.add((NodeRef) value);
            } else if (value instanceof String) {
                nodeCollection.add(new NodeRef((String) value));
            } else {
                throw new IllegalArgumentException("transfer: unknown type in collection: " + value.getClass().getName());
            }
        }
    } else if (nodesObject instanceof NodeRef) {
        nodeCollection.add((NodeRef) nodesObject);
    } else if (nodesObject instanceof String) {
        nodeCollection.add(new NodeRef((String) nodesObject));
    } else {
        throw new IllegalArgumentException("transfer: unexpected type for nodes :" + nodesObject.getClass().getName());
    }
    toTransfer.setNodes(nodeCollection);
    NodeRef reportNode = transferService.transfer(targetName, toTransfer);
    return new ScriptNode(reportNode, serviceRegistry, getScope());
}
Also used : TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ScriptNode(org.alfresco.repo.jscript.ScriptNode)

Example 2 with TransferDefinition

use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.

the class ScriptTransferService method transfer.

/**
 * Transfer a set of nodes, with no callback
 * <p>
 * Nodes are not locked on the target.
 *
 * @param targetName the name of the target to transfer to
 * @param nodesToTransfer the nodes to transfer - Java Script Array of either ScriptNodes, NodeRef or String
 * @return node ref of transfer report.
 */
@SuppressWarnings("unchecked")
public ScriptNode transfer(String targetName, Object nodesToTransfer) {
    Object nodesObject = valueConverter.convertValueForJava(nodesToTransfer);
    TransferDefinition toTransfer = new TransferDefinition();
    toTransfer.setExcludedAspects(excludedAspects);
    Collection<NodeRef> nodeCollection = new ArrayList<NodeRef>();
    if (nodesObject instanceof Collection) {
        for (Object value : (Collection) nodesObject) {
            if (value instanceof NodeRef) {
                nodeCollection.add((NodeRef) value);
            } else if (value instanceof String) {
                nodeCollection.add(new NodeRef((String) value));
            } else {
                throw new IllegalArgumentException("transfer: unknown type in collection: " + value.getClass().getName());
            }
        }
    } else if (nodesObject instanceof NodeRef) {
        nodeCollection.add((NodeRef) nodesObject);
    } else if (nodesObject instanceof String) {
        nodeCollection.add(new NodeRef((String) nodesObject));
    } else {
        throw new IllegalArgumentException("transfer: unexpected type for nodes :" + nodesObject.getClass().getName());
    }
    toTransfer.setNodes(nodeCollection);
    NodeRef reportNode = transferService.transfer(targetName, toTransfer);
    return new ScriptNode(reportNode, serviceRegistry, getScope());
}
Also used : TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ScriptNode(org.alfresco.repo.jscript.ScriptNode)

Example 3 with TransferDefinition

use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.

the class TransferAsyncAction method executeImpl.

@SuppressWarnings("unchecked")
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
    logger.debug("In TransferAsyncAction");
    String targetName = (String) action.getParameterValue("targetName");
    TransferDefinition definition = (TransferDefinition) action.getParameterValue("definition");
    Collection<TransferCallback> callback = (Collection<TransferCallback>) action.getParameterValue("callbacks");
    transferService.transfer(targetName, definition, callback);
}
Also used : TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) Collection(java.util.Collection) TransferCallback(org.alfresco.service.cmr.transfer.TransferCallback)

Example 4 with TransferDefinition

use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.

the class TransferServiceCallbackTest method testErrorDuringCommit.

public void testErrorDuringCommit() {
    Exception error = new TransferException("Commit failed");
    TransferProgress status0 = new TransferProgress();
    status0.setStatus(Status.COMMIT_REQUESTED);
    status0.setCurrentPosition(0);
    status0.setEndPosition(0);
    TransferProgress status1 = new TransferProgress();
    status1.setStatus(Status.COMMITTING);
    status1.setCurrentPosition(0);
    status1.setEndPosition(4);
    TransferProgress status2 = new TransferProgress();
    status2.setStatus(Status.COMMITTING);
    status2.setCurrentPosition(3);
    status2.setEndPosition(4);
    TransferProgress status3 = new TransferProgress();
    status3.setStatus(Status.COMMITTING);
    status3.setCurrentPosition(5);
    status3.setEndPosition(8);
    TransferProgress status4 = new TransferProgress();
    status4.setStatus(Status.ERROR);
    status4.setCurrentPosition(8);
    status4.setEndPosition(8);
    status4.setError(error);
    TransferProgress[] statuses = new TransferProgress[] { status0, status1, status2, status3, status4 };
    configureBasicMockTransmitter(statuses);
    when(mockedTransferTransmitter.begin(target, localRepositoryId, version)).thenReturn(transfer);
    TransferDefinition transferDef = new TransferDefinition();
    transferDef.setNodes(folder1, file1, file2, file3);
    try {
        transferService.transfer(TRANSFER_TARGET_NAME, transferDef, mockedCallback);
        fail();
    } catch (TransferFailureException ex) {
        List<TransferEvent> expectedEvents = new ArrayList<TransferEvent>();
        TransferEventImpl event;
        event = new TransferEventEnterState();
        event.setTransferState(TransferState.START);
        expectedEvents.add(event);
        event = new TransferEventBegin();
        event.setTransferState(TransferState.START);
        expectedEvents.add(event);
        event = new TransferEventEndState();
        event.setTransferState(TransferState.START);
        expectedEvents.add(event);
        event = new TransferEventEnterState();
        event.setTransferState(TransferState.SENDING_SNAPSHOT);
        expectedEvents.add(event);
        event = new TransferEventSendingSnapshot();
        event.setTransferState(TransferState.SENDING_SNAPSHOT);
        expectedEvents.add(event);
        event = new TransferEventEndState();
        event.setTransferState(TransferState.SENDING_SNAPSHOT);
        expectedEvents.add(event);
        event = new TransferEventEnterState();
        event.setTransferState(TransferState.SENDING_CONTENT);
        expectedEvents.add(event);
        event = new TransferEventSendingContent();
        event.setTransferState(TransferState.SENDING_CONTENT);
        expectedEvents.add(event);
        event = new TransferEventSendingContent();
        event.setTransferState(TransferState.SENDING_CONTENT);
        expectedEvents.add(event);
        event = new TransferEventSendingContent();
        event.setTransferState(TransferState.SENDING_CONTENT);
        expectedEvents.add(event);
        event = new TransferEventEndState();
        event.setTransferState(TransferState.SENDING_CONTENT);
        expectedEvents.add(event);
        event = new TransferEventEnterState();
        event.setTransferState(TransferState.PREPARING);
        expectedEvents.add(event);
        event = new TransferEventEndState();
        event.setTransferState(TransferState.PREPARING);
        expectedEvents.add(event);
        event = new TransferEventEnterState();
        event.setTransferState(TransferState.COMMITTING);
        expectedEvents.add(event);
        event = new TransferEventCommittingStatus();
        event.setTransferState(TransferState.COMMITTING);
        expectedEvents.add(event);
        event = new TransferEventCommittingStatus();
        event.setTransferState(TransferState.COMMITTING);
        expectedEvents.add(event);
        event = new TransferEventCommittingStatus();
        event.setTransferState(TransferState.COMMITTING);
        expectedEvents.add(event);
        event = new TransferEventEndState();
        event.setTransferState(TransferState.COMMITTING);
        expectedEvents.add(event);
        event = new TransferEventEnterState();
        event.setTransferState(TransferState.ERROR);
        expectedEvents.add(event);
        event = new TransferEventReport();
        event.setTransferState(TransferState.ERROR);
        expectedEvents.add(event);
        event = new TransferEventReport();
        event.setTransferState(TransferState.ERROR);
        expectedEvents.add(event);
        event = new TransferEventError();
        event.setTransferState(TransferState.ERROR);
        ((TransferEventError) event).setException(error);
        expectedEvents.add(event);
        verifyCallback(expectedEvents);
    }
}
Also used : TransferEvent(org.alfresco.service.cmr.transfer.TransferEvent) TransferEventBegin(org.alfresco.service.cmr.transfer.TransferEventBegin) TransferEventReport(org.alfresco.service.cmr.transfer.TransferEventReport) TransferFailureException(org.alfresco.service.cmr.transfer.TransferFailureException) TransferException(org.alfresco.service.cmr.transfer.TransferException) TransferEventEndState(org.alfresco.service.cmr.transfer.TransferEventEndState) TransferProgress(org.alfresco.service.cmr.transfer.TransferProgress) TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) TransferException(org.alfresco.service.cmr.transfer.TransferException) TransferEventEnterState(org.alfresco.service.cmr.transfer.TransferEventEnterState) TransferEventSendingSnapshot(org.alfresco.service.cmr.transfer.TransferEventSendingSnapshot) List(java.util.List) ArrayList(java.util.ArrayList) TransferEventCommittingStatus(org.alfresco.service.cmr.transfer.TransferEventCommittingStatus) TransferEventError(org.alfresco.service.cmr.transfer.TransferEventError) TransferFailureException(org.alfresco.service.cmr.transfer.TransferFailureException) TransferEventSendingContent(org.alfresco.service.cmr.transfer.TransferEventSendingContent)

Example 5 with TransferDefinition

use of org.alfresco.service.cmr.transfer.TransferDefinition in project alfresco-repository by Alfresco.

the class TransferServiceCallbackTest method testSendContentFailed.

public void testSendContentFailed() {
    TransferProgress status0 = new TransferProgress();
    status0.setStatus(Status.CANCELLED);
    status0.setCurrentPosition(0);
    status0.setEndPosition(0);
    TransferProgress[] statuses = new TransferProgress[] { status0 };
    configureBasicMockTransmitter(statuses);
    when(mockedTransferTransmitter.begin(target, localRepositoryId, version)).thenReturn(transfer);
    doThrow(new TransferException("Simulate failure to write content")).when(mockedTransferTransmitter).sendManifest(any(Transfer.class), any(File.class), any(OutputStream.class));
    when(mockedTransferTransmitter.getStatus(transfer)).thenReturn(statuses[0]);
    TransferDefinition transferDef = new TransferDefinition();
    transferDef.setNodes(folder1, file1, file2, file3);
    try {
        transferService.transfer(TRANSFER_TARGET_NAME, transferDef, mockedCallback);
        fail("Transfer expected to throw an exception, but it didn't.");
    } catch (TransferFailureException ex) {
        List<TransferEvent> expectedEvents = new ArrayList<TransferEvent>();
        TransferEventImpl event;
        event = new TransferEventEnterState();
        event.setTransferState(TransferState.START);
        expectedEvents.add(event);
        event = new TransferEventBegin();
        event.setTransferState(TransferState.START);
        expectedEvents.add(event);
        event = new TransferEventEndState();
        event.setTransferState(TransferState.START);
        expectedEvents.add(event);
        event = new TransferEventEnterState();
        event.setTransferState(TransferState.SENDING_SNAPSHOT);
        expectedEvents.add(event);
        event = new TransferEventSendingSnapshot();
        event.setTransferState(TransferState.SENDING_SNAPSHOT);
        expectedEvents.add(event);
        event = new TransferEventEndState();
        event.setTransferState(TransferState.SENDING_SNAPSHOT);
        expectedEvents.add(event);
        event = new TransferEventEnterState();
        event.setTransferState(TransferState.ERROR);
        expectedEvents.add(event);
        event = new TransferEventReport();
        event.setTransferState(TransferState.ERROR);
        expectedEvents.add(event);
        event = new TransferEventReport();
        event.setTransferState(TransferState.ERROR);
        expectedEvents.add(event);
        event = new TransferEventError();
        event.setTransferState(TransferState.ERROR);
        ((TransferEventError) event).setException((Exception) ex.getCause());
        expectedEvents.add(event);
        verifyCallback(expectedEvents);
    }
}
Also used : OutputStream(java.io.OutputStream) TransferEvent(org.alfresco.service.cmr.transfer.TransferEvent) TransferEventBegin(org.alfresco.service.cmr.transfer.TransferEventBegin) TransferEventReport(org.alfresco.service.cmr.transfer.TransferEventReport) TransferEventEndState(org.alfresco.service.cmr.transfer.TransferEventEndState) TransferFailureException(org.alfresco.service.cmr.transfer.TransferFailureException) TransferException(org.alfresco.service.cmr.transfer.TransferException) TransferProgress(org.alfresco.service.cmr.transfer.TransferProgress) TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) TransferException(org.alfresco.service.cmr.transfer.TransferException) TransferEventEnterState(org.alfresco.service.cmr.transfer.TransferEventEnterState) TransferEventSendingSnapshot(org.alfresco.service.cmr.transfer.TransferEventSendingSnapshot) List(java.util.List) ArrayList(java.util.ArrayList) TransferEventError(org.alfresco.service.cmr.transfer.TransferEventError) File(java.io.File) TransferFailureException(org.alfresco.service.cmr.transfer.TransferFailureException)

Aggregations

TransferDefinition (org.alfresco.service.cmr.transfer.TransferDefinition)38 NodeRef (org.alfresco.service.cmr.repository.NodeRef)31 TransferTarget (org.alfresco.service.cmr.transfer.TransferTarget)25 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)24 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)24 Test (org.junit.Test)24 HashSet (java.util.HashSet)21 Locale (java.util.Locale)19 DescriptorService (org.alfresco.service.descriptor.DescriptorService)18 ArrayList (java.util.ArrayList)17 Pair (org.alfresco.util.Pair)16 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)14 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)13 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)11 List (java.util.List)10 Path (org.alfresco.service.cmr.repository.Path)10 TransferEvent (org.alfresco.service.cmr.transfer.TransferEvent)8 Collection (java.util.Collection)7 QName (org.alfresco.service.namespace.QName)7 ContentReader (org.alfresco.service.cmr.repository.ContentReader)5