Search in sources :

Example 6 with CreateFileOperation

use of org.alfresco.filesys.repo.rules.operations.CreateFileOperation in project alfresco-repository by Alfresco.

the class ScenarioCreateShuffle method createInstance.

@Override
public ScenarioInstance createInstance(final EvaluatorContext ctx, Operation operation) {
    /**
     * This scenario is triggered by a create of a file matching
     * the pattern
     */
    if (operation instanceof CreateFileOperation) {
        CreateFileOperation c = (CreateFileOperation) operation;
        Matcher m = pattern.matcher(c.getName());
        if (m.matches()) {
            if (logger.isDebugEnabled()) {
                logger.debug("New Scenario Create Shuffle Instance pattern:" + strPattern);
            }
            ScenarioCreateShuffleInstance instance = new ScenarioCreateShuffleInstance();
            instance.setTimeout(timeout);
            instance.setRanking(ranking);
            return instance;
        }
    }
    // No not interested.
    return null;
}
Also used : Matcher(java.util.regex.Matcher) CreateFileOperation(org.alfresco.filesys.repo.rules.operations.CreateFileOperation)

Example 7 with CreateFileOperation

use of org.alfresco.filesys.repo.rules.operations.CreateFileOperation 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 8 with CreateFileOperation

use of org.alfresco.filesys.repo.rules.operations.CreateFileOperation in project alfresco-repository by Alfresco.

the class ScenarioTempDeleteShuffle method createInstance.

@Override
public ScenarioInstance createInstance(final EvaluatorContext ctx, Operation operation) {
    /**
     * This scenario is triggered by a delete of a file matching
     * the pattern
     */
    if (operation instanceof CreateFileOperation) {
        CreateFileOperation c = (CreateFileOperation) operation;
        // check whether file is below .TemporaryItems
        String path = c.getPath();
        // if path contains .TemporaryItems
        Matcher d = tempDirPattern.matcher(path);
        if (d.matches()) {
            logger.debug("pattern matches temp dir folder so this is a new create in a temp dir");
            Matcher m = pattern.matcher(c.getName());
            if (m.matches()) {
                // and how to lock - since we are already have one lock on the scenarios/folder here
                // this is a potential deadlock and synchronization bottleneck
                Map<String, String> createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY);
                if (createdTempFiles == null) {
                    synchronized (ctx.getSessionState()) {
                        logger.debug("created new temp file map and added it to the session state");
                        createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY);
                        if (createdTempFiles == null) {
                            createdTempFiles = Collections.synchronizedMap(new MaxSizeMap<String, String>(5, false));
                            ctx.getSessionState().put(SCENARIO_KEY, createdTempFiles);
                        }
                    }
                }
                createdTempFiles.put(c.getName(), c.getName());
            // TODO - Return a different scenario instance here ???
            // So it can time out and have anti-patterns etc?
            }
        }
    }
    if (operation instanceof MoveFileOperation) {
        MoveFileOperation mf = (MoveFileOperation) operation;
        // check whether file is below .TemporaryItems
        String path = mf.getFromPath();
        // if path contains .TemporaryItems
        Matcher d = tempDirPattern.matcher(path);
        if (d.matches()) {
            logger.debug("pattern matches temp dir folder so this is a new create in a temp dir");
            Matcher m = pattern.matcher(mf.getFrom());
            if (m.matches()) {
                // and how to lock - since we are already have one lock on the scenarios/folder here
                // this is a potential deadlock and synchronization bottleneck
                Map<String, String> createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY);
                if (createdTempFiles == null) {
                    synchronized (ctx.getSessionState()) {
                        logger.debug("created new temp file map and added it to the session state");
                        createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY);
                        if (createdTempFiles == null) {
                            createdTempFiles = Collections.synchronizedMap(new MaxSizeMap<String, String>(5, false));
                            ctx.getSessionState().put(SCENARIO_KEY, createdTempFiles);
                        }
                    }
                }
                createdTempFiles.remove(mf.getFrom());
            // TODO - Return a different scenario instance here ???
            // So it can time out and have anti-patterns etc?
            }
        }
    }
    if (operation instanceof DeleteFileOperation) {
        DeleteFileOperation c = (DeleteFileOperation) operation;
        Matcher m = pattern.matcher(c.getName());
        if (m.matches()) {
            Map<String, String> createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY);
            if (createdTempFiles != null) {
                if (createdTempFiles.containsKey(c.getName())) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("New Scenario Temp Delete Shuffle Instance:" + c.getName());
                    }
                    ScenarioTempDeleteShuffleInstance instance = new ScenarioTempDeleteShuffleInstance();
                    instance.setTimeout(timeout);
                    instance.setRanking(ranking);
                    return instance;
                }
            }
        }
    }
    // No not interested.
    return null;
}
Also used : Matcher(java.util.regex.Matcher) DeleteFileOperation(org.alfresco.filesys.repo.rules.operations.DeleteFileOperation) MoveFileOperation(org.alfresco.filesys.repo.rules.operations.MoveFileOperation) CreateFileOperation(org.alfresco.filesys.repo.rules.operations.CreateFileOperation) HashMap(java.util.HashMap) Map(java.util.Map) MaxSizeMap(org.alfresco.util.MaxSizeMap) MaxSizeMap(org.alfresco.util.MaxSizeMap)

Example 9 with CreateFileOperation

use of org.alfresco.filesys.repo.rules.operations.CreateFileOperation in project alfresco-repository by Alfresco.

the class NonTransactionalRuleContentDiskDriver method createFile.

@Override
public NetworkFile createFile(SrvSession sess, TreeConnection tree, FileOpenParams params) throws IOException {
    try {
        int attr = params.getAttributes();
        if (logger.isDebugEnabled()) {
            int sharedAccess = params.getSharedAccess();
            String strSharedAccess = SharingMode.getSharingModeAsString(sharedAccess);
            logger.debug("createFile:" + params.getPath() + ", isDirectory: " + params.isDirectory() + ", isStream: " + params.isStream() + ", readOnlyAccess: " + params.isReadOnlyAccess() + ", readWriteAccess: " + params.isReadWriteAccess() + ", writeOnlyAccess:" + params.isWriteOnlyAccess() + ", attributesOnlyAccess:" + params.isAttributesOnlyAccess() + ", sequentialAccessOnly:" + params.isSequentialAccessOnly() + ", requestBatchOpLock:" + params.requestBatchOpLock() + ", requestExclusiveOpLock:" + params.requestExclusiveOpLock() + ", isDeleteOnClose:" + params.isDeleteOnClose() + ", sharedAccess: " + strSharedAccess + ", allocationSize: " + params.getAllocationSize() + ", isHidden:" + FileAttribute.isHidden(attr) + ", isSystem:" + FileAttribute.isSystem(attr));
        }
        long creationDateTime = params.getCreationDateTime();
        if (creationDateTime != 0) {
            logger.debug("creationDateTime is set:" + new Date(creationDateTime));
        }
        ContentContext tctx = (ContentContext) tree.getContext();
        NodeRef rootNode = tctx.getRootNode();
        String[] paths = FileName.splitPath(params.getPath());
        String folder = paths[0];
        String file = paths[1];
        DriverState driverState = getDriverState(sess);
        EvaluatorContext ctx = getEvaluatorContext(driverState, folder);
        Operation o = new CreateFileOperation(file, rootNode, params.getPath(), params.getAllocationSize(), FileAttribute.isHidden(attr));
        Command c = ruleEvaluator.evaluate(ctx, o);
        Object ret = commandExecutor.execute(sess, tree, c);
        if (ret != null && ret instanceof NetworkFile) {
            return (NetworkFile) ret;
        } else {
            // Error - contact broken
            logger.error("contract broken - NetworkFile not returned. " + ret == null ? "Return value is null" : ret);
            return null;
        }
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) {
        throw new AccessDeniedException("Unable to create file " + params.getPath(), 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) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Command(org.alfresco.filesys.repo.rules.Command) CreateFileOperation(org.alfresco.filesys.repo.rules.operations.CreateFileOperation) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile)

Example 10 with CreateFileOperation

use of org.alfresco.filesys.repo.rules.operations.CreateFileOperation in project alfresco-repository by Alfresco.

the class ScenarioLockedDeleteShuffle method createInstance.

@Override
public ScenarioInstance createInstance(final EvaluatorContext ctx, Operation operation) {
    /**
     * This scenario is triggered by a create of a file matching
     * the pattern
     */
    if (operation instanceof CreateFileOperation) {
        CreateFileOperation c = (CreateFileOperation) operation;
        Matcher m = pattern.matcher(c.getName());
        if (m.matches()) {
            if (logger.isDebugEnabled()) {
                logger.debug("New Scenario Locked Delete Shuffle Instance pattern:" + strPattern);
            }
            ScenarioLockedDeleteShuffleInstance instance = new ScenarioLockedDeleteShuffleInstance();
            instance.setTimeout(timeout);
            instance.setRanking(ranking);
            return instance;
        }
    }
    // No not interested.
    return null;
}
Also used : Matcher(java.util.regex.Matcher) CreateFileOperation(org.alfresco.filesys.repo.rules.operations.CreateFileOperation)

Aggregations

CreateFileOperation (org.alfresco.filesys.repo.rules.operations.CreateFileOperation)13 DeleteFileOperation (org.alfresco.filesys.repo.rules.operations.DeleteFileOperation)9 Date (java.util.Date)8 ArrayList (java.util.ArrayList)7 CompoundCommand (org.alfresco.filesys.repo.rules.commands.CompoundCommand)7 CopyContentCommand (org.alfresco.filesys.repo.rules.commands.CopyContentCommand)6 DeleteFileCommand (org.alfresco.filesys.repo.rules.commands.DeleteFileCommand)6 RenameFileOperation (org.alfresco.filesys.repo.rules.operations.RenameFileOperation)6 RenameFileCommand (org.alfresco.filesys.repo.rules.commands.RenameFileCommand)5 Matcher (java.util.regex.Matcher)4 MoveFileOperation (org.alfresco.filesys.repo.rules.operations.MoveFileOperation)4 CloseFileOperation (org.alfresco.filesys.repo.rules.operations.CloseFileOperation)3 OpenFileOperation (org.alfresco.filesys.repo.rules.operations.OpenFileOperation)3 CloseFileCommand (org.alfresco.filesys.repo.rules.commands.CloseFileCommand)2 RestoreFileCommand (org.alfresco.filesys.repo.rules.commands.RestoreFileCommand)2 NetworkFile (org.alfresco.jlan.server.filesys.NetworkFile)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TempNetworkFile (org.alfresco.filesys.repo.TempNetworkFile)1 Command (org.alfresco.filesys.repo.rules.Command)1