use of org.structr.common.GraphObjectComparator in project structr by structr.
the class Resource method applyDefaultSorting.
protected void applyDefaultSorting(List<? extends GraphObject> list, PropertyKey sortKey, boolean sortDescending) {
if (!list.isEmpty()) {
String finalSortOrder = sortDescending ? "desc" : "asc";
if (sortKey == null) {
// Apply default sorting, if defined
final GraphObject obj = list.get(0);
final PropertyKey defaultSort = obj.getDefaultSortKey();
if (defaultSort != null) {
sortKey = defaultSort;
finalSortOrder = obj.getDefaultSortOrder();
}
}
if (sortKey != null) {
Collections.sort(list, new GraphObjectComparator(sortKey, finalSortOrder));
}
}
}
use of org.structr.common.GraphObjectComparator 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.common.GraphObjectComparator 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.common.GraphObjectComparator in project structr by structr.
the class DeployCommand method exportFilesAndFolders.
private void exportFilesAndFolders(final Path target, final Folder folder, final Map<String, Object> config) throws IOException {
// ignore folders with mounted content
if (folder.isMounted()) {
return;
}
final String name = folder.getName();
final Path path = target.resolve(name);
// types and those with relationships to user data.
if (DeployCommand.okToExport(folder)) {
final Map<String, Object> properties = new TreeMap<>();
Files.createDirectories(path);
exportFileConfiguration(folder, properties);
if (!properties.isEmpty()) {
config.put(folder.getPath(), properties);
}
}
final List<Folder> folders = Iterables.toList(folder.getFolders());
Collections.sort(folders, new GraphObjectComparator(AbstractNode.name, false));
for (final Folder child : folders) {
exportFilesAndFolders(path, child, config);
}
final List<File> files = Iterables.toList(folder.getFiles());
Collections.sort(files, new GraphObjectComparator(AbstractNode.name, false));
for (final File file : files) {
exportFile(path, file, config);
}
}
use of org.structr.common.GraphObjectComparator in project structr by structr.
the class HtmlServlet method findPage.
/**
* Find a page with matching path.
*
* To be compatible with older versions, fallback to name-only lookup.
*
* @param securityContext
* @param pages
* @param path
* @param edit
* @return page
* @throws FrameworkException
*/
private Page findPage(final SecurityContext securityContext, List<Page> pages, final String path, final EditMode edit) throws FrameworkException {
if (pages == null) {
pages = StructrApp.getInstance(securityContext).nodeQuery(Page.class).getAsList();
Collections.sort(pages, new GraphObjectComparator(StructrApp.key(Page.class, "position"), GraphObjectComparator.ASCENDING));
}
for (final Page page : pages) {
final String pagePath = page.getPath();
if (pagePath != null && pagePath.equals(path) && (EditMode.CONTENT.equals(edit) || isVisibleForSite(securityContext.getRequest(), page))) {
return page;
}
}
final String name = PathHelper.getName(path);
for (final Page page : pages) {
final String pageName = page.getName();
if (pageName != null && pageName.equals(name) && (EditMode.CONTENT.equals(edit) || isVisibleForSite(securityContext.getRequest(), page))) {
return page;
}
}
for (final Page page : pages) {
final String pageUuid = page.getUuid();
if (pageUuid != null && pageUuid.equals(name) && (EditMode.CONTENT.equals(edit) || isVisibleForSite(securityContext.getRequest(), page))) {
return page;
}
}
return null;
}
Aggregations