Search in sources :

Example 1 with AbstractFile

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

the class FileImportVisitor method handleDeferredFiles.

public void handleDeferredFiles() {
    final Class<Relation> relType = StructrApp.getConfiguration().getRelationshipEntityClass("AbstractMinifiedFileMINIFICATIONFile");
    final PropertyKey<Integer> positionKey = StructrApp.key(relType, "position");
    if (!this.deferredFiles.isEmpty()) {
        for (File file : this.deferredFiles) {
            try (final Tx tx = app.tx(true, false, false)) {
                // set properties from files.json
                final PropertyMap fileProperties = getPropertiesForFileOrFolder(file.getPath());
                final PropertyKey<Map<String, String>> sourcesPropertyKey = new GenericProperty("minificationSources");
                Map<String, String> sourcesConfig = fileProperties.get(sourcesPropertyKey);
                fileProperties.remove(sourcesPropertyKey);
                file.unlockSystemPropertiesOnce();
                file.setProperties(securityContext, fileProperties);
                for (String positionString : sourcesConfig.keySet()) {
                    final Integer position = Integer.parseInt(positionString);
                    final String sourcePath = sourcesConfig.get(positionString);
                    final AbstractFile source = FileHelper.getFileByAbsolutePath(securityContext, sourcePath);
                    if (source != null) {
                        app.create(app.get(AbstractMinifiedFile.class, file.getUuid()), (File) source, relType, new PropertyMap(positionKey, position));
                    } else {
                        logger.warn("Source file {} for minified file {} at position {} not found - please verify that it is included in the export", sourcePath, file.getPath(), positionString);
                    }
                }
                tx.success();
            } catch (FrameworkException fxe) {
            }
        }
    }
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Relation(org.structr.core.entity.Relation) PropertyMap(org.structr.core.property.PropertyMap) GenericProperty(org.structr.core.property.GenericProperty) AbstractMinifiedFile(org.structr.web.entity.AbstractMinifiedFile) AbstractFile(org.structr.web.entity.AbstractFile) AbstractMinifiedFile(org.structr.web.entity.AbstractMinifiedFile) File(org.structr.web.entity.File) HashMap(java.util.HashMap) PropertyMap(org.structr.core.property.PropertyMap) Map(java.util.Map)

Example 2 with AbstractFile

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

the class PathProperty method searchRecursively.

private void searchRecursively(final App app, final Folder parent, final SourceSearchAttribute attr, final ArrayList<String> parts) throws FrameworkException {
    final String currentPart = parts.remove(0);
    final List<AbstractFile> res = app.nodeQuery(AbstractFile.class).and(StructrApp.key(AbstractFile.class, "parent"), (parent == null) ? null : parent).and(AbstractFile.name, currentPart).getAsList();
    if (parts.isEmpty()) {
        for (final AbstractFile fileOrFolder : res) {
            attr.addToResult(fileOrFolder);
        }
    } else {
        for (final AbstractFile folder : res) {
            searchRecursively(app, (Folder) folder, attr, (ArrayList<String>) parts.clone());
        }
    }
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile)

Example 3 with AbstractFile

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

the class SSHTest 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 4 with AbstractFile

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

the class SSHTest 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 5 with AbstractFile

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

the class FileOrFolder method mkdir.

@Override
public boolean mkdir() {
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        logger.info("mkdir() Folder");
        AbstractFile existing = FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), newPath);
        if (existing != null) {
            logger.warn("File {} already exists.", newPath);
            return false;
        }
        final Folder parentFolder = (Folder) FileHelper.getFileByAbsolutePath(securityContext, StringUtils.substringBeforeLast(newPath, "/"));
        try {
            Folder newFolder = (Folder) app.command(CreateNodeCommand.class).execute(new NodeAttribute(AbstractNode.type, Folder.class.getSimpleName()), new NodeAttribute(AbstractNode.owner, owner.getStructrUser()), new NodeAttribute(AbstractNode.name, getName()));
            if (parentFolder != null) {
                newFolder.setParent(parentFolder);
            }
        } catch (FrameworkException ex) {
            logger.error("", ex);
            return false;
        }
        tx.success();
        return true;
    } catch (FrameworkException ex) {
        logger.error("", ex);
        return false;
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NodeAttribute(org.structr.core.graph.NodeAttribute) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder)

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