Alfresco文档派生的内容缺少<content> </content>

时间:2013-04-11 16:14:01

标签: alfresco cmis alfresco-share

我已经创建了一个从文档派生的自定义内容类型。我正在尝试使用CMIS以编程方式使用python cmislib查询我的Alfresco服务器(尝试使用4.2.b和4.2.c)。我有一个金字塔服务器,它接受REST调用并使用CMIS将它们发送到我的Alfresco服务器。

我收到此错误:

2013-04-11 11:19:25,526 | ERROR | Exception when serving /access_manager/search_noauth
Traceback (most recent call last):
  File "/home/hbrown/.virtualenvs/access_manager_master/local/lib/python2.7/site-packages/waitress-0.8.1-py2.7.egg/waitress/channel.py", line 329, in service
    task.service()
[...]
  File "/home/hbrown/workspace/spt/access_manager/access_manager/views/search.py", line 223, in cmis_main
    for result in repo.query(whole_query)
  File "/home/hbrown/.virtualenvs/access_manager_master/local/lib/python2.7/site-packages/cmislib/model.py", line 2467, in getContentStream
    assert(len(contentElements) == 1), 'Expected to find exactly one atom:content element.'
AssertionError: Expected to find exactly one atom:content element.

我正在使用getContentStream()来检索内容。根据代码注释,我会说这是正确的API调用:

    >>> doc.getName()
    u'sample-b.pdf'
    >>> o = open('tmp.pdf', 'wb')
    >>> result = doc.getContentStream()
    >>> o.write(result.read())
    >>> result.close()
    >>> o.close()
    >>> import os.path
    >>> os.path.getsize('tmp.pdf')
    117248

cmislib中的python代码显然希望文档包含一个名为content的元素的XML,而我的文件不包含。{/ p>

调用代码如下所示:

from cmislib import CmisClient

SERVER = "localhost"
url = "http://{0}:8080/alfresco/cmisatom".format(SERVER)
client = CmisClient(url, 'admin', 'alfresco')
repo = client.defaultRepository
results = repo.query("select * from wg:bulletin")
print results[0].getContentStream().read()

getContentStream中运行的XML如下所示:

<atom:entry>
    <atom:author>
        <atom:name/>
    </atom:author>
    <atom:id>http://chemistry.apache.org/aWQtMQ==</atom:id>
    <atom:published>2013-04-12T03:22:38Z</atom:published>
    <atom:title>Query Result id-1</atom:title>
    <app:edited>2013-04-12T03:22:38Z</app:edited>
    <atom:updated>2013-04-12T03:22:38Z</atom:updated>
    <cmisra:object xmlns:ns3="http://docs.oasis-open.org/ns/cmis/messaging/200908/">
        <cmis:properties>
            <cmis:propertyInteger displayName="Content Stream Length" localName="contentStreamLength" propertyDefinitionId="cmis:contentStreamLength" queryName="b.cmis:contentStreamLength">
                <cmis:value>249</cmis:value>
            </cmis:propertyInteger>
            <cmis:propertyId displayName="Object Type Id" localName="objectTypeId" propertyDefinitionId="cmis:objectTypeId" queryName="b.cmis:objectTypeId">
                <cmis:value>D:wg:bulletin</cmis:value>
            </cmis:propertyId>
            <cmis:propertyString displayName="Version Series Checked Out By" localName="versionSeriesCheckedOutBy" propertyDefinitionId="cmis:versionSeriesCheckedOutBy" queryName="b.cmis:versionSeriesCheckedOutBy"/>
            <cmis:propertyId displayName="Version Series Checked Out Id" localName="versionSeriesCheckedOutId" propertyDefinitionId="cmis:versionSeriesCheckedOutId" queryName="b.cmis:versionSeriesCheckedOutId"/>
            <cmis:propertyId displayName="Version series id" localName="versionSeriesId" propertyDefinitionId="cmis:versionSeriesId" queryName="b.cmis:versionSeriesId">
                <cmis:value>workspace://SpacesStore/1cd2053d-1fc4-4e85-b780-ba80284f0841</cmis:value>
            </cmis:propertyId>
            <cmis:propertyString displayName="wg:account" localName="account" propertyDefinitionId="wg:account" queryName="b.wg:account"/>
            <cmis:propertyString displayName="Version Label" localName="versionLabel" propertyDefinitionId="cmis:versionLabel" queryName="b.cmis:versionLabel">
                <cmis:value>1.0</cmis:value>
            </cmis:propertyString>
            <cmis:propertyBoolean displayName="Is Latest Version" localName="isLatestVersion" propertyDefinitionId="cmis:isLatestVersion" queryName="b.cmis:isLatestVersion">
                <cmis:value>true</cmis:value>
            </cmis:propertyBoolean>
            <cmis:propertyBoolean displayName="Is Version Series Checked Out" localName="isVersionSeriesCheckedOut" propertyDefinitionId="cmis:isVersionSeriesCheckedOut" queryName="b.cmis:isVersionSeriesCheckedOut">
                <cmis:value>false</cmis:value>
            </cmis:propertyBoolean>
            <cmis:propertyString displayName="Last Modified By" localName="lastModifiedBy" propertyDefinitionId="cmis:lastModifiedBy" queryName="b.cmis:lastModifiedBy">
                <cmis:value>admin</cmis:value>
            </cmis:propertyString>
            <cmis:propertyString displayName="Created by" localName="createdBy" propertyDefinitionId="cmis:createdBy" queryName="b.cmis:createdBy">
                <cmis:value>admin</cmis:value>
            </cmis:propertyString>
            <cmis:propertyDateTime displayName="wg:displayUntil" localName="displayUntil" propertyDefinitionId="wg:displayUntil" queryName="b.wg:displayUntil"/>
            <cmis:propertyId displayName="Alfresco Node Ref" localName="nodeRef" propertyDefinitionId="alfcmis:nodeRef" queryName="b.alfcmis:nodeRef">
                <cmis:value>workspace://SpacesStore/1cd2053d-1fc4-4e85-b780-ba80284f0841</cmis:value>
            </cmis:propertyId>
            <cmis:propertyString displayName="wg:email" localName="email" propertyDefinitionId="wg:email" queryName="b.wg:email"/>
            <cmis:propertyBoolean displayName="wg:isActive" localName="isActive" propertyDefinitionId="wg:isActive" queryName="b.wg:isActive">
                <cmis:value>false</cmis:value>
            </cmis:propertyBoolean>
            <cmis:propertyString displayName="wg:username" localName="username" propertyDefinitionId="wg:username" queryName="b.wg:username"/>
            <cmis:propertyBoolean displayName="Is Latest Major Version" localName="isLatestMajorVersion" propertyDefinitionId="cmis:isLatestMajorVersion" queryName="b.cmis:isLatestMajorVersion">
                <cmis:value>true</cmis:value>
            </cmis:propertyBoolean>
            <cmis:propertyId displayName="Content Stream Id" localName="contentStreamId" propertyDefinitionId="cmis:contentStreamId" queryName="b.cmis:contentStreamId">
                <cmis:value>store://2013/4/10/15/29/20b185d0-afae-4a7f-a06e-58eab399bdc9.bin</cmis:value>
            </cmis:propertyId>
            <cmis:propertyString displayName="Name" localName="name" propertyDefinitionId="cmis:name" queryName="b.cmis:name">
                <cmis:value>.pythonrc</cmis:value>
            </cmis:propertyString>
            <cmis:propertyString displayName="Content Stream MIME Type" localName="contentStreamMimeType" propertyDefinitionId="cmis:contentStreamMimeType" queryName="b.cmis:contentStreamMimeType">
                <cmis:value>text/plain</cmis:value>
            </cmis:propertyString>
            <cmis:propertyDateTime displayName="Creation Date" localName="creationDate" propertyDefinitionId="cmis:creationDate" queryName="b.cmis:creationDate">
                <cmis:value>2013-04-10T15:29:18.146-04:00</cmis:value>
            </cmis:propertyDateTime>
            <cmis:propertyString displayName="Change token" localName="changeToken" propertyDefinitionId="cmis:changeToken" queryName="b.cmis:changeToken"/>
            <cmis:propertyString displayName="wg:state" localName="state" propertyDefinitionId="wg:state" queryName="b.wg:state"/>
            <cmis:propertyDateTime displayName="wg:displayFrom" localName="displayFrom" propertyDefinitionId="wg:displayFrom" queryName="b.wg:displayFrom"/>
            <cmis:propertyString displayName="Checkin Comment" localName="checkinComment" propertyDefinitionId="cmis:checkinComment" queryName="b.cmis:checkinComment"/>
            <cmis:propertyString displayName="wg:application" localName="application" propertyDefinitionId="wg:application" queryName="b.wg:application"/>
            <cmis:propertyId displayName="Object Id" localName="objectId" propertyDefinitionId="cmis:objectId" queryName="b.cmis:objectId">
                <cmis:value>workspace://SpacesStore/1cd2053d-1fc4-4e85-b780-ba80284f0841;1.0</cmis:value>
            </cmis:propertyId>
            <cmis:propertyBoolean displayName="Is Immutable" localName="isImmutable" propertyDefinitionId="cmis:isImmutable" queryName="b.cmis:isImmutable">
                <cmis:value>false</cmis:value>
            </cmis:propertyBoolean>
            <cmis:propertyBoolean displayName="Is Major Version" localName="isMajorVersion" propertyDefinitionId="cmis:isMajorVersion" queryName="b.cmis:isMajorVersion">
                <cmis:value>true</cmis:value>
            </cmis:propertyBoolean>
            <cmis:propertyString displayName="wg:institution" localName="institution" propertyDefinitionId="wg:institution" queryName="b.wg:institution"/>
            <cmis:propertyId displayName="Base Type Id" localName="baseTypeId" propertyDefinitionId="cmis:baseTypeId" queryName="b.cmis:baseTypeId">
                <cmis:value>cmis:document</cmis:value>
            </cmis:propertyId>
            <cmis:propertyString displayName="Content Stream Filename" localName="contentStreamFileName" propertyDefinitionId="cmis:contentStreamFileName" queryName="b.cmis:contentStreamFileName">
                <cmis:value>.pythonrc</cmis:value>
            </cmis:propertyString>
            <cmis:propertyDateTime displayName="Last Modified Date" localName="lastModificationDate" propertyDefinitionId="cmis:lastModificationDate" queryName="b.cmis:lastModificationDate">
                <cmis:value>2013-04-10T15:29:23.384-04:00</cmis:value>
            </cmis:propertyDateTime>
        </cmis:properties>
    </cmisra:object>
</atom:entry>

这里显然没有名为content的XML元素用于提取的python代码。

这是我的自定义内容文档的错误配置还是cmislib无法跟踪的CMIS更改或我是否调用错误的API函数来获取内容或其他内容?


稍后:解决此问题的最小更改是拨打reloadgetAllowableActions

这是原始代码:

def cmis_main(props, settings):
    """
    Create a CMIS query based on props and execute against Alfresco
    """
    def cmis_query(props, mapping):
        """
        Create CMIS query of AND-separated OR-clauses
        """
        # Code that formats a query string from dictionaries...

    cmis_mapping = {
        # Dictionary config for call to cmis_query
        # Nothing to see here. Move on.
        "app_sids": {
            "where_fmt": IN_WHERE_FMT,
            "key": "{0}:application".format(CMIS_NAMESPACE),
            "fn": set_format,
        },
    }

    cmis_url, cmis_user, cmis_password = cmis_args(settings)
    cmisclient = CmisClient(cmis_url, cmis_user, cmis_password)
    repo = cmisclient.getDefaultRepository()
    whole_query = cmis_query(props, cmis_mapping)
    logger.debug(whole_query)

    return [
        {
            'name': result.name,
            'content': result.getContentStream().read(),
            'content_mime_type': result.properties["cmis:contentStreamMimeType"],
        }
        for result in repo.query(whole_query)
    ]

它被打破了。所以我把代码更改为:

    results = list(repo.query(whole_query))
    for result in results:
        print(result.getAllowableActions())
        # or: result.reload()

    return [
        {
            'name': result.name,
            'content': result.getContentStream().read(),
            'content_mime_type': result.properties["cmis:contentStreamMimeType"],
        }
        for result in results
    ]

它有效。我改成了这个:

    results = list(repo.query(whole_query))
    for result in results:
        pass

    return [
        {
            'name': result.name,
            'content': result.getContentStream().read(),
            'content_mime_type': result.properties["cmis:contentStreamMimeType"],
        }
        for result in results
    ]

它破了。因此,XML似乎没有在CMISLIB对象中完全加载。

1 个答案:

答案 0 :(得分:2)

在调用getContentStream()之前尝试执行结果[0] .reload()。这不应该是必需的,但它可能会强制对象重新加载内容元素。