Search in sources :

Example 1 with Folder

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

the class DeploymentTest method getRootFolder.

private Folder getRootFolder(final Folder folder) {
    Folder parent = folder;
    boolean root = false;
    while (parent != null && !root) {
        if (parent.getParent() != null) {
            parent = parent.getParent();
        } else {
            root = true;
        }
    }
    return parent;
}
Also used : Folder(org.structr.web.entity.Folder)

Example 2 with Folder

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

the class DeploymentTest method test36BuiltInTypesWithProperties.

@Test
public void test36BuiltInTypesWithProperties() {
    // setup schema
    try (final Tx tx = app.tx()) {
        final JsonSchema schema = StructrSchema.createFromDatabase(app);
        Assert.assertNotNull("StructrSchema must return a valid schema object", schema);
        final JsonType pageType = schema.getType("Page");
        final JsonType fileType = schema.getType("File");
        Assert.assertNotNull("Type Page must exist in every schema", pageType);
        Assert.assertNotNull("Type File must exist in every schema", fileType);
        pageType.addIntegerProperty("displayPosition");
        pageType.addStringProperty("icon");
        fileType.addIntegerProperty("test1");
        fileType.addStringProperty("test2");
        // install schema
        StructrSchema.replaceDatabaseSchema(app, schema);
        tx.success();
    } catch (FrameworkException | URISyntaxException fex) {
        fail("Unexpected exception.");
    }
    // setup
    try (final Tx tx = app.tx()) {
        final Page page = Page.createSimplePage(securityContext, "page1");
        page.setProperty(StructrApp.key(Page.class, "displayPosition"), 12);
        page.setProperty(StructrApp.key(Page.class, "icon"), "icon");
        final Folder folder = app.create(Folder.class, "files");
        folder.setProperty(StructrApp.key(Folder.class, "includeInFrontendExport"), true);
        // create test file with custom attributes
        app.create(File.class, new NodeAttribute<>(StructrApp.key(File.class, "name"), "test.txt"), new NodeAttribute<>(StructrApp.key(File.class, "parent"), folder), new NodeAttribute<>(StructrApp.key(File.class, "contentType"), "text/plain"), new NodeAttribute<>(StructrApp.key(File.class, "test1"), 123), new NodeAttribute<>(StructrApp.key(File.class, "test2"), "testString"));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    compare(calculateHash(), true);
}
Also used : JsonType(org.structr.schema.json.JsonType) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) JsonSchema(org.structr.schema.json.JsonSchema) Page(org.structr.web.entity.dom.Page) URISyntaxException(java.net.URISyntaxException) Folder(org.structr.web.entity.Folder) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 3 with Folder

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

the class DeploymentTest method test14FileAttributesInFolders.

@Test
public void test14FileAttributesInFolders() {
    final String folderPath = "/deeply/nested/Folder Structure/with spaces";
    final String fileName = "test14.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);
        tx.success();
    } catch (IOException | FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // test
    doImportExportRoundtrip(true);
    // 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 does not restore attributes correctly", folder, file.getParent());
        Assert.assertTrue("Deployment import does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "visibleToPublicUsers")));
        Assert.assertTrue("Deployment import does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "visibleToAuthenticatedUsers")));
        Assert.assertTrue("Deployment import does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "enableBasicAuth")));
        Assert.assertTrue("Deployment import does not restore attributes correctly", file.getProperty(StructrApp.key(File.class, "useAsJavascriptLibrary")));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) 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 4 with Folder

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

the class DeploymentTest method calculateHash.

private String calculateHash() {
    final StringBuilder buf = new StringBuilder();
    try (final Tx tx = app.tx()) {
        for (final Page page : app.nodeQuery(Page.class).sort(AbstractNode.name).getAsList()) {
            System.out.print("############################# ");
            calculateHash(page, buf, 0);
        }
        for (final Folder folder : app.nodeQuery(Folder.class).sort(AbstractNode.name).getAsList()) {
            if (DeployCommand.okToExport(folder) && folder.includeInFrontendExport()) {
                System.out.print("############################# ");
                calculateHash(folder, buf, 0);
            }
        }
        for (final File file : app.nodeQuery(File.class).sort(AbstractNode.name).getAsList()) {
            if (DeployCommand.okToExport(file) && file.includeInFrontendExport()) {
                System.out.print("############################# ");
                calculateHash(file, buf, 0);
            }
        }
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
    // DigestUtils.md5Hex(buf.toString());
    return buf.toString();
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Page(org.structr.web.entity.dom.Page) Folder(org.structr.web.entity.Folder) File(org.structr.web.entity.File)

Example 5 with Folder

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

the class DeploymentTest method test23FileOwnershipAndGrants.

@Test
public void test23FileOwnershipAndGrants() {
    Principal user1 = null;
    Principal user2 = null;
    try (final Tx tx = app.tx()) {
        user1 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
        user2 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
        tx.success();
    } catch (FrameworkException ex) {
        fail("Unexpected exception.");
    }
    Assert.assertNotNull("User was not created, test cannot continue", user1);
    Assert.assertNotNull("User was not created, test cannot continue", user2);
    // setup
    try (final Tx tx = app.tx()) {
        // create some files and folders
        final Folder folder1 = app.create(Folder.class, new NodeAttribute<>(Folder.name, "Folder1"), new NodeAttribute<>(StructrApp.key(Folder.class, "includeInFrontendExport"), true));
        final Folder folder2 = app.create(Folder.class, new NodeAttribute<>(Folder.name, "Folder2"), new NodeAttribute<>(StructrApp.key(Folder.class, "parent"), folder1));
        final File file1 = FileHelper.createFile(securityContext, "test".getBytes(), "text/plain", File.class, "test1.txt");
        final File file2 = FileHelper.createFile(securityContext, "test".getBytes(), "text/plain", File.class, "test2.txt");
        file1.setParent(folder2);
        file2.setParent(folder2);
        folder1.setProperty(Folder.owner, user1);
        folder1.grant(Permission.read, user2);
        folder2.setProperty(Folder.owner, user2);
        folder2.grant(Permission.write, user1);
        file1.setProperty(File.owner, user1);
        file2.setProperty(File.owner, user2);
        file1.setProperty(Folder.owner, user1);
        file1.grant(Permission.read, user2);
        file2.setProperty(Folder.owner, user2);
        file2.grant(Permission.write, user1);
        tx.success();
    } catch (IOException | FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    doImportExportRoundtrip(true, true, new Function() {

        @Override
        public Object apply(Object t) {
            try (final Tx tx = app.tx()) {
                createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
                createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
                tx.success();
            } catch (FrameworkException ex) {
                fail("Unexpected exception.");
            }
            return null;
        }
    });
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) IOException(java.io.IOException) Folder(org.structr.web.entity.Folder) Function(java.util.function.Function) GraphObject(org.structr.core.GraphObject) File(org.structr.web.entity.File) Principal(org.structr.core.entity.Principal) 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