Package org.structr.web.entity

Examples of org.structr.web.entity.Folder


          String newParentPath = StringUtils.substringBeforeLast(path, "/");
          AbstractFile newParent = FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), newParentPath);

          if (newParent != null && newParent instanceof Folder) {

            Folder newParentFolder = (Folder) newParent;
            structrFile.setProperty(AbstractFile.parent, newParentFolder);

          } else {

            // Move to /
View Full Code Here


          fileNode = createFileNode(uuid, fileName, ct, size, checksum);
        }

        if (fileNode != null) {

          Folder parent = FileHelper.createFolderPath(securityContext, path);

          if (parent != null) {

            fileNode.setProperty(File.parent, parent);
View Full Code Here

      name = doc.getName();

      assertEquals(7, folders.size());

      Folder rootNode = folders.get(0);
      rootNode.setProperty(AbstractNode.name, "rootNode");
      Folder folderA = folders.get(1);
      folderA.setProperty(AbstractNode.name, "folderA");
      Folder folderB = folders.get(2);
      folderB.setProperty(AbstractNode.name, "folderB");
      Folder folderC = folders.get(3);
      folderC.setProperty(AbstractNode.name, "folderC");
      Folder folderD = folders.get(4);
      folderD.setProperty(AbstractNode.name, "folderD");
      Folder folderE = folders.get(5);
      folderE.setProperty(AbstractNode.name, "folderE");
      Folder folderF = folders.get(6);
      folderF.setProperty(AbstractNode.name, "folderF");

      File file1 = files.get(0);
      file1.setProperty(AbstractNode.name, "file1");
      File file2 = files.get(1);
      file2.setProperty(AbstractNode.name, "file2");
View Full Code Here

  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.getSuperUserInstance(), path);
      if (parent != null && parent instanceof Folder) {
        Folder parentFolder = (Folder) parent;
        dir.setProperty(Folder.parent, parentFolder);
      }
    }

    logger.log(Level.INFO, "FTP directory {0} created successfully.", dir);
View Full Code Here

    File file = (File) createTestNodes(File.class, 1, props).get(0);

    if (StringUtils.isNotBlank(path)) {
      AbstractFile parent = FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), path);
      if (parent != null && parent instanceof Folder) {
        Folder parentFolder = (Folder) parent;
        file.setProperty(Folder.parent, parentFolder);
      }
    }

    logger.log(Level.INFO, "FTP file {0} created successfully.", file);
View Full Code Here

 
  public void testCreateFolder() {
   
    try (final Tx tx = app.tx()) {
     
      Folder test4 = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), "/a/a");
      Folder test3 = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), "/c/b/a");
      Folder test2 = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), "/b/a");
      Folder test1 = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), "/a/b/c");
           
      tx.success();
     
    } catch (FrameworkException ex) {
      Logger.getLogger(FolderTest.class.getName()).log(Level.SEVERE, null, ex);
    }

    try (final Tx tx = app.tx()) {
     
      Folder a = (Folder) FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), "/a");
      assertNotNull(a);
      assertEquals(FileHelper.getFolderPath(a), "/a");
     
      Folder b = (Folder) FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), "/a/b");
      assertNotNull(b);
      assertEquals(FileHelper.getFolderPath(b), "/a/b");
     
      Folder c = (Folder) FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), "/a/b/c");
      assertNotNull(c);
      assertEquals(FileHelper.getFolderPath(c), "/a/b/c");
           
    } catch (FrameworkException ex) {
      Logger.getLogger(FolderTest.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

    if (path == null) {

      return null;
    }

    Folder folder = (Folder) FileHelper.getFileByAbsolutePath(securityContext, path);

    if (folder != null) {
      return folder;
    }

    String[] parts = PathHelper.getParts(path);
    String partialPath = "";

    for (String part : parts) {

      // ignore ".." and "." in paths
      if ("..".equals(part) || ".".equals(part)) {
        continue;
      }

      Folder parent = folder;

      partialPath += PathHelper.PATH_SEP + part;
      folder = (Folder) FileHelper.getFileByAbsolutePath(securityContext, partialPath);

      if (folder == null) {
View Full Code Here

      if (existing != null) {
        logger.log(Level.WARNING, "File {0} already exists.", newPath);
        return false;
      }

      final Folder parentFolder = (Folder) FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), StringUtils.substringBeforeLast(newPath, "/"));

      try {
        Folder newFolder = (Folder) StructrApp.getInstance().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.setProperty(AbstractFile.parent, parentFolder);
        }

      } catch (FrameworkException ex) {
        logger.log(Level.SEVERE, null, ex);
        return false;
View Full Code Here

    try (Tx tx = StructrApp.getInstance().tx()) {

      if (structrFile == null) {

        final Folder parentFolder = (Folder) FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), StringUtils.substringBeforeLast(newPath, "/"));

        try {
          structrFile = FileHelper.createFile(SecurityContext.getSuperUserInstance(), new byte[0], null, File.class, getName());
          structrFile.setProperty(AbstractNode.type, File.class.getSimpleName());
          structrFile.setProperty(AbstractNode.owner, owner.getStructrUser());
View Full Code Here

      return null;
    }

    // Find root folder
    final App app = StructrApp.getInstance(securityContext);
    Folder folder = null;
    for (final Folder possibleRootFolder : app.nodeQuery(Folder.class).andName(parts[0])) {

      if (possibleRootFolder.getProperty(Folder.parent) == null) {
        folder = possibleRootFolder;
        break;
      }

    }

    if (folder == null) {

      // Root folder doesn't exist, so create it and all child folders
      folder = app.create(Folder.class, parts[0]);
      logger.log(Level.INFO, "Created root folder {0}", new Object[]{parts[0]});

      for (int i = 1; i < parts.length - 1; i++) {
        Folder childFolder = app.create(Folder.class, parts[i]);
        childFolder.setProperty(Folder.parent, folder);
        logger.log(Level.INFO, "Created {0} {1} with path {2}", new Object[]{childFolder.getType(), childFolder, FileHelper.getFolderPath(childFolder)});
        folder = childFolder;
      }

      return folder;

    }

    // Root folder exists, so walk over children and search for next path part
    for (int i = 1; i < parts.length - 1; i++) {

      Folder subFolder = null;

      for (AbstractFile child : folder.getProperty(Folder.children)) {

        if (child instanceof Folder && child.getName().equals(parts[i])) {
          subFolder = (Folder) child;
          break;
        }

      }

      if (subFolder == null) {

        // sub folder doesn't exist, so create it and all child folders
        subFolder = app.create(Folder.class, parts[i]);
        subFolder.setProperty(Folder.parent, folder);
        logger.log(Level.INFO, "Created {0} {1} with path {2}", new Object[]{subFolder.getType(), subFolder, FileHelper.getFolderPath(subFolder)});

      }

      folder = subFolder;
    }
View Full Code Here

TOP

Related Classes of org.structr.web.entity.Folder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.