package org.alfresco.filesys.repo.rules; import org.alfresco.filesys.repo.ResultCallback; import org.alfresco.filesys.repo.rules.commands.*; import org.alfresco.filesys.repo.rules.operations.RenameFileOperation; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.service.cmr.repository.NodeRef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.util.ArrayList; import java.util.Date; /** * This is an instance of a "multiple rename shuffle" triggered by rename of a file to a special pattern * file matching a specified pattern. * * a) Original file renamed to the temporary * b) Any operations with temporary (optional): * b1) Temporary file renamed to other temporary * b2) Temporary file deleted * c) Temporary file (maybe not the same, as it was at step 1) renamed to the original file *
* If this filter is active then this is what happens.
* a) Temporary file created. Content copied from original file to temporary file.
* b) Original file deleted (temporary).
* c) any operations with temporary file
* d) Original file restored. Content copied from temporary file to original file.
*
*/
public class ScenarioMultipleRenameShuffleInstance implements ScenarioInstance
{
private static Log logger = LogFactory.getLog(ScenarioMultipleRenameShuffleInstance.class);
private NodeRef originalNodeRef;
enum InternalState
{
NONE,
INITIALISED
}
InternalState internalState = InternalState.NONE;
private Date startTime = new Date();
private String originalName;
private Ranking ranking;
/**
* Timeout in ms. Default 30 seconds.
*/
private long timeout = 30000;
private boolean isComplete;
/**
* Evaluate the next operation
* @param operation
*/
public Command evaluate(Operation operation)
{
/**
* Anti-pattern : timeout
*/
Date now = new Date();
if(now.getTime() > startTime.getTime() + getTimeout())
{
if(logger.isDebugEnabled())
{
logger.debug("Instance timed out");
}
isComplete = true;
return null;
}
switch (internalState)
{
case NONE:
/**
* Looking for first rename O(original) to T(temporary)
*/
if(operation instanceof RenameFileOperation)
{
RenameFileOperation r = (RenameFileOperation)operation;
if(logger.isDebugEnabled())
{
logger.debug("Got first rename - tracking rename: " + operation);
}
originalName = r.getFromPath();
ArrayList