use of org.alfresco.repo.action.ActionCancelledException in project alfresco-repository by Alfresco.
the class ReplicationActionExecutor method executeImpl.
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
if (action instanceof ReplicationDefinition) {
// Already of the correct type
} else if (action.getActionDefinitionName().equals(ReplicationDefinitionImpl.EXECUTOR_NAME)) {
// Specialise the action if needed, eg when loaded directly from
// the NodeRef without going via the replication service
action = new ReplicationDefinitionImpl(action);
}
// Off we go
final ReplicationDefinition replicationDef = (ReplicationDefinition) action;
if (replicationDef.getTargetName() == null || replicationDef.getTargetName().equals("")) {
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_TARGET_NOT_GIVEN));
}
if (replicationDef.getPayload().size() == 0) {
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_NO_PAYLOADS_SPECIFIED));
}
if (!replicationDef.isEnabled()) {
throw new DisabledReplicationJobException(I18NUtil.getMessage(MSG_ERR_REPLICATION_DEF_DISABLED));
}
if (!replicationParams.isEnabled()) {
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_UNABLE_TO_REPLICATE));
}
// Lock the service - only one instance of the replication
// should occur at a time
ReplicationDefinitionLockExtender lock = new ReplicationDefinitionLockExtender(replicationDef);
// Turn our payload list of root nodes into something that
// the transfer service can work with
Set<NodeRef> toTransfer;
try {
toTransfer = expandPayload(replicationDef);
} catch (Exception e) {
lock.close();
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_PROCESSING_PAYLOAD, e.getMessage()), e);
}
// Ask the transfer service to do the replication
// work for us
TransferEndEvent endEvent = null;
try {
// Build the definition
TransferDefinition transferDefinition = buildTransferDefinition(replicationDef, toTransfer);
// Off we go
endEvent = transferService.transfer(replicationDef.getTargetName(), transferDefinition, lock);
if (endEvent instanceof TransferEventCancelled) {
if (logger.isDebugEnabled())
logger.debug("Cancelling replication job");
// that this is correctly recorded
throw new ActionCancelledException(replicationDef);
}
// Record details of the transfer reports (in success case)
replicationDef.setLocalTransferReport(endEvent.getSourceReport());
replicationDef.setRemoteTransferReport(endEvent.getDestinationReport());
replicationDefinitionPersister.saveReplicationDefinition(replicationDef);
} catch (Exception e) {
if (e instanceof ActionCancelledException) {
writeDefinitionReports(replicationDef, endEvent.getSourceReport(), endEvent.getDestinationReport());
throw (ActionCancelledException) e;
}
if (e instanceof TransferFailureException) {
TransferEventError failureEndEvent = ((TransferFailureException) e).getErrorEvent();
writeDefinitionReports(replicationDef, failureEndEvent.getSourceReport(), failureEndEvent.getDestinationReport());
Throwable cause = (e.getCause() == null) ? e : e.getCause();
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_EXECUTING_TRANSFER, cause.getMessage()), cause);
}
writeDefinitionReports(replicationDef, null, null);
throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_EXECUTING_TRANSFER, e.getMessage()), e);
} finally {
lock.close();
}
}
Aggregations