commitProcessors = manifestProcessorFactory.getCommitProcessors(
RepoTransferReceiverImpl.this, transferId);
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser parser = saxParserFactory.newSAXParser();
File snapshotFile = getSnapshotFile(transferId);
if (snapshotFile.exists())
{
if (log.isDebugEnabled())
{
log.debug("Processing manifest file:" + snapshotFile.getAbsolutePath());
}
// We parse the file as many times as we have processors
for (TransferManifestProcessor processor : commitProcessors)
{
XMLTransferManifestReader reader = new XMLTransferManifestReader(processor);
//behaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
behaviourFilter.disableAllBehaviours();
try
{
parser.parse(snapshotFile, reader);
}
finally
{
// behaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE);
behaviourFilter.enableAllBehaviours();
}
nudgeLock(transferId);
parser.reset();
}
}
else
{
progressMonitor.log(transferId, "Unable to start commit. No snapshot file received",
new TransferException(MSG_NO_SNAPSHOT_RECEIVED, new Object[]{transferId}));
}
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(commitWork, false, true);
Throwable error = progressMonitor.getProgress(transferId).getError();
if (error != null)
{
if (TransferException.class.isAssignableFrom(error.getClass()))
{
throw (TransferException) error;
}
else
{
throw new TransferException(MSG_ERROR_WHILE_COMMITTING_TRANSFER, new Object[]{transferId}, error);
}
}
/**
* Successfully committed
*/
if (log.isDebugEnabled())
{
log.debug("Commit success transferId=" + transferId);
}
}
catch (Exception ex)
{
if (TransferException.class.isAssignableFrom(ex.getClass()))
{
throw (TransferException) ex;
}
else
{
throw new TransferException(MSG_ERROR_WHILE_COMMITTING_TRANSFER, ex);
}
}
finally
{
if(rulesEnabled)
{
/**
* Turn rules back on if we turned them off earlier.
*/
ruleService.enableRules();
}
/**
* Clean up at the end of the transfer
*/
try
{
end(transferId);
}
catch (Exception ex)
{
log.error("Failed to clean up transfer. Lock may still be in place: " + transferId);
}
}
}
public TransferProgress getStatus(String transferId) throws TransferException
{
return getProgressMonitor().getProgress(transferId);
}
private File getSnapshotFile(String transferId)
{
return new File(getStagingFolder(transferId), SNAPSHOT_FILE_NAME);
}
/**
* @param searchService
* the searchService to set
*/
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
/**
* @param transactionService
* the transactionService to set
*/
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* @param transferLockFolderPath
* the transferLockFolderPath to set
*/
public void setTransferLockFolderPath(String transferLockFolderPath)
{
this.transferLockFolderPath = transferLockFolderPath;
}
/**
* @param transferTempFolderPath
* the transferTempFolderPath to set
*/
public void setTransferTempFolderPath(String transferTempFolderPath)
{
this.transferTempFolderPath = transferTempFolderPath;
}
/**
* @param rootStagingDirectory
* the rootTransferFolder to set
*/
public void setRootStagingDirectory(String rootStagingDirectory)
{
this.rootStagingDirectory = rootStagingDirectory;
}
/**
* @param inboundTransferRecordsPath
* the inboundTransferRecordsPath to set
*/
public void setInboundTransferRecordsPath(String inboundTransferRecordsPath)
{
this.inboundTransferRecordsPath = inboundTransferRecordsPath;
}
/**
* @param nodeService
* the nodeService to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param manifestProcessorFactory
* the manifestProcessorFactory to set
*/
public void setManifestProcessorFactory(ManifestProcessorFactory manifestProcessorFactory)
{
this.manifestProcessorFactory = manifestProcessorFactory;
}
/**
* @param behaviourFilter
* the behaviourFilter to set
*/
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
{
this.behaviourFilter = behaviourFilter;
}
/**
* @return the progressMonitor
*/
public TransferProgressMonitor getProgressMonitor()
{
return progressMonitor;
}
/**
* @param progressMonitor
* the progressMonitor to set
*/
public void setProgressMonitor(TransferProgressMonitor progressMonitor)
{
this.progressMonitor = progressMonitor;
}
public void setActionService(ActionService actionService)
{
this.actionService = actionService;
}
/**
* Set the ruleService
* @param ruleService
* the ruleService to set
*/
public void setRuleService(RuleService ruleService)
{
this.ruleService = ruleService;
}
/**
* Get the rule service
* @return the rule service
*/
public RuleService getRuleService()
{
return this.ruleService;
}
/**
* Generate the requsite
*/
public void generateRequsite(String transferId, OutputStream out) throws TransferException
{
log.debug("Generate Requsite for transfer:" + transferId);
try
{
File snapshotFile = getSnapshotFile(transferId);
if (snapshotFile.exists())
{
log.debug("snapshot does exist");
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser parser = saxParserFactory.newSAXParser();
OutputStreamWriter dest = new OutputStreamWriter(out, "UTF-8");
XMLTransferRequsiteWriter writer = new XMLTransferRequsiteWriter(dest);
TransferManifestProcessor processor = manifestProcessorFactory.getRequsiteProcessor(
RepoTransferReceiverImpl.this,
transferId,
writer);
XMLTransferManifestReader reader = new XMLTransferManifestReader(processor);
/**
* Now run the parser
*/
parser.parse(snapshotFile, reader);
/**
* And flush the destination in case any content remains in the writer.
*/
dest.flush();
}
log.debug("Generate Requsite done transfer:" + transferId);
}
catch (Exception ex)
{
if (TransferException.class.isAssignableFrom(ex.getClass()))
{
throw (TransferException) ex;
}
else
{
throw new TransferException(MSG_ERROR_WHILE_GENERATING_REQUISITE, ex);
}
}
}
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
public PolicyComponent getPolicyComponent()
{
return policyComponent;
}
/**
* When a new node is created as a child of a Transferred or Alien node then
* the new node needs to be marked as an alien.
*
* Then the tree needs to be walked upwards to mark all parent
* transferred nodes as alien.
*/
public void onCreateChildAssociation(ChildAssociationRef childAssocRef,
boolean isNewNode)
{
log.debug("on create child association to transferred node");
final String localRepositoryId = descriptorService.getCurrentRepositoryDescriptor().getId();
alienProcessor.onCreateChild(childAssocRef, localRepositoryId, isNewNode);
}
/**
* When an alien node is deleted the it may be the last alien invader
*
* Walk the tree checking the invasion status!
*/
public void beforeDeleteNode(NodeRef deletedNodeRef)
{
log.debug("on delete node - need to check for transferred node");
alienProcessor.beforeDeleteAlien(deletedNodeRef, null);
}
/**
* When a transferred node is restored it may be a new invader or it may no
* longer be an invader.
*
* Walk the tree checking the invasion status!
*/
public void onRestoreNode(ChildAssociationRef childAssocRef)
{
log.debug("on restore node");
final String localRepositoryId = descriptorService.getCurrentRepositoryDescriptor().getId();
log.debug("restoredAssocRef:" + childAssocRef);
alienProcessor.afterMoveAlien(childAssocRef);
}
/**
* When an alien node is moved it may un-invade its old location and invade a new
* location. The node may also cease to be alien.
*/
public void onMoveNode(ChildAssociationRef oldChildAssocRef,
ChildAssociationRef newChildAssocRef)
{
log.debug("onMoveNode");
log.debug("oldChildAssocRef:" + oldChildAssocRef);
log.debug("newChildAssocRef:" + newChildAssocRef);
alienProcessor.beforeDeleteAlien(newChildAssocRef.getChildRef(), oldChildAssocRef);
alienProcessor.afterMoveAlien(newChildAssocRef);
}
public void setDescriptorService(DescriptorService descriptorService)
{
this.descriptorService = descriptorService;
}
public DescriptorService getDescriptorService()
{
return descriptorService;
}
public void setAlienProcessor(AlienProcessor alienProcessor)
{
this.alienProcessor = alienProcessor;
}
public AlienProcessor getAlienProcessor()
{
return alienProcessor;
}
}