Search in sources :

Example 71 with Folder

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

the class JavaParserModule method parseFolder.

private void parseFolder(final Folder folder, final int depth, final Folder parentFolder) {
    logger.info("Parsing folder " + folder.getName() + ", depth " + depth);
    // Handle folder itself
    readPomAndPackageInfoFile(folder, parentFolder);
    // Handle all direct file children of this folder
    parseJavaFilesAndSolveTypes(folder);
    // Handle subfolders of this folder
    for (final Folder subfolder : folder.getFolders()) {
        parseFolder(subfolder, depth + 1, folder);
    }
}
Also used : Folder(org.structr.web.entity.Folder)

Example 72 with Folder

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

the class DeploymentTest method test15FileAttributesOnUpdate.

@Test
public void test15FileAttributesOnUpdate() {
    final String folderPath = "/deeply/nested/Folder Structure/with spaces";
    final String fileName = "test15.txt";
    // setup
    try (final Tx tx = app.tx()) {
        final Folder folder = FileHelper.createFolderPath(securityContext, folderPath);
        final File file = FileHelper.createFile(securityContext, "test".getBytes("utf-8"), "text/plain", File.class, fileName);
        final Folder rootFolder = getRootFolder(folder);
        Assert.assertNotNull("Root folder should not be null", rootFolder);
        // root folder needs to have "includeInFrontendExport" set
        rootFolder.setProperty(StructrApp.key(Folder.class, "includeInFrontendExport"), true);
        file.setProperty(StructrApp.key(File.class, "parent"), folder);
        file.setProperty(StructrApp.key(File.class, "visibleToPublicUsers"), true);
        file.setProperty(StructrApp.key(File.class, "visibleToAuthenticatedUsers"), true);
        file.setProperty(StructrApp.key(File.class, "enableBasicAuth"), true);
        file.setProperty(StructrApp.key(File.class, "useAsJavascriptLibrary"), true);
        file.setProperty(StructrApp.key(File.class, "includeInFrontendExport"), true);
        tx.success();
    } catch (IOException | FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // test, don't clean the database but modify the file flags
    doImportExportRoundtrip(true, false, new Function() {

        @Override
        public Object apply(Object t) {
            try (final Tx tx = app.tx()) {
                final File file = app.nodeQuery(File.class).and(File.name, fileName).getFirst();
                file.setProperty(StructrApp.key(File.class, "visibleToPublicUsers"), false);
                file.setProperty(StructrApp.key(File.class, "visibleToAuthenticatedUsers"), false);
                file.setProperty(StructrApp.key(File.class, "enableBasicAuth"), false);
                file.setProperty(StructrApp.key(File.class, "useAsJavascriptLibrary"), false);
                file.setProperty(StructrApp.key(File.class, "includeInFrontendExport"), false);
                tx.success();
            } catch (FrameworkException fex) {
            }
            return null;
        }
    });
    // check
    try (final Tx tx = app.tx()) {
        final Folder folder = app.nodeQuery(Folder.class).andName("with spaces").getFirst();
        Assert.assertNotNull("Invalid deployment result", folder);
        final File file = app.nodeQuery(File.class).and(StructrApp.key(File.class, "parent"), folder).and(File.name, fileName).getFirst();
        Assert.assertNotNull("Invalid deployment result", file);
        Assert.assertEquals("Deployment import of existing file does not restore attributes correctly", folder, file.getParent());
        Assert.assertTrue("Deployment import of existing file does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "visibleToPublicUsers")));
        Assert.assertTrue("Deployment import of existing file does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "visibleToAuthenticatedUsers")));
        Assert.assertTrue("Deployment import of existing file does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "enableBasicAuth")));
        Assert.assertTrue("Deployment import of existing file does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "useAsJavascriptLibrary")));
        Assert.assertTrue("Deployment import of existing file does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "includeInFrontendExport")));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : Function(java.util.function.Function) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) GraphObject(org.structr.core.GraphObject) IOException(java.io.IOException) Folder(org.structr.web.entity.Folder) File(org.structr.web.entity.File) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 73 with Folder

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

the class DeploymentTest method test39EmptyFolderInDeployment.

@Test
public void test39EmptyFolderInDeployment() {
    final String folderPath = "/empty/folders/in/filesystem";
    // setup
    try (final Tx tx = app.tx()) {
        final Folder folder = FileHelper.createFolderPath(securityContext, folderPath);
        final Folder rootFolder = getRootFolder(folder);
        Assert.assertNotNull("Root folder should not be null", rootFolder);
        // root folder needs to have "includeInFrontendExport" set
        rootFolder.setProperty(StructrApp.key(Folder.class, "includeInFrontendExport"), true);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    doImportExportRoundtrip(true, true, null);
    // check
    try (final Tx tx = app.tx()) {
        final Folder folder = app.nodeQuery(Folder.class).andName("filesystem").getFirst();
        Assert.assertNotNull("Invalid deployment result - empty folder from export was not imported!", folder);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 74 with Folder

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

the class FilesystemTest method test03UserHomeDirectory.

@Test
public void test03UserHomeDirectory() {
    Settings.FilesystemEnabled.setValue(true);
    try (final Tx tx = app.tx()) {
        app.create(User.class, "tester");
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final User tester = app.nodeQuery(User.class).andName("tester").getFirst();
        tester.setEMail("tester@structr.com");
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final User tester = app.nodeQuery(User.class).andName("tester").getFirst();
        tester.setEMail("tester2@structr.com");
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final User tester = app.nodeQuery(User.class).andName("tester").getFirst();
        tester.setEMail("tester3@structr.com");
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final User tester = app.nodeQuery(User.class).andName("tester").getFirst();
        final List<Folder> dirs = app.nodeQuery(Folder.class).getAsList();
        final Set<String> names = new HashSet<>();
        // there should only be two directories: home, and the home directory of the user
        assertEquals("Too many directories exist after modifying a user", 2, dirs.size());
        for (final Folder folder : dirs) {
            names.add(folder.getName());
        }
        // check for "home" directory
        assertTrue("A directory named 'home' must exist", names.contains("home"));
        // check for user home directory (which has the user's UUID as its name)
        assertTrue("A directory named 'home' must exist", names.contains(tester.getUuid()));
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception.");
    }
}
Also used : User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) Folder(org.structr.web.entity.Folder) HashSet(java.util.HashSet) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 75 with Folder

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

the class UiScriptingTest method testSpecialHeaders.

@Test
public void testSpecialHeaders() {
    String uuid = null;
    // schema setup
    try (final Tx tx = app.tx()) {
        // create list of 100 folders
        final List<Folder> folders = new LinkedList<>();
        for (int i = 0; i < 100; i++) {
            folders.add(createTestNode(Folder.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Folder" + i)));
        }
        // create parent folder
        final Folder parent = createTestNode(Folder.class, new NodeAttribute<>(StructrApp.key(AbstractNode.class, "name"), "Parent"), new NodeAttribute<>(StructrApp.key(Folder.class, "folders"), folders));
        uuid = parent.getUuid();
        // create function property that returns folder children
        final SchemaNode schemaNode = app.nodeQuery(SchemaNode.class).andName("Folder").getFirst();
        schemaNode.setProperty(new StringProperty("_testFunction"), "Function(this.folders)");
        // create admin user
        createTestNode(User.class, new NodeAttribute<>(StructrApp.key(User.class, "name"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "password"), "admin"), new NodeAttribute<>(StructrApp.key(User.class, "isAdmin"), true));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception");
    }
    RestAssured.basePath = "/structr/rest";
    RestAssured.given().contentType("application/json; charset=UTF-8").accept("application/json; properties=id,type,name,folders,testFunction").header("Range", "folders=0-10;testFunction=0-10").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", "admin", "X-Password", "admin").expect().statusCode(200).body("result.folders", Matchers.hasSize(10)).body("result.testFunction", Matchers.hasSize(10)).when().get("/Folder/" + uuid + "/ui");
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) SchemaNode(org.structr.core.entity.SchemaNode) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) StringProperty(org.structr.core.property.StringProperty) Folder(org.structr.web.entity.Folder) LinkedList(java.util.LinkedList) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Folder (org.structr.web.entity.Folder)95 Tx (org.structr.core.graph.Tx)64 FrameworkException (org.structr.common.error.FrameworkException)60 AbstractFile (org.structr.web.entity.AbstractFile)42 App (org.structr.core.app.App)35 StructrApp (org.structr.core.app.StructrApp)35 File (org.structr.web.entity.File)34 Test (org.junit.Test)23 StructrUiTest (org.structr.web.StructrUiTest)21 IOException (java.io.IOException)20 PropertyMap (org.structr.core.property.PropertyMap)16 Path (java.nio.file.Path)14 LinkedList (java.util.LinkedList)10 NodeAttribute (org.structr.core.graph.NodeAttribute)9 InputStream (java.io.InputStream)5 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)5 CMISRootFolder (org.structr.files.cmis.repository.CMISRootFolder)5 User (org.structr.web.entity.User)5 Page (org.structr.web.entity.dom.Page)5 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)4