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;
}
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);
}
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.");
}
}
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();
}
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;
}
});
}
Aggregations