cancel
Showing results for 
Search instead for 
Did you mean: 

Creating documents with custom properties via dotcmis

katie
Champ in-the-making
Champ in-the-making
Hi,

After much flailing in the dark it is looking like I am either simply missing something important or simply not trying to do this in the right way at all.

What I need to be able to do is set custom properties associated with documents when they are uploaded to the DMS.  I need to be able to search for documents based on these custom properties, and see the values of these properties in the search results.  This is all being done in C# via the dotcmis library and hope (ultimately) to interface with a number of DMS - currently, I am developing against Alfresco because we use it internally, but ultimately this will almost certainly have to work with another CMIS-compliant DMS.

I can't get anything to do with custom properties working, without resorting to using Alfresco's web interface manually after I've used my program to upload the document, and even then, I still can't search using Query…

We have a model set up with a basic document type, that currently specifies a number of mandatory aspects (this is not important, I will not require the properties to be mandatory).  I can create a document using CreateDocument with the property cmisSmiley SurprisedbjectTypeId set to my document type.  If I look at the properties in the Alfresco web interface I can then see our custom properties, so this much seems to be working as I would expect.

I cannot add any custom properties in CreateDocument, this gives me a "Not found" error.  If I try to add the aspects to the cmisSmiley SurprisedbjectTypeId property, this also results in a "Not found" error (this is true even for the standard CMIS aspects, so I am unable even to set a description, for example.)  This, however, does not seem particularly necessary, because according to the web interface it's expecting the properties in any case, because it's how the document type is defined.

Finally, Query will not recognise any of the custom properties.  "select * from my:doctype" gives me results, but none of the custom properties are returned even though I've specified our custom document type.  If I try to add a where-clause based on a custom property, I get an "Internal Server Error."  Changing the property name to any standard cmis property works correctly (except with dates, but that is another issue entirely!)

Can anybody suggest anything?  I can't help thinking that I am missing something quite simple.  I have run out of things to try and am about to resort to a system of encoding the custom properties in the filename!

Thanks.
8 REPLIES 8

jpotts
World-Class Innovator
World-Class Innovator
CMIS does not support aspects out-of-the-box. I believe that dotcmis also lacks support for aspects. So you should be able to create instances of custom types and you should be able to set and query for custom properties on those custom types, but you won't be able to do that for any properties that are defined as part of an aspect without some customization to the dotcmis library.

The OpenCMIS (Java) and cmislib (Python) client libraries also lack support for aspects. But there are extensions available for both of those libraries that adds support for aspects. Here is the one for OpenCMIS.

Jeff

katie
Champ in-the-making
Champ in-the-making
Problem solved - we removed the aspects from the document model and defined the properties directly within the document types.  It does seem rather silly that the properties are simply not visible because of the way they are defined - but I can see a political reason for Alfresco to decide to implement the CMIS interface this way…

mtam
Champ in-the-making
Champ in-the-making
defined the properties directly within the document types

Hi Katie,
I'm stuck on adding a new custom property to my documents in my .NET application, can you shed some lights on this and elaborate what you meant by defined directly within the document types? Did you enable the feature in your .NET code or did you defined new properties in Alfresco? Thanks much!

jpotts
World-Class Innovator
World-Class Innovator
mtam,

Types can not be defined through code using CMIS 1.0. The CMIS 1.1 spec does include mutable types, but we won't see an implementation of that for quite some time.

So if you need to add a custom property to your Alfresco content model, you can define that property on a type or an aspect. If you need to know how to do that, or you want to learn more about the difference between types and aspects, you should read this tutorial.

Jeff

ivanatap
Champ in-the-making
Champ in-the-making
Hi Katie,

We have similar problem.
It looks like standard cmis does not recognize custom properties that we defined in Alfresco. We defined custom properties using types, not aspects, because we must use standard cmis, not Alfresco cmis extension, that work with aspects. So, that's why we didn't configure our properties using aspects (I guess we understood this problem correctly from your post).

We have successfully added property of document type through Alfresco, and it looks like this:

<type name="bc:doc">
  <title>Our Document</title>
   <parent>cm:content</parent>
      <properties>
                    <property name="bc:num">
                       <description>Doc Number</description>
                          <type>d:text</type>
                   </property>
            </properties>
</type>

Property bc:num appeared in Alfresco form on web share (after manually assigning type: bc:doc to our document), but the problem is that we could not edit value of that property through our OpenCMIS, and we tried to do that using this code:

private ObjectId createDocument(String barcode, String filePath, Folder dmsFolderTest) {
      Map<String, Object> properties = new HashMap<String, Object>();
      properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
      properties.put(PropertyIds.NAME, "some name");
      properties.put("bc:num", "12345");

      ContentStream contentStream = getFileContentStream(filePath);
               
      return dmsFolderTest.createDocument(properties, contentStream, VersioningState.NONE);            
   }

…or this code (after adding document and manually assigning "bc:doc"  type on our document using alfresco web form):

private void updateProperties(ObjectId documentId) {
      
      CmisObject document = session.getObject(documentId);

      Map<String, Object> updateproperties = new HashMap<String, Object>();
      updateproperties.put("bc:num", "12345");

      document.updateProperties(updateproperties);
      
   }


But this doesn't work, opencmis returns an exception "Property 'bc:num' is not valid for this type!".

Could anyone tell us where we are wrong???

ivanatap
Champ in-the-making
Champ in-the-making
Katie,

You seam to be lucky person for as, cause we solve the problem after posting to you. Smiley Happy
Actually, we forgot to define what type belongs property, and we do that like this changing: properties.put(PropertyIds.OBJECT_TYPE_ID, "D:bc:doc").

private ObjectId createDocument(String barcode, String filePath, Folder dmsFolderTest) {
      Map<String, Object> properties = new HashMap<String, Object>();
      properties.put(PropertyIds.OBJECT_TYPE_ID, "D:bc:doc");
      properties.put(PropertyIds.NAME, "some name");
      properties.put("bc:num", "12345");

      ContentStream contentStream = getFileContentStream(filePath);
              
      return dmsFolderTest.createDocument(properties, contentStream, VersioningState.NONE);           
   }

and

private void updateProperties(ObjectId documentId) {
     
      CmisObject document = session.getObject(documentId);

      Map<String, Object> updateproperties = new HashMap<String, Object>();
      updateproperties.put(PropertyIds.OBJECT_TYPE_ID, "D:bc:doc")
      updateproperties.put("bc:num", "12345");

      document.updateProperties(updateproperties);     
   }

Hope that we saved time to someone else. Smiley Happy

Mirjana & Ivana

Hello.

I have the same problem, in this moment i want create a document in alfresco in a particular folder.

This particular folder, have a folder rule; that add a particular aspect to the document.

After the creation of the document, i want to add some properties to that document.

I have this code …



        /*This method is for create the document*/
        public void PutFile(CMISDocument document)
        {
            IObjectId cmisObjectFolder = (IObjectId)session.GetObject(document.FolderId);

            IDictionary<string, object> properties = new Dictionary<string, object>();
            properties[PropertyIds.Name] = document.ContentStreamFileName;
            properties[PropertyIds.ObjectTypeId] = "cmis:document";
            properties[PropertyIds.CreationDate] = DateTime.Now;

            ContentStream contentStream = new ContentStream();
            contentStream.FileName = document.ContentStreamFileName;
            contentStream.MimeType = document.ContentStreamMimeType;
            contentStream.Length = document.Stream.Length;
            contentStream.Stream = document.Stream;

            IObjectId objectId = session.CreateDocument(properties, cmisObjectFolder, contentStream, DotCMIS.Enums.VersioningState.None);
           
            PutFileDetail(objectId,document.Owner);
        }

        /*This method is for add properties of a specific aspect*/
        internal void PutFileDetail(IObjectId objectId,string actorIdCard)
        {
            ICmisObject cmisObject = session.GetObject(objectId);

            IDictionary<string, object> properties = new Dictionary<string, object>();
            properties[PropertyIds.ObjectTypeId] = "adm:aridoctypBase";
            properties["adm:actidcard"] = actorIdCard;

            IObjectId newId = cmisObject.UpdateProperties(properties);

            if (newId.Id == cmisObject.Id)
            {
                // the repository updated this object - refresh the object
                cmisObject.Refresh();
            }
            else
            {
                // the repository created a new version - fetch the new version
                cmisObject = session.GetObject(newId);
            }
        }



With this code i can create the document but the method PutFileDetail result in a error:

Mensaje: Property +'adm:actidcard' is not valid for this type!   
Origen: DotCMIS   
Detalle:    at DotCMIS.Client.Impl.ObjectFactory.ConvertProperties(IDictionary`2 properties, IObjectType type, HashSet`1 updatabilityFilter)
   at DotCMIS.Client.Impl.AbstractCmisObject.UpdateProperties(IDictionary`2 properties, Boolean refresh)
   at DotCMIS.Client.Impl.AbstractCmisObject.UpdateProperties(IDictionary`2 properties)
   at CustomSystemFrameworks.CMISIntegration.CMISIntegrationRepository.PutFileDetail(IObjectId objectId, String actorIdCard) in C:\Corp\Projects\Colombia\CustomSystemFrameworks\AriDocsIntegration\CMISIntegrationRepository.cs:line 268
   at CustomSystemFrameworks.CMISIntegration.CMISIntegrationRepository.PutFile(CMISDocument document) in C:\Corp\Projects\Colombia\CustomSystemFrameworks\AriDocsIntegration\CMISIntegrationRepository.cs:line 257
   at WebUI.AriDocs.ibtnSave_Click(Object sender, ImageClickEventArgs e) in c:\Corp\Projects\Colombia\Presentation\AriDocs.aspx.cs:line 257
   
Método: ConvertProperties   
To String: System.ArgumentException: Property +'adm:actidcard' is not valid for this type!
   at DotCMIS.Client.Impl.ObjectFactory.ConvertProperties(IDictionary`2 properties, IObjectType type, HashSet`1 updatabilityFilter)
   at DotCMIS.Client.Impl.AbstractCmisObject.UpdateProperties(IDictionary`2 properties, Boolean refresh)
   at DotCMIS.Client.Impl.AbstractCmisObject.UpdateProperties(IDictionary`2 properties)
   at CustomSystemFrameworks.CMISIntegration.CMISIntegrationRepository.PutFileDetail(IObjectId objectId, String actorIdCard) in C:\Corp\Projects\Colombia\CustomSystemFrameworks\AriDocsIntegration\CMISIntegrationRepository.cs:line 268
   at CustomSystemFrameworks.CMISIntegration.CMISIntegrationRepository.PutFile(CMISDocument document) in C:\Corp\Projects\Colombia\CustomSystemFrameworks\AriDocsIntegration\CMISIntegrationRepository.cs:line 257
   at WebUI.AriDocs.ibtnSave_Click(Object sender, ImageClickEventArgs e) in c:\Corp\Projects\Colombia\Presentation\AriDocs.aspx.cs:line 257
   
 

 
Detalle Interno de Error    
Nivel del InnerException: 0
Mensaje: Property +'adm:actidcard' is not valid for this type! 
Origen: DotCMIS 
Detalle:    at DotCMIS.Client.Impl.ObjectFactory.ConvertProperties(IDictionary`2 properties, IObjectType type, HashSet`1 updatabilityFilter)
   at DotCMIS.Client.Impl.AbstractCmisObject.UpdateProperties(IDictionary`2 properties, Boolean refresh)
   at DotCMIS.Client.Impl.AbstractCmisObject.UpdateProperties(IDictionary`2 properties)
   at CustomSystemFrameworks.CMISIntegration.CMISIntegrationRepository.PutFileDetail(IObjectId objectId, String actorIdCard) in C:\Corp\Projects\Colombia\CustomSystemFrameworks\AriDocsIntegration\CMISIntegrationRepository.cs:line 268
   at CustomSystemFrameworks.CMISIntegration.CMISIntegrationRepository.PutFile(CMISDocument document) in C:\Corp\Projects\Colombia\CustomSystemFrameworks\AriDocsIntegration\CMISIntegrationRepository.cs:line 257
   at WebUI.AriDocs.ibtnSave_Click(Object sender, ImageClickEventArgs e) in c:\Corp\Projects\Colombia\Presentation\AriDocs.aspx.cs:line 257
 
Método: ConvertProperties 
To String: System.ArgumentException: Property +'adm:actidcard' is not valid for this type!
   at DotCMIS.Client.Impl.ObjectFactory.ConvertProperties(IDictionary`2 properties, IObjectType type, HashSet`1 updatabilityFilter)
   at DotCMIS.Client.Impl.AbstractCmisObject.UpdateProperties(IDictionary`2 properties, Boolean refresh)
   at DotCMIS.Client.Impl.AbstractCmisObject.UpdateProperties(IDictionary`2 properties)
   at CustomSystemFrameworks.CMISIntegration.CMISIntegrationRepository.PutFileDetail(IObjectId objectId, String actorIdCard) in C:\Corp\Projects\Colombia\CustomSystemFrameworks\AriDocsIntegration\CMISIntegrationRepository.cs:line 268
   at CustomSystemFrameworks.CMISIntegration.CMISIntegrationRepository.PutFile(CMISDocument document) in C:\Corp\Projects\Colombia\CustomSystemFrameworks\AriDocsIntegration\CMISIntegrationRepository.cs:line 257
   at WebUI.AriDocs.ibtnSave_Click(Object sender, ImageClickEventArgs e) in c:\Corp\Projects\Colombia\Presentation\AriDocs.aspx.cs:line 257
 



arronlee
Champ in-the-making
Champ in-the-making
Hi,
As for me, I am testing the related java barcode generation projects these days. Do you have any ideas about it? Or any good suggestion? I am totally a green hand on barcode generating field. Any suggestion will be appreciated. Thanks in advance.


Best regards,
Arron