Search in sources :

Example 6 with GraphObjectComparator

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));
        }
    }
}
Also used : GraphObjectComparator(org.structr.common.GraphObjectComparator) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Example 7 with GraphObjectComparator

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);
    }
}
Also used : ObjectInFolderContainerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderContainerImpl) CMISObjectInFolderWrapper(org.structr.files.cmis.wrapper.CMISObjectInFolderWrapper) GraphObjectComparator(org.structr.common.GraphObjectComparator) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer) LinkedList(java.util.LinkedList)

Example 8 with GraphObjectComparator

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;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) FrameworkException(org.structr.common.error.FrameworkException) GraphObjectComparator(org.structr.common.GraphObjectComparator) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer) LinkedList(java.util.LinkedList)

Example 9 with GraphObjectComparator

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);
    }
}
Also used : Path(java.nio.file.Path) GraphObjectComparator(org.structr.common.GraphObjectComparator) TreeMap(java.util.TreeMap) Folder(org.structr.web.entity.Folder) AbstractFile(org.structr.web.entity.AbstractFile) AbstractMinifiedFile(org.structr.web.entity.AbstractMinifiedFile) MinifiedCssFile(org.structr.web.entity.MinifiedCssFile) File(org.structr.web.entity.File) MinifiedJavaScriptFile(org.structr.web.entity.MinifiedJavaScriptFile)

Example 10 with GraphObjectComparator

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;
}
Also used : Page(org.structr.web.entity.dom.Page) GraphObjectComparator(org.structr.common.GraphObjectComparator)

Aggregations

GraphObjectComparator (org.structr.common.GraphObjectComparator)10 GraphObject (org.structr.core.GraphObject)3 Folder (org.structr.web.entity.Folder)3 LinkedList (java.util.LinkedList)2 ObjectInFolderContainer (org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer)2 FrameworkException (org.structr.common.error.FrameworkException)2 PropertyKey (org.structr.core.property.PropertyKey)2 CMISRootFolder (org.structr.files.cmis.repository.CMISRootFolder)2 Page (org.structr.web.entity.dom.Page)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1 ObjectInFolderContainerImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderContainerImpl)1 QueryResult (org.structr.api.QueryResult)1 GeoCodingResult (org.structr.common.geo.GeoCodingResult)1