use of org.structr.web.entity.Folder in project structr by structr.
the class CMISNavigationService method getFolderParent.
@Override
public ObjectData getFolderParent(final String repositoryId, final String folderId, final String propertyFilter, final ExtensionsData extension) {
final App app = StructrApp.getInstance();
ObjectData result = null;
try (final Tx tx = app.tx()) {
final AbstractFile graphObject = app.get(AbstractFile.class, folderId);
if (graphObject != null) {
final Folder parent = graphObject.getParent();
if (parent != null) {
result = CMISObjectWrapper.wrap(parent, propertyFilter, false);
}
}
tx.success();
} catch (Throwable t) {
logger.warn("", t);
}
if (result != null) {
return result;
}
return null;
}
use of org.structr.web.entity.Folder in project structr by structr.
the class CMISNavigationService method getChildrenQuery.
public Query<AbstractFile> getChildrenQuery(final App app, final String folderId) throws FrameworkException {
final Query<AbstractFile> query = app.nodeQuery(AbstractFile.class).sort(AbstractNode.name);
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");
if (CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
query.and(hasParent, false).and(isThumbnail, false);
} else {
final Folder folder = app.get(Folder.class, folderId);
if (folder != null) {
query.and(parent, folder).and(isThumbnail, false);
} else {
throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
}
}
return query;
}
use of org.structr.web.entity.Folder in project structr by structr.
the class CMISNavigationService method getFolderTree.
@Override
public List<ObjectInFolderContainer> getFolderTree(final String repositoryId, final String folderId, final BigInteger depth, final String filter, final Boolean includeAllowableActions, final IncludeRelationships includeRelationships, final String renditionFilter, final Boolean includePathSegment, final ExtensionsData extension) {
final PropertyKey<Folder> parentKey = StructrApp.key(AbstractFile.class, "parent");
final List<ObjectInFolderContainer> result = new LinkedList<>();
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
int maxDepth = Integer.MAX_VALUE;
if (depth != null && depth.intValue() >= 0) {
maxDepth = depth.intValue();
}
if (CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
for (final Folder folder : app.nodeQuery(Folder.class).and(parentKey, null).sort(AbstractNode.name).getAsList()) {
recursivelyCollectFolderTree(result, folder, maxDepth, 1, includeAllowableActions);
}
} else {
final Folder folder = app.get(Folder.class, folderId);
if (folder != null) {
final List<Folder> children = Iterables.toList(folder.getFolders());
Collections.sort(children, new GraphObjectComparator(AbstractNode.name, false));
for (final Folder child : children) {
recursivelyCollectFolderTree(result, child, maxDepth, 1, includeAllowableActions);
}
} else {
throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
}
}
tx.success();
} catch (final FrameworkException fex) {
logger.warn("", fex);
}
return result;
}
use of org.structr.web.entity.Folder in project structr by structr.
the class CMISObjectService method createFolder.
@Override
public String createFolder(final String repositoryId, final Properties properties, final String folderId, final List<String> policies, final Acl addAces, final Acl removeAces, final ExtensionsData extension) {
final App app = StructrApp.getInstance(securityContext);
String uuid = null;
try (final Tx tx = app.tx()) {
final String objectTypeId = getStringValue(properties, PropertyIds.OBJECT_TYPE_ID);
final Class type = typeFromObjectTypeId(objectTypeId, BaseTypeId.CMIS_FOLDER, Folder.class);
// check if type exists
if (type != null) {
// check that base type is cmis:folder
final BaseTypeId baseTypeId = getBaseTypeId(type);
if (baseTypeId != null && BaseTypeId.CMIS_FOLDER.equals(baseTypeId)) {
// create folder
final AbstractFile newFolder = (AbstractFile) app.create(type, PropertyMap.cmisTypeToJavaType(securityContext, type, properties));
// find and set parent if it exists
if (!CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
final Folder parent = app.get(Folder.class, folderId);
if (parent != null) {
newFolder.setParent(parent);
} else {
throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
}
}
uuid = newFolder.getUuid();
} else {
throw new CmisConstraintException("Cannot create cmis:folder of type " + objectTypeId);
}
} else {
throw new CmisObjectNotFoundException("Type with ID " + objectTypeId + " does not exist");
}
tx.success();
} catch (Throwable t) {
throw new CmisRuntimeException("New folder could not be created: " + t.getMessage());
}
return uuid;
}
use of org.structr.web.entity.Folder in project structr by structr.
the class FileSyncWatchEventListener method handle.
// ----- private methods -----
private FolderAndFile handle(final Path root, final Path relativePath, final Path path, final boolean create) throws FrameworkException {
// identify mounted folder object
final PropertyKey<String> mountTargetKey = StructrApp.key(Folder.class, "mountTarget");
final Folder folder = StructrApp.getInstance().nodeQuery(Folder.class).and(mountTargetKey, root.toString()).getFirst();
if (folder != null) {
final String mountFolderPath = folder.getProperty(StructrApp.key(Folder.class, "path"));
if (mountFolderPath != null) {
final Path relativePathParent = relativePath.getParent();
if (relativePathParent == null) {
return new FolderAndFile(folder, getOrCreate(folder, path, relativePath, create));
} else {
final String pathRelativeToRoot = folder.getPath() + "/" + relativePathParent.toString();
final Folder parentFolder = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), pathRelativeToRoot);
final AbstractFile file = getOrCreate(parentFolder, path, relativePath, create);
return new FolderAndFile(folder, file);
}
} else {
logger.warn("Cannot handle watch event, folder {} has no path", folder.getUuid());
}
}
return null;
}
Aggregations