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