Search in sources :

Example 1 with ObjectInFolderDataImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method getChildren.

// --- navigation service ---
@Override
public ObjectInFolderList getChildren(String repositoryId, String folderId, String filter, String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
    long start = System.currentTimeMillis();
    checkRepositoryId(repositoryId);
    // convert BigIntegers to int
    int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
    int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());
    ObjectInFolderListImpl result = new ObjectInFolderListImpl();
    List<ObjectInFolderData> list = new ArrayList<ObjectInFolderData>();
    result.setObjects(list);
    // get the children references
    NodeRef folderNodeRef = getOrCreateFolderInfo(folderId, "Folder").getNodeRef();
    // convert orderBy to sortProps
    List<Pair<QName, Boolean>> sortProps = null;
    if (orderBy != null) {
        sortProps = new ArrayList<Pair<QName, Boolean>>(1);
        String[] parts = orderBy.split(",");
        int len = parts.length;
        final int origLen = len;
        if (origLen > 0) {
            int maxSortProps = GetChildrenCannedQuery.MAX_FILTER_SORT_PROPS;
            if (len > maxSortProps) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Too many sort properties in 'orderBy' - ignore those above max (max=" + maxSortProps + ",actual=" + len + ")");
                }
                len = maxSortProps;
            }
            for (int i = 0; i < len; i++) {
                String[] sort = parts[i].split(" +");
                if (sort.length > 0) {
                    // MNT-10529: Leading spaces result in an empty string value after the split operation. Leading spaces may occur in the 'orderBy' statement when the
                    // elements of statement separated by a comma and a space(s)
                    int index = (sort[0].isEmpty()) ? (1) : (0);
                    Pair<QName, Boolean> sortProp = connector.getSortProperty(sort[index], sort.length > (index + 1) ? sort[index + 1] : null);
                    sortProps.add(sortProp);
                }
            }
        }
        if (sortProps.size() < origLen) {
            logger.warn("Sort properties trimmed - either too many and/or not found: \n" + "   orig:  " + orderBy + "\n" + "   final: " + sortProps);
        }
    }
    PagingRequest pageRequest = new PagingRequest(skip, max, null);
    // TODO make this optional/configurable
    pageRequest.setRequestTotalCountMax(skip + 10000);
    // - affects whether numItems may be returned
    Set<QName> typeqnames = new HashSet<QName>();
    List<TypeDefinitionWrapper> allTypes = connector.getOpenCMISDictionaryService().getAllTypes();
    for (TypeDefinitionWrapper type : allTypes) {
        typeqnames.add(type.getAlfrescoClass());
    }
    PagingResults<FileInfo> pageOfNodeInfos = connector.getFileFolderService().list(folderNodeRef, typeqnames, // ignoreAspectQNames,
    null, sortProps, pageRequest);
    if (max > 0) {
        for (FileInfo child : pageOfNodeInfos.getPage()) {
            try {
                // TODO this will break the paging if filtering is performed...
                if (connector.filter(child.getNodeRef())) {
                    continue;
                }
                // create a child CMIS object
                // note: checkExists=false (don't need to check again)
                CMISNodeInfo ni = createNodeInfo(child.getNodeRef(), child.getType(), child.getProperties(), null, false);
                // Skip non-cmis objects
                if (ni.getObjectVariant() == CMISObjectVariant.INVALID_ID || ni.getObjectVariant() == CMISObjectVariant.NOT_EXISTING || ni.getObjectVariant() == CMISObjectVariant.NOT_A_CMIS_OBJECT || ni.getObjectVariant() == CMISObjectVariant.PERMISSION_DENIED) {
                    continue;
                }
                ObjectData object = connector.createCMISObject(ni, filter, includeAllowableActions, includeRelationships, renditionFilter, false, false);
                boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
                if (isObjectInfoRequired) {
                    getObjectInfo(repositoryId, ni.getObjectId(), includeRelationships);
                }
                ObjectInFolderDataImpl childData = new ObjectInFolderDataImpl();
                childData.setObject(object);
                // include path segment
                if (includePathSegment) {
                    childData.setPathSegment(child.getName());
                }
                // add it
                list.add(childData);
            } catch (InvalidNodeRefException e) {
            // ignore invalid children
            } catch (CmisObjectNotFoundException e) {
            // ignore objects that have not been found (perhaps because their type is unknown to CMIS)
            }
        }
    }
    // has more ?
    result.setHasMoreItems(pageOfNodeInfos.hasMoreItems());
    // total count ?
    Pair<Integer, Integer> totalCounts = pageOfNodeInfos.getTotalResultCount();
    if (totalCounts != null) {
        Integer totalCountLower = totalCounts.getFirst();
        Integer totalCountUpper = totalCounts.getSecond();
        if ((totalCountLower != null) && (totalCountLower.equals(totalCountUpper))) {
            result.setNumItems(BigInteger.valueOf(totalCountLower));
        }
    }
    logGetObjectsCall("getChildren", start, folderId, list.size(), filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, extension, skipCount, maxItems, orderBy, null);
    return result;
}
Also used : ObjectInFolderDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) ArrayList(java.util.ArrayList) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) Pair(org.alfresco.util.Pair) HashSet(java.util.HashSet) QName(org.alfresco.service.namespace.QName) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) PagingRequest(org.alfresco.query.PagingRequest) BigInteger(java.math.BigInteger) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ObjectInFolderListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderListImpl) ObjectInFolderData(org.apache.chemistry.opencmis.commons.data.ObjectInFolderData)

Example 2 with ObjectInFolderDataImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method getDescendantsTree.

private void getDescendantsTree(String repositoryId, NodeRef folderNodeRef, int depth, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, boolean foldersOnly, List<ObjectInFolderContainer> list) {
    // get the children references
    List<ChildAssociationRef> childrenList = connector.getNodeService().getChildAssocs(folderNodeRef);
    for (ChildAssociationRef child : childrenList) {
        try {
            TypeDefinitionWrapper type = connector.getType(child.getChildRef());
            if (type == null) {
                continue;
            }
            boolean isFolder = (type instanceof FolderTypeDefintionWrapper);
            if (foldersOnly && !isFolder) {
                continue;
            }
            if (isFolder && type.getAlfrescoClass().equals(ContentModel.TYPE_SYSTEM_FOLDER)) {
                continue;
            }
            if (connector.isHidden(child.getChildRef())) {
                continue;
            }
            if (connector.filter(child.getChildRef())) {
                continue;
            }
            boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
            // create a child CMIS object
            ObjectInFolderDataImpl object = new ObjectInFolderDataImpl();
            // note: checkExists=false (don't need to check again)
            CMISNodeInfo ni = createNodeInfo(child.getChildRef(), null, false);
            object.setObject(connector.createCMISObject(ni, filter, includeAllowableActions, includeRelationships, renditionFilter, false, false));
            if (isObjectInfoRequired) {
                getObjectInfo(repositoryId, ni.getObjectId(), includeRelationships);
            }
            if (includePathSegment) {
                object.setPathSegment(connector.getName(child.getChildRef()));
            }
            // create the container
            ObjectInFolderContainerImpl container = new ObjectInFolderContainerImpl();
            container.setObject(object);
            if ((depth != 1) && isFolder) {
                container.setChildren(new ArrayList<ObjectInFolderContainer>());
                getDescendantsTree(repositoryId, child.getChildRef(), depth - 1, filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, foldersOnly, container.getChildren());
            }
            // add it
            list.add(container);
        } catch (InvalidNodeRefException e) {
        // ignore invalid children
        } catch (CmisObjectNotFoundException e) {
        // ignore objects that have not been found (perhaps because their type is unknown to CMIS)
        }
    }
}
Also used : ObjectInFolderDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ObjectInFolderContainerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderContainerImpl) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) FolderTypeDefintionWrapper(org.alfresco.opencmis.dictionary.FolderTypeDefintionWrapper) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer)

Example 3 with ObjectInFolderDataImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl in project iaf by ibissource.

the class CmisUtils method xml2ObjectsInFolderList.

public static ObjectInFolderList xml2ObjectsInFolderList(Element result) {
    ObjectInFolderListImpl objectInFolderList = new ObjectInFolderListImpl();
    objectInFolderList.setNumItems(CmisUtils.parseBigIntegerAttr(result, "numberOfItems"));
    objectInFolderList.setHasMoreItems(CmisUtils.parseBooleanAttr(result, "hasMoreItems"));
    List<ObjectInFolderData> objects = new ArrayList<ObjectInFolderData>();
    Element objectsElem = XmlUtils.getFirstChildTag(result, "objects");
    for (Node type : XmlUtils.getChildTags(objectsElem, "object")) {
        ObjectInFolderDataImpl oifd = new ObjectInFolderDataImpl();
        String pathSegment = CmisUtils.parseStringAttr(result, "pathSegment");
        oifd.setPathSegment(pathSegment);
        ObjectData objectData = xml2ObjectData((Element) type, null);
        oifd.setObject(objectData);
        objects.add(oifd);
    }
    objectInFolderList.setObjects(objects);
    return objectInFolderList;
}
Also used : ObjectInFolderDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ObjectInFolderListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderListImpl) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) ObjectInFolderData(org.apache.chemistry.opencmis.commons.data.ObjectInFolderData)

Example 4 with ObjectInFolderDataImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl in project structr by structr.

the class CMISObjectInFolderWrapper method wrapObjectData.

public ObjectInFolderData wrapObjectData(final ObjectData element, final String pathSegment) {
    final ObjectInFolderDataImpl data = new ObjectInFolderDataImpl(element);
    data.setPathSegment(pathSegment);
    return data;
}
Also used : ObjectInFolderDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl)

Aggregations

ObjectInFolderDataImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl)4 ArrayList (java.util.ArrayList)2 CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)2 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)2 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)2 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)2 ObjectInFolderData (org.apache.chemistry.opencmis.commons.data.ObjectInFolderData)2 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)2 ObjectInFolderListImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderListImpl)2 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1 FolderTypeDefintionWrapper (org.alfresco.opencmis.dictionary.FolderTypeDefintionWrapper)1 PagingRequest (org.alfresco.query.PagingRequest)1 FileInfo (org.alfresco.service.cmr.model.FileInfo)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 QName (org.alfresco.service.namespace.QName)1 Pair (org.alfresco.util.Pair)1 ObjectInFolderContainer (org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer)1 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)1