Search in sources :

Example 26 with AbstractFile

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

the class LsCommand method listFolder.

// ----- private methods -----
private void listFolder(final StructrShellCommand parent, final Iterable<AbstractFile> folder) throws FrameworkException, IOException {
    boolean hasContents = false;
    for (final AbstractFile child : folder) {
        if (parent.isAllowed(child, Permission.read, false)) {
            hasContents = true;
            if (child instanceof Folder) {
                term.setBold(true);
                term.setTextColor(4);
                term.print(child.getName() + "  ");
                term.setTextColor(7);
                term.setBold(false);
            } else {
                term.print(child.getName() + "  ");
            }
        }
    }
    if (hasContents) {
        term.println();
    }
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) Folder(org.structr.web.entity.Folder)

Example 27 with AbstractFile

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

the class FtpTest method createFTPFile.

protected File createFTPFile(final String path, final String name) throws FrameworkException {
    PropertyMap props = new PropertyMap();
    props.put(StructrApp.key(File.class, "name"), name);
    props.put(StructrApp.key(File.class, "size"), 0L);
    props.put(StructrApp.key(File.class, "owner"), ftpUser);
    File file = (File) createTestNodes(File.class, 1, props).get(0);
    if (StringUtils.isNotBlank(path)) {
        AbstractFile parent = FileHelper.getFileByAbsolutePath(securityContext, path);
        if (parent != null && parent instanceof Folder) {
            Folder parentFolder = (Folder) parent;
            file.setParent(parentFolder);
        }
    }
    logger.info("FTP file {} created successfully.", file);
    return file;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) AbstractFile(org.structr.web.entity.AbstractFile) Folder(org.structr.web.entity.Folder) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File) FTPFile(org.apache.commons.net.ftp.FTPFile)

Example 28 with AbstractFile

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

the class FtpTest method createFTPDirectory.

protected Folder createFTPDirectory(final String path, final String name) throws FrameworkException {
    PropertyMap props = new PropertyMap();
    props.put(Folder.name, name);
    props.put(Folder.owner, ftpUser);
    Folder dir = (Folder) createTestNodes(Folder.class, 1, props).get(0);
    if (StringUtils.isNotBlank(path)) {
        AbstractFile parent = FileHelper.getFileByAbsolutePath(securityContext, path);
        if (parent != null && parent instanceof Folder) {
            Folder parentFolder = (Folder) parent;
            dir.setParent(parentFolder);
        }
    }
    logger.info("FTP directory {} created successfully.", dir);
    return dir;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) AbstractFile(org.structr.web.entity.AbstractFile) Folder(org.structr.web.entity.Folder)

Example 29 with AbstractFile

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

the class UnarchiveCommand method handleFile.

private void handleFile(final SecurityContext securityContext, final InputStream in, final Folder existingParentFolder, final String entryPath) throws FrameworkException, IOException {
    final PropertyKey<Folder> parentKey = StructrApp.key(AbstractFile.class, "parent");
    final PropertyKey<Boolean> hasParentKey = StructrApp.key(AbstractFile.class, "hasParent");
    final String filePath = (existingParentFolder != null ? existingParentFolder.getPath() : "") + PathHelper.PATH_SEP + PathHelper.clean(entryPath);
    final String name = PathHelper.getName(entryPath);
    final AbstractFile newFile = ImageHelper.isImageType(name) ? ImageHelper.createImage(securityContext, in, null, Image.class, name, false) : FileHelper.createFile(securityContext, in, null, File.class, name);
    final String folderPath = StringUtils.substringBeforeLast(filePath, PathHelper.PATH_SEP);
    final Folder parentFolder = FileHelper.createFolderPath(securityContext, folderPath);
    if (parentFolder != null) {
        final PropertyMap properties = new PropertyMap();
        properties.put(parentKey, parentFolder);
        properties.put(hasParentKey, true);
        newFile.setProperties(securityContext, properties);
    }
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) PropertyMap(org.structr.core.property.PropertyMap) Folder(org.structr.web.entity.Folder) Image(org.structr.web.entity.Image) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File) SevenZFile(org.apache.commons.compress.archivers.sevenz.SevenZFile)

Example 30 with AbstractFile

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

the class CMISNavigationService method recursivelyCollectDescendants.

private void recursivelyCollectDescendants(final List<ObjectInFolderContainer> list, final AbstractFile child, final int maxDepth, final int depth, final Boolean includeAllowableActions) throws FrameworkException {
    if (depth > maxDepth) {
        return;
    }
    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");
    final CMISObjectInFolderWrapper wrapper = new CMISObjectInFolderWrapper(includeAllowableActions);
    final ObjectInFolderContainerImpl impl = new ObjectInFolderContainerImpl();
    final List<ObjectInFolderContainer> childContainerList = new LinkedList<>();
    final String pathSegment = child.getName();
    impl.setObject(wrapper.wrapObjectData(wrapper.wrapGraphObject(child), pathSegment));
    impl.setChildren(childContainerList);
    // add wrapped object to current list
    list.add(impl);
    if (child.getProperty(AbstractNode.type).equals("Folder")) {
        final App app = StructrApp.getInstance();
        // descend into children
        for (final AbstractFile folderChild : app.nodeQuery(AbstractFile.class).sort(AbstractNode.name).and(parent, (Folder) child).and(isThumbnail, false).getAsList()) {
            recursivelyCollectDescendants(childContainerList, folderChild, maxDepth, depth + 1, includeAllowableActions);
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) AbstractFile(org.structr.web.entity.AbstractFile) ObjectInFolderContainerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderContainerImpl) CMISObjectInFolderWrapper(org.structr.files.cmis.wrapper.CMISObjectInFolderWrapper) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer) LinkedList(java.util.LinkedList)

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