cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Title and Description when adding a document

michaelloveusa
Champ on-the-rise
Champ on-the-rise
Hi there - I am trying to use the CMIS Object Service to create a document and have it set the cm:title and cm:description properties. When I use the discovery service, I see that they are stored as an aspect property, but I cannot figure out how to get them in there. I keep getting variations of the following error:

   <soap:Body>
      <soap:Fault>
         <faultcode>soapSmiley Frustratederver</faultcode>
         <faultstring>Property cmis:title not found for type D:srv:devServices in CMIS Dictionary</faultstring>
         <detail>
            <cmisFault xmlns="http://docs.oasis-open.org/ns/cmis/messaging/200908/" xmlns:ns2="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns:ns3="http://www.alfresco.org">
               <type>invalidArgument</type>
              
400

               <message>Property cmis:title not found for type D:srv:devServices in CMIS Dictionary</message>
            </cmisFault>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

Can someone guide me?

Thanks, Mike
18 REPLIES 18

mitpatoliya
Star Collaborator
Star Collaborator
Could you also post the piece of code?
It will give more insight. :?:

michaelloveusa
Champ on-the-rise
Champ on-the-rise
Hi there. I don't really have code per se. I am creating the xml request in an xsl transformation. Here is my create document request:

<createDocument>
<tns:repositoryId>29aafde4-16c2-49f5-bdae-d5a70feba957</tns:repositoryId>
<tnsSmiley Tongueroperties>
<ns1Smiley TongueropertyString  propertyDefinitionId="cmis:name"  localName="cmis:name"  displayName="cmis:name"  queryName="cmis:name">
<ns1:value>2012-SITE-000008-capt_photo_1279891919425-1-0.jpg</ns1:value>
</ns1Smiley TongueropertyString>
<ns1Smiley TongueropertyId  propertyDefinitionId="cmisSmiley SurprisedbjectTypeId"  localName="cmisSmiley SurprisedbjectTypeId"  displayName="cmisSmiley SurprisedbjectTypeId"  queryName="cmisSmiley SurprisedbjectTypeId">
<ns1:value>D:srv:devServices</ns1:value>
</ns1Smiley TongueropertyId>
<ns1Smiley TongueropertyString  propertyDefinitionId="srv:devServicesType"  localName="srv:devServicesType"  displayName="srv:devServicesType"  queryName="srv:devServicesType">
<ns1:value>CAP</ns1:value>
</ns1Smiley TongueropertyString>
<ns1Smiley TongueropertyString  propertyDefinitionId="srv:capParcelId"  localName="srv:capParcelId"  displayName="srv:capParcelId"  queryName="srv:capParcelId">
<ns1:value>2012-SITE-000008</ns1:value>
</ns1Smiley TongueropertyString>
<ns1Smiley TongueropertyString  propertyDefinitionId="cm:title"  localName="cm:title"  displayName="cm:title"  queryName="cm:title">
<ns1:value>capt_photo_1279891919425-1-0.jpg</ns1:value>
</ns1Smiley TongueropertyString>
<ns1Smiley TongueropertyString  propertyDefinitionId="cm:description"  localName="cm:description"  displayName="cm:description"  queryName="cm:description">
<ns1:value/>
</ns1Smiley TongueropertyString>

</tnsSmiley Tongueroperties>
<tns:folderId>workspace://SpacesStore/6a7b99e5-a34d-451e-8a4e-7e16bb0e7c33</tns:folderId>
<tns:contentStream>
<tns:length>16066</tns:length>
<tns:mimeType>image/pjpeg</tns:mimeType>
<tns:filename>2012-SITE-000008-capt_photo_1279891919425-1-0.jpg</tns:filename>
<tns:stream>…</tns:stream>
</tns:contentStream>
</createDocument>

michaelloveusa
Champ on-the-rise
Champ on-the-rise
Any thoughts on this would be greatly appreciated.

Mike

michaelloveusa
Champ on-the-rise
Champ on-the-rise
Maybe I should step back as there may be a better solution to my problem.

What I need to store when I add a new document is a "display" filename and a description of the file when the user adds it.

For example: I am integrating Alfresco with a system that does building permits. A user would have a unique identifier associated with his/her permit application, plans etc. The user might have an electronic document that  is their building plan. Let's say they want to upload the file and it is called "MyPlan.pdf" In order to make that filename unique in Alfresco, I prepend the system's unique identifier to the filename as such: "2012-PERMIT-1234 - MyPlan.pdf". This is what I put into the filename attribute when the document gets created in Alfresco. This is fine for Alfresco, but now the user sees this filename  "2012-PERMIT-1234 - MyPlan.pdf" instead of what it is really called ("MyPlan.pdf"). So, what I want to do is use the filename attribute to store the long name ("2012-PERMIT-1234 - MyPlan.pdf") in Alfresco to make sure it is unique (many people may have a "MyPlan.pdf"), but show the user "MyPlan.pdf". The idea is basically an internal filename and a display filename. So, along with that, the user can enter a file description and I want to store that with the document as well.

We have a couple of custom attributes for the container, but we do not want to add more to accomodate the above issues. I want to use appropriate base document attributes if possible to solve this problem. This is why I was trying to use title and description.

Any other ideas?

Thanks again, Mike

michaelloveusa
Champ on-the-rise
Champ on-the-rise
Funny - When I add a title/description through Alfresco, I can see the attributes of title and description, but they are under the aspects element in the xml response.

<soap:Body>
      <getPropertiesResponse xmlns="http://docs.oasis-open.org/ns/cmis/messaging/200908/" xmlns:ns2="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns:ns3="http://www.alfresco.org">
         <properties>
            <ns2Smiley TongueropertyInteger propertyDefinitionId="cmis:contentStreamLength">
               <ns2:value>32848</ns2:value>
            </ns2Smiley TongueropertyInteger>
            <ns2Smiley TongueropertyId propertyDefinitionId="cmisSmiley SurprisedbjectTypeId">
               <ns2:value>D:srv:devServices</ns2:value>
            </ns2Smiley TongueropertyId>
            <ns2Smiley TongueropertyId propertyDefinitionId="cmis:versionSeriesId">
               <ns2:value>workspace://SpacesStore/bea3b541-cf4e-4494-8c4f-7369992dfe17</ns2:value>
            </ns2Smiley TongueropertyId>
            <ns2Smiley TongueropertyString propertyDefinitionId="cmis:versionLabel">
               <ns2:value>1.13</ns2:value>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyBoolean propertyDefinitionId="cmis:isVersionSeriesCheckedOut">
               <ns2:value>false</ns2:value>
            </ns2Smiley TongueropertyBoolean>
            <ns2Smiley TongueropertyString propertyDefinitionId="srv:capParcelID">
               <ns2:value>2012-RESCON-000017</ns2:value>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyString propertyDefinitionId="srv:devServicesType">
               <ns2:value>CAP</ns2:value>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyBoolean propertyDefinitionId="cmis:isLatestMajorVersion">
               <ns2:value>false</ns2:value>
            </ns2Smiley TongueropertyBoolean>
            <ns2Smiley TongueropertyId propertyDefinitionId="cmis:contentStreamId">
               <ns2:value>store://2011/11/11/20/44/1716b262-f186-449f-b759-cbeb88fae7b5.bin</ns2:value>
            </ns2Smiley TongueropertyId>
            <ns2Smiley TongueropertyString propertyDefinitionId="cmis:name">
               <ns2:value>cap12345-PanthersBoat5e537.JPG</ns2:value>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyString propertyDefinitionId="ccdSmiley Surprisedwner">
               <ns2:value>fred</ns2:value>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyBoolean propertyDefinitionId="cmis:isMajorVersion">
               <ns2:value>false</ns2:value>
            </ns2Smiley TongueropertyBoolean>
            <ns2Smiley TongueropertyId propertyDefinitionId="cmis:baseTypeId">
               <ns2:value>cmis:document</ns2:value>
            </ns2Smiley TongueropertyId>
            <ns2Smiley TongueropertyString propertyDefinitionId="cmis:contentStreamFileName">
               <ns2:value>cap12345-PanthersBoat5e537.JPG</ns2:value>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyDateTime propertyDefinitionId="cmis:lastModificationDate">
               <ns2:value>2012-03-28T12:43:24.734-06:00</ns2:value>
            </ns2Smiley TongueropertyDateTime>
            <ns2Smiley TongueropertyString propertyDefinitionId="ccd:boxNumber">
               <ns2:value/>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyString propertyDefinitionId="ccd:securedDocumentFlag">
               <ns2:value>fred</ns2:value>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyBoolean propertyDefinitionId="cmis:isLatestVersion">
               <ns2:value>true</ns2:value>
            </ns2Smiley TongueropertyBoolean>
            <ns2Smiley TongueropertyString propertyDefinitionId="cmis:lastModifiedBy">
               <ns2:value>Dev_Services</ns2:value>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyString propertyDefinitionId="cmis:createdBy">
               <ns2:value>Dev_Services</ns2:value>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyString propertyDefinitionId="ccd:submittedBy">
               <ns2:value/>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyString propertyDefinitionId="ccd:agency">
               <ns2:value/>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyString propertyDefinitionId="cmis:contentStreamMimeType">
               <ns2:value>image/jpeg</ns2:value>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyString propertyDefinitionId="ccdSmiley TonguerojectName">
               <ns2:value/>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyDateTime propertyDefinitionId="cmis:creationDate">
               <ns2:value>2011-11-11T20:44:36.680-07:00</ns2:value>
            </ns2Smiley TongueropertyDateTime>
            <ns2Smiley TongueropertyString propertyDefinitionId="ccdSmiley SurprisedperatorComments">
               <ns2:value/>
            </ns2Smiley TongueropertyString>
            <ns2Smiley TongueropertyId propertyDefinitionId="cmisSmiley SurprisedbjectId">
               <ns2:value>workspace://SpacesStore/bea3b541-cf4e-4494-8c4f-7369992dfe17</ns2:value>
            </ns2Smiley TongueropertyId>
            <ns2Smiley TongueropertyBoolean propertyDefinitionId="cmis:isImmutable">
               <ns2:value>false</ns2:value>
            </ns2Smiley TongueropertyBoolean>
            <ns3:aspects>
               <ns3:appliedAspects>P:cm:titled</ns3:appliedAspects>
               <ns3:appliedAspects>P:cm:templatable</ns3:appliedAspects>
               <ns3:appliedAspects>P:ccd:kofaxMapping</ns3:appliedAspects>
               <ns3:appliedAspects>P:ccd:recordTypeInfo</ns3:appliedAspects>
               <ns3:appliedAspects>P:cm:author</ns3:appliedAspects>
               <ns3Smiley Tongueroperties>
                  <ns2Smiley TongueropertyId propertyDefinitionId="cm:template">
                     <ns2:value>workspace://SpacesStore/2b61b06b-ef9c-4091-a4b4-decb8f5e32eb</ns2:value>
                  </ns2Smiley TongueropertyId>
                  <ns2Smiley TongueropertyString propertyDefinitionId="cm:title">
                     <ns2:value>Mike title</ns2:value>
                  </ns2Smiley TongueropertyString>
                  <ns2Smiley TongueropertyString propertyDefinitionId="cm:description">
                     <ns2:value>Mike description</ns2:value>
                  </ns2Smiley TongueropertyString>
                  <ns2Smiley TongueropertyString propertyDefinitionId="cm:author">
                     <ns2:value/>
                  </ns2Smiley TongueropertyString>
                  <ns2Smiley TongueropertyString propertyDefinitionId="ccd:recordType">
                     <ns2:value>fred</ns2:value>
                  </ns2Smiley TongueropertyString>
               </ns3Smiley Tongueroperties>
            </ns3:aspects>
         </properties>
      </getPropertiesResponse>

jpotts
World-Class Innovator
World-Class Innovator
Title and description are defined as part of the "cm:titled" aspect which is why you are seeing them where you are and why you are having trouble setting them as if they were "normal" properties on cmis:document.

One way to figure out the appropriate XML would be to download OpenCMIS from Apache Chemistry and the OpenCMIS Alfresco Extension from Google Code. Then you can set the title and description using Java and use Wireshark (or your favorite equivalent) to see what's being sent to Alfresco in the SOAP envelope.

The OpenCMIS code to create a document with the titled aspect, title, and description might look like:

        Session session = getSession();
      
        // Grab a reference to the folder where we want to create content
   Folder folder = (Folder) session.getObjectByPath("/" + getFolderName());
      
   String timeStamp = new Long(System.currentTimeMillis()).toString();
   String filename = docName + " (" + timeStamp + ")";
      
   // Create a Map of objects with the props we want to set
   Map <String, Object> properties = new HashMap<String, Object>();
   // Following sets the content type and adds the titled aspect
   // This works because we are using the OpenCMIS extension for Alfresco
   properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:cm:titled");
   properties.put("cm:title", "some title");
   properties.put("cm:description", "some description");

   String docText = "This is a sample " + contentType + " document called " + docName;
   byte[] content = docText.getBytes();
   InputStream stream = new ByteArrayInputStream(content);
   ContentStream contentStream = new ContentStreamImpl(filename, BigInteger.valueOf(content.length), "text/plain", stream);

   Document doc = folder.createDocument(
            properties,
            contentStream,
            VersioningState.MAJOR);
   System.out.println("Created: " + doc.getId());
   System.out.println("Content Length: " + doc.getContentStreamLength());

If you don't want to use OpenCMIS to do it you could also just use the Apache Chemistry Workbench as long as you tell it to load up the OpenCMIS extension to enable it to work with aspects.

Jeff

michaelloveusa
Champ on-the-rise
Champ on-the-rise
Hi Jeff - Can you give me some more details on this?

"If you don't want to use OpenCMIS to do it you could also just use the Apache Chemistry Workbench as long as you tell it to load up the OpenCMIS extension to enable it to work with aspects."

I am new to this arena, so I don't quite get it. I downloaded the CMIS Workbench client. Do I then add the connection to my server, confirm that it does have the OpenCMIS extension with aspects turned on (not sure how to do this) and then in the createDocument somehow set those attributes?

Or, are you saying to to download the CMIS Workbench server and get it running locally to test this?

Thanks, Mike

jpotts
World-Class Innovator
World-Class Innovator
Mike,

Sorry about that. Here are the details…

Version 1.0 of the CMIS spec doesn't support aspects. Alfresco extends CMIS to return aspect info from the server but the OpenCMIS client out-of-the-box is spec compliant so it doesn't support aspects either. In order to get the OpenCMIS client to work with Alfresco aspects you need the Alfresco OpenCMIS Extension available at that Google Code project I mentioned.

Now, Alfresco ships with both OpenCMIS and the Alfresco OpenCMIS Extension. If you go look in $TOMCAT_HOME/webapps/alfresco/WEB-INF/lib you'll see both the opencmis and opencmis-extension JARs.

The easiest way to work with Alfresco via CMIS is to use a client library like OpenCMIS. And because the JARs already ship with Alfresco, you don't even have to download anything additional if you don't want to. OpenCMIS can be used with either the restful ATOM Pub binding or the SOAP-based Web Services binding. You can see examples that show how to do very common things with OpenCMIS in my "Working with Custom Content Types, 2nd Edition" tutorial. It is meant for people learning to extend the content model with their own types but it will probably shed some light on how a lot of this stuff works, and it includes CMIS examples, so check it out.

If you can't/don't want to work with a client library like OpenCMIS then you can always post your own raw XML to either the ATOM Pub binding or the Web Services binding. In your case, you were trying to set some aspect-based properties and I pointed out that you were using the wrong XML to do that.

So, to figure out the right XML to post, I proposed two possibilities: (1) Perform the same action using a client side library and watch the XML that gets posted behind the scenes or (2) Perform the same action using the OpenCMIS workbench and watch the XML that gets posted.

In either case, you are using client-side code that doesn't understand aspects by default. Because you are setting aspect-based properties, you're going to need the OpenCMIS extension to enable the client to work with aspects. In the "run the code" option you just need to tell OpenCMIS to use a different object factory. You can see how to do that in the tutorial I referenced. It's just a line of Java code, like this, but look at the source that comes with the tutorial for a complete, working example:
parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
In the "use the workbench" option, you have to tell the workbench to use the OpenCMIS extension. To do that, first make sure the alfresco-opencmis-extension JAR is on the classpath. Once that is set, launch the workbench. When specifying the connection details, fill out everything you need on the "Basic" tab. Then, switch to the "Expert" tab and add:
org.apache.chemistry.opencmis.objectfactory.classname=org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl
Now, WITHOUT switching back to "Basic", click "Load Repositories" then "Login". Now you should be able to see aspect-based properties as you navigate the repository.

Jeff

michaelloveusa
Champ on-the-rise
Champ on-the-rise
Thanks for the detailed response Jeff! I will give it a run. This may be a moot point for me as I was told a while ago that we needed to be CMIS 1.0 compatible (not sure why). If that is the case, I will have to cerate custom attributes.

Thanks again and I will let you know how it goes.

Mike