Search in sources :

Example 6 with RenameFileOperation

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;
}
Also used : DeleteFileOperation(org.alfresco.filesys.repo.rules.operations.DeleteFileOperation) ArrayList(java.util.ArrayList) DeleteFileCommand(org.alfresco.filesys.repo.rules.commands.DeleteFileCommand) Date(java.util.Date) RenameFileOperation(org.alfresco.filesys.repo.rules.operations.RenameFileOperation) CompoundCommand(org.alfresco.filesys.repo.rules.commands.CompoundCommand) CopyContentCommand(org.alfresco.filesys.repo.rules.commands.CopyContentCommand) RenameFileCommand(org.alfresco.filesys.repo.rules.commands.RenameFileCommand) CompoundCommand(org.alfresco.filesys.repo.rules.commands.CompoundCommand) RenameFileCommand(org.alfresco.filesys.repo.rules.commands.RenameFileCommand) CopyContentCommand(org.alfresco.filesys.repo.rules.commands.CopyContentCommand) DeleteFileCommand(org.alfresco.filesys.repo.rules.commands.DeleteFileCommand) CreateFileOperation(org.alfresco.filesys.repo.rules.operations.CreateFileOperation)

Example 7 with RenameFileOperation

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;
}
Also used : Matcher(java.util.regex.Matcher) RenameFileOperation(org.alfresco.filesys.repo.rules.operations.RenameFileOperation)

Example 8 with RenameFileOperation

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);
    }
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) EvaluatorContext(org.alfresco.filesys.repo.rules.EvaluatorContext) OpenFileOperation(org.alfresco.filesys.repo.rules.operations.OpenFileOperation) RenameFileOperation(org.alfresco.filesys.repo.rules.operations.RenameFileOperation) DeleteFileOperation(org.alfresco.filesys.repo.rules.operations.DeleteFileOperation) CreateFileOperation(org.alfresco.filesys.repo.rules.operations.CreateFileOperation) Operation(org.alfresco.filesys.repo.rules.Operation) MoveFileOperation(org.alfresco.filesys.repo.rules.operations.MoveFileOperation) CloseFileOperation(org.alfresco.filesys.repo.rules.operations.CloseFileOperation) RenameFileOperation(org.alfresco.filesys.repo.rules.operations.RenameFileOperation) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Command(org.alfresco.filesys.repo.rules.Command) MoveFileOperation(org.alfresco.filesys.repo.rules.operations.MoveFileOperation)

Example 9 with RenameFileOperation

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;
}
Also used : Matcher(java.util.regex.Matcher) RenameFileOperation(org.alfresco.filesys.repo.rules.operations.RenameFileOperation)

Example 10 with RenameFileOperation

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());
            }
        }
    }
}
Also used : RenameFileOperation(org.alfresco.filesys.repo.rules.operations.RenameFileOperation)

Aggregations

RenameFileOperation (org.alfresco.filesys.repo.rules.operations.RenameFileOperation)16 Date (java.util.Date)9 ArrayList (java.util.ArrayList)8 CompoundCommand (org.alfresco.filesys.repo.rules.commands.CompoundCommand)7 CopyContentCommand (org.alfresco.filesys.repo.rules.commands.CopyContentCommand)7 DeleteFileOperation (org.alfresco.filesys.repo.rules.operations.DeleteFileOperation)7 Matcher (java.util.regex.Matcher)6 DeleteFileCommand (org.alfresco.filesys.repo.rules.commands.DeleteFileCommand)6 RenameFileCommand (org.alfresco.filesys.repo.rules.commands.RenameFileCommand)6 CreateFileOperation (org.alfresco.filesys.repo.rules.operations.CreateFileOperation)6 CloseFileOperation (org.alfresco.filesys.repo.rules.operations.CloseFileOperation)4 MoveFileOperation (org.alfresco.filesys.repo.rules.operations.MoveFileOperation)4 CloseFileCommand (org.alfresco.filesys.repo.rules.commands.CloseFileCommand)3 RestoreFileCommand (org.alfresco.filesys.repo.rules.commands.RestoreFileCommand)2 OpenFileOperation (org.alfresco.filesys.repo.rules.operations.OpenFileOperation)2 TempNetworkFile (org.alfresco.filesys.repo.TempNetworkFile)1 Command (org.alfresco.filesys.repo.rules.Command)1 EvaluatorContext (org.alfresco.filesys.repo.rules.EvaluatorContext)1 Operation (org.alfresco.filesys.repo.rules.Operation)1 CallbackCommand (org.alfresco.filesys.repo.rules.commands.CallbackCommand)1