use of org.alfresco.filesys.repo.rules.operations.RenameFileOperation in project alfresco-repository by Alfresco.
the class ScenarioRenameShuffleInstance method evaluate.
/**
* Evaluate the next operation
* @param operation 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(state) {
case NONE:
if (operation instanceof RenameFileOperation) {
logger.debug("New scenario initialised");
RenameFileOperation r = (RenameFileOperation) operation;
this.from = r.getFrom();
this.to = r.getTo();
state = InternalState.INITIALISED;
}
break;
case INITIALISED:
if (operation instanceof CreateFileOperation) {
CreateFileOperation c = (CreateFileOperation) operation;
if (from.equals(c.getName())) {
logger.debug("transition to LOOK_FOR_DELETE");
state = InternalState.LOOK_FOR_DELETE;
}
}
break;
case LOOK_FOR_DELETE:
if (operation instanceof DeleteFileOperation) {
DeleteFileOperation d = (DeleteFileOperation) operation;
if (to.equals(d.getName())) {
logger.debug("Rename shuffle complete - fire!");
String[] paths = FileName.splitPath(d.getPath());
String oldFolder = paths[0];
/**
* Shuffle is as follows
* a) Copy content from File to File~
* b) Delete File
* c) Rename File~ to File
*/
ArrayList<Command> commands = new ArrayList<Command>();
CopyContentCommand copyContent = new CopyContentCommand(from, to, d.getRootNodeRef(), oldFolder + "\\" + from, oldFolder + "\\" + to);
RenameFileCommand r1 = new RenameFileCommand(to, from, d.getRootNodeRef(), oldFolder + "\\" + to, oldFolder + "\\" + from);
DeleteFileCommand d1 = new DeleteFileCommand(from, d.getRootNodeRef(), oldFolder + "\\" + from);
commands.add(copyContent);
commands.add(d1);
commands.add(r1);
logger.debug("Scenario complete");
isComplete = true;
return new CompoundCommand(commands);
}
}
}
return null;
}
use of org.alfresco.filesys.repo.rules.operations.RenameFileOperation in project alfresco-repository by Alfresco.
the class ScenarioMultipleRenameShuffle method createInstance.
@Override
public ScenarioInstance createInstance(final EvaluatorContext ctx, Operation operation) {
/**
* This scenario is triggered by a rename of a file matching
* the pattern
*/
if (operation instanceof RenameFileOperation) {
RenameFileOperation r = (RenameFileOperation) operation;
Matcher m = pattern.matcher(r.getTo());
if (m.matches()) {
if (logger.isDebugEnabled()) {
logger.debug("New Scenario Multiple Rename Shuffle strPattern: " + strPattern + " matches" + r.getTo());
}
ScenarioMultipleRenameShuffleInstance instance = new ScenarioMultipleRenameShuffleInstance();
instance.setTimeout(timeout);
instance.setRanking(ranking);
return instance;
}
}
// No not interested.
return null;
}
use of org.alfresco.filesys.repo.rules.operations.RenameFileOperation in project alfresco-repository by Alfresco.
the class NonTransactionalRuleContentDiskDriver method renameFile.
@Override
public void renameFile(SrvSession sess, TreeConnection tree, String oldPath, String newPath) throws IOException {
ContentContext tctx = (ContentContext) tree.getContext();
NodeRef rootNode = tctx.getRootNode();
if (logger.isDebugEnabled()) {
logger.debug("renameFile oldPath:" + oldPath + ", newPath:" + newPath);
}
DriverState driverState = getDriverState(sess);
// Is this a rename within the same folder or a move between folders?
String[] paths = FileName.splitPath(oldPath);
String oldFolder = paths[0];
String oldFile = paths[1];
paths = FileName.splitPath(newPath);
String newFolder = paths[0];
String newFile = paths[1];
try {
if (oldFolder.equalsIgnoreCase(newFolder)) {
logger.debug("renameFileCommand - is a rename within the same folder");
EvaluatorContext ctx = getEvaluatorContext(driverState, oldFolder);
Operation o = new RenameFileOperation(oldFile, newFile, oldPath, newPath, rootNode);
Command c = ruleEvaluator.evaluate(ctx, o);
commandExecutor.execute(sess, tree, c);
ruleEvaluator.notifyRename(ctx, o, c);
releaseEvaluatorContextIfEmpty(driverState, ctx, oldFolder);
} else {
logger.debug("moveFileCommand - move between folders");
Operation o = new MoveFileOperation(oldFile, newFile, oldPath, newPath, rootNode);
/*
* Note: At the moment we only have move scenarios for the destination folder - so
* we only need to evaluate against a single (destination) context/folder.
* This will require re-design as and when we need to have scenarios for the source/folder
*/
// EvaluatorContext ctx1 = getEvaluatorContext(driverState, oldFolder);
EvaluatorContext ctx2 = getEvaluatorContext(driverState, newFolder);
Command c = ruleEvaluator.evaluate(ctx2, o);
commandExecutor.execute(sess, tree, c);
releaseEvaluatorContextIfEmpty(driverState, ctx2, newFolder);
// diskInterface.renameFile(sess, tree, oldPath, newPath);
}
} catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) {
throw new AccessDeniedException("Unable to rename file file " + oldPath, ade);
}
}
use of org.alfresco.filesys.repo.rules.operations.RenameFileOperation in project alfresco-repository by Alfresco.
the class ScenarioDoubleRenameShuffle method createInstance.
@Override
public ScenarioInstance createInstance(final EvaluatorContext ctx, Operation operation) {
/**
* This scenario is triggered by a rename of a file matching
* the pattern
*/
if (operation instanceof RenameFileOperation) {
RenameFileOperation r = (RenameFileOperation) operation;
Matcher m = pattern.matcher(r.getTo());
if (m.matches()) {
if (logger.isDebugEnabled()) {
logger.debug("New Scenario Double Rename Shuffle Instance strPattern:" + pattern + " matches" + r.getTo());
}
ScenarioDoubleRenameShuffleInstance instance = new ScenarioDoubleRenameShuffleInstance();
instance.setTimeout(timeout);
instance.setRanking(ranking);
instance.setDeleteBackup(deleteBackup);
instance.setMoveAsSystem(moveAsSystem);
if (interimPattern != null) {
instance.setInterimPattern(interimPattern);
}
return instance;
}
}
// No not interested.
return null;
}
use of org.alfresco.filesys.repo.rules.operations.RenameFileOperation in project alfresco-repository by Alfresco.
the class ScenarioOpenFileInstance method notifyRename.
@Override
public void notifyRename(Operation operation, Command command) {
if (operation instanceof RenameFileOperation) {
RenameFileOperation r = (RenameFileOperation) operation;
if (r.getFrom() == null) {
return;
}
if (name.equalsIgnoreCase(r.getFrom())) {
if (logger.isWarnEnabled()) {
logger.warn("rename of this scenario: to " + r.getTo());
}
name = r.getTo();
if (fileHandleReadWrite != null) {
fileHandleReadWrite.setName(r.getTo());
fileHandleReadWrite.setFullName(r.getToPath());
}
if (fileHandleReadOnly != null) {
fileHandleReadOnly.setName(r.getTo());
fileHandleReadOnly.setFullName(r.getToPath());
}
}
}
}
Aggregations