Search in sources :

Example 31 with AbstractFile

use of org.structr.web.entity.AbstractFile in project structr by structr.

the class CMISNavigationService method getFolderParent.

@Override
public ObjectData getFolderParent(final String repositoryId, final String folderId, final String propertyFilter, final ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    ObjectData result = null;
    try (final Tx tx = app.tx()) {
        final AbstractFile graphObject = app.get(AbstractFile.class, folderId);
        if (graphObject != null) {
            final Folder parent = graphObject.getParent();
            if (parent != null) {
                result = CMISObjectWrapper.wrap(parent, propertyFilter, false);
            }
        }
        tx.success();
    } catch (Throwable t) {
        logger.warn("", t);
    }
    if (result != null) {
        return result;
    }
    return null;
}
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) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder)

Example 32 with AbstractFile

use of org.structr.web.entity.AbstractFile in project structr by structr.

the class CMISNavigationService method getChildrenQuery.

public Query<AbstractFile> getChildrenQuery(final App app, final String folderId) throws FrameworkException {
    final Query<AbstractFile> query = app.nodeQuery(AbstractFile.class).sort(AbstractNode.name);
    final PropertyKey<Folder> parent = StructrApp.key(AbstractFile.class, "parent");
    final PropertyKey<Boolean> hasParent = StructrApp.key(AbstractFile.class, "hasParent");
    final PropertyKey<Boolean> isThumbnail = StructrApp.key(Image.class, "isThumbnail");
    if (CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
        query.and(hasParent, false).and(isThumbnail, false);
    } else {
        final Folder folder = app.get(Folder.class, folderId);
        if (folder != null) {
            query.and(parent, folder).and(isThumbnail, false);
        } else {
            throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
        }
    }
    return query;
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder)

Example 33 with AbstractFile

use of org.structr.web.entity.AbstractFile in project structr by structr.

the class CMISObjectService method createFolder.

@Override
public String createFolder(final String repositoryId, final Properties properties, final String folderId, final List<String> policies, final Acl addAces, final Acl removeAces, final ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    String uuid = null;
    try (final Tx tx = app.tx()) {
        final String objectTypeId = getStringValue(properties, PropertyIds.OBJECT_TYPE_ID);
        final Class type = typeFromObjectTypeId(objectTypeId, BaseTypeId.CMIS_FOLDER, Folder.class);
        // check if type exists
        if (type != null) {
            // check that base type is cmis:folder
            final BaseTypeId baseTypeId = getBaseTypeId(type);
            if (baseTypeId != null && BaseTypeId.CMIS_FOLDER.equals(baseTypeId)) {
                // create folder
                final AbstractFile newFolder = (AbstractFile) app.create(type, PropertyMap.cmisTypeToJavaType(securityContext, type, properties));
                // find and set parent if it exists
                if (!CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
                    final Folder parent = app.get(Folder.class, folderId);
                    if (parent != null) {
                        newFolder.setParent(parent);
                    } else {
                        throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
                    }
                }
                uuid = newFolder.getUuid();
            } else {
                throw new CmisConstraintException("Cannot create cmis:folder of type " + objectTypeId);
            }
        } else {
            throw new CmisObjectNotFoundException("Type with ID " + objectTypeId + " does not exist");
        }
        tx.success();
    } catch (Throwable t) {
        throw new CmisRuntimeException("New folder could not be created: " + t.getMessage());
    }
    return uuid;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) Folder(org.structr.web.entity.Folder)

Example 34 with AbstractFile

use of org.structr.web.entity.AbstractFile in project structr by structr.

the class FileSyncWatchEventListener method handle.

// ----- private methods -----
private FolderAndFile handle(final Path root, final Path relativePath, final Path path, final boolean create) throws FrameworkException {
    // identify mounted folder object
    final PropertyKey<String> mountTargetKey = StructrApp.key(Folder.class, "mountTarget");
    final Folder folder = StructrApp.getInstance().nodeQuery(Folder.class).and(mountTargetKey, root.toString()).getFirst();
    if (folder != null) {
        final String mountFolderPath = folder.getProperty(StructrApp.key(Folder.class, "path"));
        if (mountFolderPath != null) {
            final Path relativePathParent = relativePath.getParent();
            if (relativePathParent == null) {
                return new FolderAndFile(folder, getOrCreate(folder, path, relativePath, create));
            } else {
                final String pathRelativeToRoot = folder.getPath() + "/" + relativePathParent.toString();
                final Folder parentFolder = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), pathRelativeToRoot);
                final AbstractFile file = getOrCreate(parentFolder, path, relativePath, create);
                return new FolderAndFile(folder, file);
            }
        } else {
            logger.warn("Cannot handle watch event, folder {} has no path", folder.getUuid());
        }
    }
    return null;
}
Also used : Path(java.nio.file.Path) AbstractFile(org.structr.web.entity.AbstractFile) Folder(org.structr.web.entity.Folder)

Example 35 with AbstractFile

use of org.structr.web.entity.AbstractFile in project structr by structr.

the class DeployCommand method exportFileConfiguration.

private void exportFileConfiguration(final AbstractFile abstractFile, final Map<String, Object> config) {
    if (abstractFile.isVisibleToPublicUsers()) {
        putIf(config, "visibleToPublicUsers", true);
    }
    if (abstractFile.isVisibleToAuthenticatedUsers()) {
        putIf(config, "visibleToAuthenticatedUsers", true);
    }
    if (abstractFile instanceof File) {
        final File file = (File) abstractFile;
        if (file.isTemplate()) {
            putIf(config, "isTemplate", true);
        }
    }
    putIf(config, "type", abstractFile.getProperty(File.type));
    putIf(config, "contentType", abstractFile.getProperty(StructrApp.key(File.class, "contentType")));
    putIf(config, "cacheForSeconds", abstractFile.getProperty(StructrApp.key(File.class, "cacheForSeconds")));
    putIf(config, "useAsJavascriptLibrary", abstractFile.getProperty(StructrApp.key(File.class, "useAsJavascriptLibrary")));
    putIf(config, "includeInFrontendExport", abstractFile.getProperty(StructrApp.key(File.class, "includeInFrontendExport")));
    putIf(config, "basicAuthRealm", abstractFile.getProperty(StructrApp.key(File.class, "basicAuthRealm")));
    putIf(config, "enableBasicAuth", abstractFile.getProperty(StructrApp.key(File.class, "enableBasicAuth")));
    if (abstractFile instanceof Image) {
        final Image image = (Image) abstractFile;
        putIf(config, "isThumbnail", image.isThumbnail());
        putIf(config, "isImage", image.isImage());
        putIf(config, "width", image.getWidth());
        putIf(config, "height", image.getHeight());
    }
    if (abstractFile instanceof AbstractMinifiedFile) {
        if (abstractFile instanceof MinifiedCssFile) {
            final MinifiedCssFile mcf = (MinifiedCssFile) abstractFile;
            putIf(config, "lineBreak", mcf.getLineBreak());
        }
        if (abstractFile instanceof MinifiedJavaScriptFile) {
            final MinifiedJavaScriptFile mjf = (MinifiedJavaScriptFile) abstractFile;
            putIf(config, "optimizationLevel", mjf.getOptimizationLevel());
        }
        final Class<Relation> relType = StructrApp.getConfiguration().getRelationshipEntityClass("AbstractMinifiedFileMINIFICATIONFile");
        final PropertyKey<Integer> positionKey = StructrApp.key(relType, "position");
        final Map<Integer, String> minifcationSources = new TreeMap<>();
        for (Relation minificationSourceRel : AbstractMinifiedFile.getSortedRelationships((AbstractMinifiedFile) abstractFile)) {
            final File file = (File) minificationSourceRel.getTargetNode();
            minifcationSources.put(minificationSourceRel.getProperty(positionKey), file.getPath());
        }
        putIf(config, "minificationSources", minifcationSources);
    }
    // export all dynamic properties
    for (final PropertyKey key : StructrApp.getConfiguration().getPropertySet(abstractFile.getClass(), PropertyView.All)) {
        // only export dynamic (=> additional) keys
        if (!key.isPartOfBuiltInSchema()) {
            putIf(config, key.jsonName(), abstractFile.getProperty(key));
        }
    }
    exportOwnershipAndSecurity(abstractFile, config);
}
Also used : Image(org.structr.web.entity.Image) TreeMap(java.util.TreeMap) MinifiedCssFile(org.structr.web.entity.MinifiedCssFile) Relation(org.structr.core.entity.Relation) AbstractMinifiedFile(org.structr.web.entity.AbstractMinifiedFile) MinifiedJavaScriptFile(org.structr.web.entity.MinifiedJavaScriptFile) AbstractFile(org.structr.web.entity.AbstractFile) AbstractMinifiedFile(org.structr.web.entity.AbstractMinifiedFile) MinifiedCssFile(org.structr.web.entity.MinifiedCssFile) File(org.structr.web.entity.File) MinifiedJavaScriptFile(org.structr.web.entity.MinifiedJavaScriptFile) PropertyKey(org.structr.core.property.PropertyKey)

Aggregations

AbstractFile (org.structr.web.entity.AbstractFile)36 Folder (org.structr.web.entity.Folder)24 Tx (org.structr.core.graph.Tx)17 FrameworkException (org.structr.common.error.FrameworkException)16 App (org.structr.core.app.App)14 StructrApp (org.structr.core.app.StructrApp)14 File (org.structr.web.entity.File)10 PropertyMap (org.structr.core.property.PropertyMap)8 LinkedList (java.util.LinkedList)6 CMISRootFolder (org.structr.files.cmis.repository.CMISRootFolder)4 Path (java.nio.file.Path)3 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)3 PropertyKey (org.structr.core.property.PropertyKey)3 Image (org.structr.web.entity.Image)3 Map (java.util.Map)2 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)2 GraphObject (org.structr.core.GraphObject)2 AbstractNode (org.structr.core.entity.AbstractNode)2 NodeAttribute (org.structr.core.graph.NodeAttribute)2 FileNotFoundException (java.io.FileNotFoundException)1