use of org.structr.web.entity.Folder in project structr by structr.
the class ConsoleTest method testUserCommand.
@Test
public void testUserCommand() {
final Console console = new Console(securityContext, ConsoleMode.JavaScript, Collections.emptyMap());
Principal admin = null;
try {
assertEquals("Invalid console execution result", "Mode set to 'AdminShell'. Type 'help' to get a list of commands.\r\n", console.runForTest("Console.setMode('" + ConsoleMode.AdminShell.name() + "')"));
assertEquals("Invalid console execution result", "\r\n", console.runForTest("user list"));
// create a user
assertEquals("Invalid console execution result", "User created.\r\n", console.runForTest("user add tester tester@test.de"));
assertEquals("Invalid console execution result", "User created.\r\n", console.runForTest("user add admin admin@localhost isAdmin"));
assertEquals("Invalid console execution result", "User created.\r\n", console.runForTest("user add root isAdmin"));
// check success
try (final Tx tx = app.tx()) {
final User user = app.nodeQuery(User.class).andName("tester").getFirst();
assertNotNull("Invalid console execution result", user);
assertEquals("Invalid console execution result", "tester", user.getProperty(User.name));
assertEquals("Invalid console execution result", "tester@test.de", user.getEMail());
assertEquals("Invalid console execution result", Boolean.FALSE, user.isAdmin());
tx.success();
}
// check list
assertEquals("Invalid console execution result", "admin, root, tester\r\n", console.runForTest("user list"));
// delete user
assertEquals("Invalid console execution result", "User deleted.\r\n", console.runForTest("user delete tester"));
// check list
assertEquals("Invalid console execution result", "admin, root\r\n", console.runForTest("user list"));
// check "root" user
try (final Tx tx = app.tx()) {
final User root = app.nodeQuery(User.class).andName("root").getFirst();
assertNotNull("Invalid console execution result", root);
assertEquals("Invalid console execution result", "root", root.getProperty(User.name));
assertEquals("Invalid console execution result", Boolean.TRUE, root.isAdmin());
tx.success();
}
// make check "admin" user
try (final Tx tx = app.tx()) {
admin = app.nodeQuery(User.class).andName("admin").getFirst();
assertNotNull("Invalid console execution result", admin);
assertEquals("Invalid console execution result", "admin", admin.getProperty(User.name));
assertEquals("Invalid console execution result", "admin@localhost", admin.getEMail());
assertEquals("Invalid console execution result", Boolean.TRUE, admin.isAdmin());
final Folder folder = app.create(Folder.class, "folder");
folder.setProperties(folder.getSecurityContext(), new PropertyMap(Folder.owner, admin));
tx.success();
}
final String idHash = admin.getUuid().substring(7, 11);
// delete user without confirmation
assertEquals("Invalid console execution result", "User 'admin' has owned nodes, please confirm deletion with 'user delete admin " + idHash + "'.\r\n", console.runForTest("user delete admin"));
// delete user with confirmation
assertEquals("Invalid console execution result", "User deleted.\r\n", console.runForTest("user delete admin " + idHash));
// check list
assertEquals("Invalid console execution result", "root\r\n", console.runForTest("user list"));
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
use of org.structr.web.entity.Folder in project structr by structr.
the class FileHelper method createFolderPath.
/**
* Create one folder per path item and return the last folder.
*
* F.e.: /a/b/c => Folder["name":"a"] --HAS_CHILD--> Folder["name":"b"]
* --HAS_CHILD--> Folder["name":"c"], returns Folder["name":"c"]
*
* @param securityContext
* @param path
* @return folder
* @throws FrameworkException
*/
public static Folder createFolderPath(final SecurityContext securityContext, final String path) throws FrameworkException {
final App app = StructrApp.getInstance(securityContext);
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) {
folder = app.create(Folder.class, part);
}
if (parent != null) {
folder.setParent(parent);
}
}
return folder;
}
use of org.structr.web.entity.Folder in project structr by structr.
the class FileHelper method getChecksums.
/**
* Calculate checksums that are configured in settings of parent folder.
*
* @param file
* @param fileOnDisk
* @return
* @throws IOException
*/
private static PropertyMap getChecksums(final File file, final java.io.File fileOnDisk) throws IOException {
final PropertyMap propertiesWithChecksums = new PropertyMap();
Folder parentFolder = file.getParent();
String checksums = null;
while (parentFolder != null && checksums == null) {
checksums = parentFolder.getEnabledChecksums();
parentFolder = parentFolder.getParent();
}
if (checksums == null) {
checksums = Settings.DefaultChecksums.getValue();
}
// New, very fast xxHash default checksum, will always be calculated
propertiesWithChecksums.put(StructrApp.key(File.class, "checksum"), FileHelper.getChecksum(fileOnDisk));
if (StringUtils.contains(checksums, "crc32")) {
propertiesWithChecksums.put(StructrApp.key(File.class, "crc32"), FileHelper.getChecksum(fileOnDisk));
}
if (StringUtils.contains(checksums, "md5")) {
propertiesWithChecksums.put(StructrApp.key(File.class, "md5"), FileHelper.getMD5Checksum(file));
}
if (StringUtils.contains(checksums, "sha1")) {
propertiesWithChecksums.put(StructrApp.key(File.class, "sha1"), FileHelper.getSHA1Checksum(file));
}
if (StringUtils.contains(checksums, "sha512")) {
propertiesWithChecksums.put(StructrApp.key(File.class, "sha512"), FileHelper.getSHA512Checksum(file));
}
return propertiesWithChecksums;
}
use of org.structr.web.entity.Folder in project structr by structr.
the class CMISNavigationService method recursivelyCollectFolderTree.
// ----- private methods -----
private void recursivelyCollectFolderTree(final List<ObjectInFolderContainer> list, final Folder child, final int maxDepth, final int depth, final Boolean includeAllowableActions) throws FrameworkException {
if (depth > maxDepth) {
return;
}
final CMISObjectInFolderWrapper wrapper = new CMISObjectInFolderWrapper(includeAllowableActions);
final ObjectInFolderContainerImpl impl = new ObjectInFolderContainerImpl();
final List<ObjectInFolderContainer> childContainerList = new LinkedList<>();
final String pathSegment = child.getName();
impl.setObject(wrapper.wrapObjectData(wrapper.wrapGraphObject(child), pathSegment));
impl.setChildren(childContainerList);
// add wrapped object to current list
list.add(impl);
// fetch and sort children
final List<Folder> children = Iterables.toList(child.getFolders());
Collections.sort(children, new GraphObjectComparator(AbstractNode.name, false));
// descend into children
for (final Folder folderChild : children) {
recursivelyCollectFolderTree(childContainerList, folderChild, maxDepth, depth + 1, includeAllowableActions);
}
}
use of org.structr.web.entity.Folder in project structr by structr.
the class CMISNavigationService method recursivelyCollectDescendants.
private void recursivelyCollectDescendants(final List<ObjectInFolderContainer> list, final AbstractFile child, final int maxDepth, final int depth, final Boolean includeAllowableActions) throws FrameworkException {
if (depth > maxDepth) {
return;
}
final PropertyKey<Folder> parent = StructrApp.key(AbstractFile.class, "parent");
final PropertyKey<Boolean> hasParent = StructrApp.key(AbstractFile.class, "hasParent");
final PropertyKey<Boolean> isThumbnail = StructrApp.key(Image.class, "isThumbnail");
final CMISObjectInFolderWrapper wrapper = new CMISObjectInFolderWrapper(includeAllowableActions);
final ObjectInFolderContainerImpl impl = new ObjectInFolderContainerImpl();
final List<ObjectInFolderContainer> childContainerList = new LinkedList<>();
final String pathSegment = child.getName();
impl.setObject(wrapper.wrapObjectData(wrapper.wrapGraphObject(child), pathSegment));
impl.setChildren(childContainerList);
// add wrapped object to current list
list.add(impl);
if (child.getProperty(AbstractNode.type).equals("Folder")) {
final App app = StructrApp.getInstance();
// descend into children
for (final AbstractFile folderChild : app.nodeQuery(AbstractFile.class).sort(AbstractNode.name).and(parent, (Folder) child).and(isThumbnail, false).getAsList()) {
recursivelyCollectDescendants(childContainerList, folderChild, maxDepth, depth + 1, includeAllowableActions);
}
}
}
Aggregations