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);
//
// ChildAssociationRef currentAssoc = childAssocRef;
//
// final String localRepositoryId = descriptorService.getCurrentRepositoryDescriptor().getId();
//
// // TODO Needs to check assoc is a cm:contains or subtype
// if(childAssocRef.isPrimary())
// {
// NodeRef parentNodeRef = currentAssoc.getParentRef();
// NodeRef childNodeRef = currentAssoc.getChildRef();
//
// /**
// * Make the new child node ref an alien node
// */
// setAlien(childNodeRef, localRepositoryId);
//
// /**
// * Now deal with the parents of this alien node
// */
// while(currentAssoc != null)
// {
// parentNodeRef = currentAssoc.getParentRef();
// childNodeRef = currentAssoc.getChildRef();
//
// if(nodeService.hasAspect(parentNodeRef, TransferModel.ASPECT_TRANSFERRED) || nodeService.hasAspect(parentNodeRef, TransferModel.ASPECT_ALIEN))
// {
// if (!isInvaded(parentNodeRef, localRepositoryId))
// {
// if(log.isDebugEnabled())
// {
// log.debug("alien invades parent node:" + parentNodeRef + ", repositoryId:" + localRepositoryId);
// }
//
// final NodeRef newAlien = parentNodeRef;
//
// /**
// * Parent may be locked or not be editable by the current user
// * turn off auditing and lock service for this transaction and
// * run as admin.
// */
// RunAsWork actionRunAs = new RunAsWork()
// {
// public Void doWork() throws Exception
// {
// behaviourFilter.disableBehaviour(newAlien, ContentModel.ASPECT_AUDITABLE);
// behaviourFilter.disableBehaviour(newAlien, ContentModel.ASPECT_LOCKABLE);
// setAlien(newAlien, localRepositoryId);
// return null;
// }
// };
// AuthenticationUtil.runAs(actionRunAs, AuthenticationUtil.getSystemUserName());
//
// // Yes the parent has been invaded so step up to the parent's parent
// currentAssoc = nodeService.getPrimaryParent(parentNodeRef);
// }
// else
// {
// log.debug("parent node is already invaded");
// currentAssoc = null;
// }
// }
// else
// {
// log.debug("parent is not a transferred node");
// currentAssoc = null;
// }
// }
// }
}
/**
* 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);
//
// Liststuff = (List)nodeService.getProperty(deletedNodeRef, TransferModel.PROP_INVADED_BY);
//
// Vector exInvaders = new Vector(stuff);
//
// ChildAssociationRef currentAssoc = nodeService.getPrimaryParent(deletedNodeRef);
//
// while(currentAssoc != null && exInvaders != null && exInvaders.size() > 0)
// {
// NodeRef parentNodeRef = currentAssoc.getParentRef();
// NodeRef currentNodeRef = currentAssoc.getChildRef();
//
// /**
// * Does the parent have alien invaders ?
// */
// if(nodeService.hasAspect(parentNodeRef, TransferModel.ASPECT_ALIEN))
// {
// log.debug("parent node is alien - check siblings");
//
// /**
// * For each invader of the deletedNode
// */
// Iterator i = exInvaders.listIterator();
// while(i.hasNext())
// {
// String exInvader = i.next();
// log.debug("Checking exInvader:" + exInvader);
//
// /**
// * Check the siblings of this node to see whether there are any other alien nodes for this invader.
// */
// //TODO replace with a more efficient query
// List refs = nodeService.getChildAssocs(parentNodeRef);
//
// for(ChildAssociationRef ref : refs)
// {
// NodeRef childRef = ref.getChildRef();
// ListinvadedBy = (List)nodeService.getProperty(childRef, TransferModel.PROP_INVADED_BY);
//
// if(childRef.equals(currentNodeRef))
// {
// // do nothing - this is the node we are working with.
// }
// else
// {
// if(invadedBy != null && invadedBy.contains(exInvader))
// {
// // There is a sibling so remove this from the list of ex invaders.
// log.debug("yes there is a sibling so it remains an invader");
// i.remove();
// break;
// }
// }
// } // for each child assoc
//
// } // for each invader
//
// log.debug("end of checking siblings");
//
// if(exInvaders.size() > 0)
// {
// log.debug("removing invaders from parent node:" + parentNodeRef);
// List parentInvaders = (List)nodeService.getProperty(parentNodeRef, TransferModel.PROP_INVADED_BY);
//
// final List newInvaders = new ArrayList(10);
// for(String invader : parentInvaders)
// {
// if(exInvaders.contains(invader))
// {
// log.debug("removing invader:" + invader);
// }
// else
// {
// newInvaders.add(invader);
// }
// }
//
// final NodeRef oldAlien = parentNodeRef;
//
// /**
// * Parent may be locked or not be editable by the current user
// * turn off auditing and lock service for this transaction and
// * run as admin.
// */
// RunAsWork actionRunAs = new RunAsWork()
// {
// public Void doWork() throws Exception
// {
// behaviourFilter.disableBehaviour(oldAlien, ContentModel.ASPECT_AUDITABLE);
// behaviourFilter.disableBehaviour(oldAlien, ContentModel.ASPECT_LOCKABLE);
// if(newInvaders.size() > 0)
// {
// nodeService.setProperty(oldAlien, TransferModel.PROP_INVADED_BY, (Serializable)newInvaders);
// }
// else
// {
// log.debug("parent node no is no longer alien");
// nodeService.removeAspect(oldAlien, TransferModel.ASPECT_ALIEN);
// }
// return null;
// }
// };
// AuthenticationUtil.runAs(actionRunAs, AuthenticationUtil.getSystemUserName());
// }
//
// /**
// * Now step up to the parent's parent
// */
// currentAssoc = nodeService.getPrimaryParent(parentNodeRef);
// }
// else
// {
// log.debug("parent is not an alien node");
// currentAssoc = null;
// }
// } // end of while
}
// /**
// * Is this node invaded ?
// * @param nodeRef
// * @param invader
// * @return true, this node has been invaded by the invader
// */
// private boolean isInvaded(NodeRef nodeRef, String invader)
// {
// ListinvadedBy = (List)nodeService.getProperty(nodeRef, TransferModel.PROP_INVADED_BY);
//
// if(invadedBy == null)
// {
// return false;
// }
//
// return invadedBy.contains(invader);
// }
//
// /**
// * Mark the specified node as an alien node, invadedby the invader.
// * @param newAlien
// * @param invader
// */
// private void setAlien(NodeRef newAlien, String invader)
// {
// // Introduce a Multi-valued property
// List invadedBy = (List)nodeService.getProperty(newAlien,
// TransferModel.PROP_INVADED_BY);
//
// if(invadedBy == null)
// {
// nodeService.setProperty(newAlien, TransferModel.PROP_ALIEN, Boolean.TRUE);
// invadedBy = new ArrayList(1);
// }
// invadedBy.add(invader);
//
// /**
// * Set the invaded by property
// */
// nodeService.setProperty(newAlien, TransferModel.PROP_INVADED_BY, (Serializable) invadedBy);
//
// /**
// * Experiment with a residual property
// */
// nodeService.setProperty(newAlien, QName.createQName(TransferModel.TRANSFER_MODEL_1_0_URI,
// "invader" + invader), Boolean.TRUE);
//
// }
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;
}
}