Search in sources :

Example 6 with TypeDefinitionWrapper

use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper 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 7 with TypeDefinitionWrapper

use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method getTypeDescendants.

@Override
public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth, Boolean includePropertyDefinitions, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>();
    // check depth
    int d = (depth == null ? -1 : depth.intValue());
    if (d == 0) {
        throw new CmisInvalidArgumentException("Depth must not be 0!");
    }
    if (typeId == null) {
        for (TypeDefinitionWrapper tdw : connector.getOpenCMISDictionaryService().getBaseTypes(true)) {
            result.add(getTypesDescendants(d, tdw, includePropertyDefinitions));
        }
    } else {
        TypeDefinitionWrapper tdw = connector.getOpenCMISDictionaryService().findType(typeId);
        if (tdw == null) {
            throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!");
        }
        List<TypeDefinitionWrapper> children = connector.getOpenCMISDictionaryService().getChildren(typeId);
        if (children != null) {
            for (TypeDefinitionWrapper child : children) {
                result.add(getTypesDescendants(d, child, includePropertyDefinitions));
            }
        }
    }
    return result;
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) ArrayList(java.util.ArrayList) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) TypeDefinitionContainer(org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer)

Example 8 with TypeDefinitionWrapper

use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method applyPolicy.

// --- policy service ---
@Override
public void applyPolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");
    TypeDefinitionWrapper type = info.getType();
    if (type == null) {
        throw new CmisObjectNotFoundException("No corresponding type found! Not a CMIS object?");
    }
    connector.applyPolicies(info.getNodeRef(), type, Collections.singletonList(policyId));
}
Also used : CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Example 9 with TypeDefinitionWrapper

use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper 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 10 with TypeDefinitionWrapper

use of org.alfresco.opencmis.dictionary.TypeDefinitionWrapper in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method createDocumentFromSource.

@Override
public String createDocumentFromSource(String repositoryId, String sourceId, final Properties properties, String folderId, VersioningState versioningState, final List<String> policies, final Acl addAces, final Acl removeAces, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    // get the parent folder node ref
    final CMISNodeInfo parentInfo = getOrCreateFolderInfo(folderId, "Parent folder");
    // get source
    CMISNodeInfo info = getOrCreateNodeInfo(sourceId, "Source");
    // check source
    if (info.isVariant(CMISObjectVariant.ASSOC)) {
        throw new CmisConstraintException("Source object is not a document!");
    }
    final NodeRef sourceNodeRef = info.getNodeRef();
    if (!info.isDocument()) {
        throw new CmisConstraintException("Source object is not a document!");
    }
    // get name and type
    final String name = connector.getNameProperty(properties, info.getName());
    final TypeDefinitionWrapper type = info.getType();
    connector.checkChildObjectType(parentInfo, type.getTypeId());
    versioningState = getDocumentDefaultVersioningState(versioningState, type);
    try {
        FileInfo fileInfo = connector.getFileFolderService().copy(sourceNodeRef, parentInfo.getNodeRef(), name);
        NodeRef nodeRef = fileInfo.getNodeRef();
        connector.setProperties(nodeRef, type, properties, new String[] { PropertyIds.NAME, PropertyIds.OBJECT_TYPE_ID });
        connector.applyPolicies(nodeRef, type, policies);
        connector.applyACL(nodeRef, type, addAces, removeAces);
        connector.extractMetadata(nodeRef);
        connector.createThumbnails(nodeRef, Collections.singleton("doclib"));
        connector.applyVersioningState(nodeRef, versioningState);
        connector.getActivityPoster().postFileFolderAdded(nodeRef);
        return connector.createObjectId(nodeRef);
    } catch (FileNotFoundException e) {
        throw new CmisContentAlreadyExistsException("An object with this name already exists!", e);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) CmisContentAlreadyExistsException(org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo)

Aggregations

TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)33 CMISNodeInfo (org.alfresco.opencmis.dictionary.CMISNodeInfo)13 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)13 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)13 NodeRef (org.alfresco.service.cmr.repository.NodeRef)12 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)11 ArrayList (java.util.ArrayList)10 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)9 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)9 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)9 Serializable (java.io.Serializable)8 QName (org.alfresco.service.namespace.QName)8 PropertyDefinitionWrapper (org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper)7 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)5 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)4