Search in sources :

Example 1 with EvaluatorContext

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

the class NonTransactionalRuleContentDiskDriver method openFile.

@Override
public NetworkFile openFile(SrvSession sess, TreeConnection tree, FileOpenParams param) throws IOException {
    String path = param.getPath();
    boolean truncate = param.isOverwrite();
    if (logger.isDebugEnabled()) {
        int sharedAccess = param.getSharedAccess();
        String strSharedAccess = SharingMode.getSharingModeAsString(sharedAccess);
        logger.debug("openFile:" + path + ", isDirectory: " + param.isDirectory() + ", isStream: " + param.isStream() + ", readOnlyAccess: " + param.isReadOnlyAccess() + ", readWriteAccess: " + param.isReadWriteAccess() + ", writeOnlyAccess:" + param.isWriteOnlyAccess() + ", attributesOnlyAccess:" + param.isAttributesOnlyAccess() + ", sequentialAccessOnly:" + param.isSequentialAccessOnly() + ", writeThrough:" + param.isWriteThrough() + ", truncate:" + truncate + ", requestBatchOpLock:" + param.requestBatchOpLock() + ", requestExclusiveOpLock:" + param.requestExclusiveOpLock() + ", isDeleteOnClose:" + param.isDeleteOnClose() + ", allocationSize:" + param.getAllocationSize() + ", sharedAccess: " + strSharedAccess + ", openAction: " + param.getOpenAction() + param);
    }
    ContentContext tctx = (ContentContext) tree.getContext();
    NodeRef rootNode = tctx.getRootNode();
    DriverState driverState = getDriverState(sess);
    String[] paths = FileName.splitPath(path);
    String folder = paths[0];
    String file = paths[1];
    EvaluatorContext ctx = getEvaluatorContext(driverState, folder);
    OpenFileMode openMode = OpenFileMode.READ_ONLY;
    if (param.isAttributesOnlyAccess()) {
        openMode = OpenFileMode.ATTRIBUTES_ONLY;
    } else if (param.isReadWriteAccess()) {
        openMode = OpenFileMode.READ_WRITE;
    } else if (param.isWriteOnlyAccess()) {
        openMode = OpenFileMode.WRITE_ONLY;
    } else if (param.isReadOnlyAccess()) {
        openMode = OpenFileMode.READ_ONLY;
    } else if (param.isDeleteOnClose()) {
        if (logger.isDebugEnabled()) {
            logger.debug("open file has delete on close");
        }
        openMode = OpenFileMode.DELETE;
    }
    try {
        Operation o = new OpenFileOperation(file, openMode, truncate, rootNode, path);
        Command c = ruleEvaluator.evaluate(ctx, o);
        Object ret = commandExecutor.execute(sess, tree, c);
        if (ret != null && ret instanceof NetworkFile) {
            NetworkFile x = (NetworkFile) ret;
            if (logger.isDebugEnabled()) {
                logger.debug("returning open file: for path:" + path + ", ret:" + ret);
            }
            return x;
        } 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 open file " + param.getPath(), ade);
    }
// return diskInterface.openFile(sess, tree, params);
}
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) OpenFileOperation(org.alfresco.filesys.repo.rules.operations.OpenFileOperation) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Command(org.alfresco.filesys.repo.rules.Command) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile)

Example 2 with EvaluatorContext

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

the class NonTransactionalRuleContentDiskDriver method deleteFile.

@Override
public void deleteFile(SrvSession sess, TreeConnection tree, String name) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("deleteFile name:" + name);
    }
    try {
        ContentContext tctx = (ContentContext) tree.getContext();
        NodeRef rootNode = tctx.getRootNode();
        DriverState driverState = getDriverState(sess);
        String[] paths = FileName.splitPath(name);
        String folder = paths[0];
        String file = paths[1];
        EvaluatorContext ctx = getEvaluatorContext(driverState, folder);
        Operation o = new DeleteFileOperation(file, rootNode, name);
        Command c = ruleEvaluator.evaluate(ctx, o);
        commandExecutor.execute(sess, tree, c);
        releaseEvaluatorContextIfEmpty(driverState, ctx, folder);
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) {
        throw new AccessDeniedException("Unable to delete file " + name, ade);
    }
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) EvaluatorContext(org.alfresco.filesys.repo.rules.EvaluatorContext) DeleteFileOperation(org.alfresco.filesys.repo.rules.operations.DeleteFileOperation) 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) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Command(org.alfresco.filesys.repo.rules.Command)

Example 3 with EvaluatorContext

use of org.alfresco.filesys.repo.rules.EvaluatorContext 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 4 with EvaluatorContext

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

the class NonTransactionalRuleContentDiskDriver method closeFile.

@Override
public void closeFile(SrvSession sess, TreeConnection tree, NetworkFile param) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("closeFile:" + param.getFullName());
    }
    ContentContext tctx = (ContentContext) tree.getContext();
    NodeRef rootNode = tctx.getRootNode();
    DriverState driverState = getDriverState(sess);
    String[] paths = FileName.splitPath(param.getFullName());
    String folder = paths[0];
    String file = paths[1];
    try {
        EvaluatorContext ctx = getEvaluatorContext(driverState, folder);
        Operation o = new CloseFileOperation(file, param, rootNode, param.getFullName(), param.hasDeleteOnClose(), param.isForce());
        Command c = ruleEvaluator.evaluate(ctx, o);
        commandExecutor.execute(sess, tree, c);
        releaseEvaluatorContextIfEmpty(driverState, ctx, folder);
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) {
        throw new AccessDeniedException("Unable to close file " + param.getFullName(), ade);
    }
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) EvaluatorContext(org.alfresco.filesys.repo.rules.EvaluatorContext) CloseFileOperation(org.alfresco.filesys.repo.rules.operations.CloseFileOperation) 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) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Command(org.alfresco.filesys.repo.rules.Command)

Example 5 with EvaluatorContext

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

the class NonTransactionalRuleContentDiskDriver method getEvaluatorContext.

/**
 * Get the evaluator context from the state and the folder.
 * @param driverState DriverState
 * @param folder String
 * @return EvaluatorContext
 */
private EvaluatorContext getEvaluatorContext(DriverState driverState, String folder) {
    synchronized (driverState.contextMap) {
        EvaluatorContext ctx = driverState.contextMap.get(folder);
        if (ctx == null) {
            ctx = ruleEvaluator.createContext(driverState.sessionState);
            driverState.contextMap.put(folder, ctx);
            if (logger.isDebugEnabled()) {
                logger.debug("new driver context: " + folder);
            }
        }
        return ctx;
    }
}
Also used : EvaluatorContext(org.alfresco.filesys.repo.rules.EvaluatorContext)

Aggregations

EvaluatorContext (org.alfresco.filesys.repo.rules.EvaluatorContext)6 Command (org.alfresco.filesys.repo.rules.Command)5 Operation (org.alfresco.filesys.repo.rules.Operation)5 CloseFileOperation (org.alfresco.filesys.repo.rules.operations.CloseFileOperation)5 CreateFileOperation (org.alfresco.filesys.repo.rules.operations.CreateFileOperation)5 DeleteFileOperation (org.alfresco.filesys.repo.rules.operations.DeleteFileOperation)5 MoveFileOperation (org.alfresco.filesys.repo.rules.operations.MoveFileOperation)5 OpenFileOperation (org.alfresco.filesys.repo.rules.operations.OpenFileOperation)5 RenameFileOperation (org.alfresco.filesys.repo.rules.operations.RenameFileOperation)5 AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 NetworkFile (org.alfresco.jlan.server.filesys.NetworkFile)2 Date (java.util.Date)1