Search in sources :

Example 51 with App

use of org.structr.core.app.App in project structr by structr.

the class StructrSchemaViewPath method getSchemaNode.

public AbstractSchemaNode getSchemaNode() {
    if (schemaNode == null) {
        final App app = StructrApp.getInstance(fs.getSecurityContext());
        try (final Tx tx = app.tx()) {
            // remove /files from path since it is a virtual directory
            schemaNode = app.nodeQuery(AbstractSchemaNode.class).and(AbstractNode.name, name).getFirst();
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("Unable to load actual file for path {}: {}", new Object[] { toString(), fex.getMessage() });
        }
    }
    return schemaNode;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode)

Example 52 with App

use of org.structr.core.app.App in project structr by structr.

the class StructrSchemaViewsPath method resolveStructrPath.

@Override
public StructrPath resolveStructrPath(final String pathComponent) {
    final App app = StructrApp.getInstance(fs.getSecurityContext());
    StructrPath path = null;
    try (final Tx tx = app.tx()) {
        for (final SchemaView schemaView : schemaNode.getProperty(SchemaNode.schemaViews)) {
            if (pathComponent.equals(schemaView.getName())) {
                path = new StructrSchemaViewPath(fs, StructrSchemaViewsPath.this, schemaNode, schemaView);
            }
        }
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
    return path;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) SchemaView(org.structr.core.entity.SchemaView) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StructrPath(org.structr.files.ssh.filesystem.StructrPath)

Example 53 with App

use of org.structr.core.app.App in project structr by structr.

the class CatCommand method execute.

@Override
public void execute(final StructrShellCommand parent) throws IOException {
    final App app = StructrApp.getInstance();
    try (final Tx tx = app.tx()) {
        final Folder currentFolder = parent.getCurrentFolder();
        if (currentFolder != null) {
            listFolder(parent, currentFolder.getChildren());
        } else {
            listFolder(parent, app.nodeQuery(AbstractFile.class).and(StructrApp.key(AbstractFile.class, "parent"), null).getAsList());
        }
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder)

Example 54 with App

use of org.structr.core.app.App in project structr by structr.

the class CdCommand method handleTabCompletion.

@Override
public void handleTabCompletion(final StructrShellCommand parent, final String line, final int tabCount) throws IOException {
    if (line.contains(" ") && line.length() >= 3) {
        final PropertyKey<AbstractFile> parentKey = StructrApp.key(AbstractFile.class, "parent");
        String incompletePath = line.substring(line.indexOf(" ") + 1);
        Folder baseFolder = null;
        String lastPathPart = null;
        if (incompletePath.startsWith("\"")) {
            incompletePath = incompletePath.substring(1);
        }
        final App app = StructrApp.getInstance();
        if ("..".equals(incompletePath)) {
            term.handleCharacter('/');
            return;
        }
        if (incompletePath.startsWith("/")) {
            incompletePath = incompletePath.substring(1);
        } else {
            baseFolder = parent.getCurrentFolder();
        }
        // identify full path parts and find folders
        final String[] parts = incompletePath.split("[/]+");
        final int partCount = parts.length;
        try (final Tx tx = app.tx()) {
            // only a single path part
            if (partCount == 1) {
                lastPathPart = parts[0];
            } else {
                lastPathPart = parts[partCount - 1];
                // more than a single path part, find preceding folders
                for (int i = 0; i < partCount - 1; i++) {
                    // skip empty path parts
                    if (StringUtils.isNotBlank(parts[i])) {
                        baseFolder = app.nodeQuery(Folder.class).and(parentKey, baseFolder).and(Folder.name, parts[i]).getFirst();
                        if (baseFolder == null) {
                            return;
                        }
                    }
                }
            }
            final List<Folder> allFolders = app.nodeQuery(Folder.class).and(parentKey, baseFolder).getAsList();
            final List<Folder> folders = new LinkedList<>();
            for (final Folder folder : allFolders) {
                if (folder.getName().startsWith(lastPathPart)) {
                    folders.add(folder);
                }
            }
            if (folders.size() > 1) {
                // only display autocomplete suggestions after second tab
                if (tabCount > 1) {
                    displayAutocompleteSuggestions(parent, folders, line);
                }
            } else if (!folders.isEmpty()) {
                final Folder folder = folders.get(0);
                if (parent.isAllowed(folder, Permission.read, false)) {
                    if (lastPathPart.equals(folder.getName())) {
                        // only display autocomplete suggestions after second tab
                        if (tabCount > 1) {
                            displayAutocompleteSuggestions(parent, folder.getFolders(), line);
                        } else {
                            if (!line.endsWith("/")) {
                                term.handleCharacter('/');
                            }
                        }
                    } else {
                        displayAutocompleteFolder(folder, lastPathPart);
                    }
                }
            }
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder) LinkedList(java.util.LinkedList)

Example 55 with App

use of org.structr.core.app.App in project structr by structr.

the class CMISRepositoryService method getBaseTypeChildren.

private List<TypeDefinition> getBaseTypeChildren(final BaseTypeId baseTypeId, final Boolean includePropertyDefinitions) {
    final ConfigurationProvider config = StructrApp.getConfiguration();
    final List<TypeDefinition> result = new LinkedList<>();
    final App app = StructrApp.getInstance();
    // static definition of base type children, add new types here!
    switch(baseTypeId) {
        case CMIS_DOCUMENT:
            result.add(extendTypeDefinition(File.class, includePropertyDefinitions));
            break;
        case CMIS_FOLDER:
            result.add(extendTypeDefinition(Folder.class, includePropertyDefinitions));
            break;
        case CMIS_ITEM:
            try (final Tx tx = app.tx()) {
                for (final SchemaNode schemaNode : app.nodeQuery(SchemaNode.class).sort(AbstractNode.name).getAsList()) {
                    final Class type = config.getNodeEntityClass(schemaNode.getClassName());
                    if (type != null) {
                        final CMISInfo info = getCMISInfo(type);
                        if (info != null && baseTypeId.equals(info.getBaseTypeId())) {
                            final TypeDefinition extendedTypeDefinition = extendTypeDefinition(type, includePropertyDefinitions);
                            if (extendedTypeDefinition != null) {
                                result.add(extendedTypeDefinition);
                            }
                        }
                    }
                }
                tx.success();
            } catch (final FrameworkException fex) {
                logger.warn("", fex);
            }
            break;
    }
    return result;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) SchemaNode(org.structr.core.entity.SchemaNode) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ConfigurationProvider(org.structr.schema.ConfigurationProvider) CMISInfo(org.structr.cmis.CMISInfo) Folder(org.structr.web.entity.Folder) File(org.structr.web.entity.File) LinkedList(java.util.LinkedList) MutableTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableTypeDefinition) MutablePolicyTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutablePolicyTypeDefinition) MutableRelationshipTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableRelationshipTypeDefinition) MutableFolderTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableFolderTypeDefinition) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) MutableDocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableDocumentTypeDefinition) MutableSecondaryTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableSecondaryTypeDefinition) MutableItemTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.MutableItemTypeDefinition)

Aggregations

App (org.structr.core.app.App)296 StructrApp (org.structr.core.app.StructrApp)294 Tx (org.structr.core.graph.Tx)201 FrameworkException (org.structr.common.error.FrameworkException)176 LinkedList (java.util.LinkedList)60 SecurityContext (org.structr.common.SecurityContext)56 PropertyMap (org.structr.core.property.PropertyMap)41 Folder (org.structr.web.entity.Folder)38 GraphObject (org.structr.core.GraphObject)35 Principal (org.structr.core.entity.Principal)31 IOException (java.io.IOException)30 AbstractFile (org.structr.web.entity.AbstractFile)27 AbstractNode (org.structr.core.entity.AbstractNode)26 Test (org.junit.Test)24 NodeAttribute (org.structr.core.graph.NodeAttribute)24 File (org.structr.web.entity.File)23 NodeInterface (org.structr.core.graph.NodeInterface)22 SchemaNode (org.structr.core.entity.SchemaNode)19 PropertyKey (org.structr.core.property.PropertyKey)17 Map (java.util.Map)16