0

I'm having some troubles adding metadata to a document that I am programmatically creating in alfresco.

I'm using dotCMIS library for this.

I have the following code:

IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.Name] = "title.doc";
properties[PropertyIds.ObjectTypeId] = "cmis:document";

ContentStream contentStream = new ContentStream();
contentStream.FileName = "title.doc";
contentStream.MimeType = "application/msword";
contentStream.Length = bytes.Length;
contentStream.Stream = new MemoryStream(bytes);
IDocument doc = folder.CreateDocument(properties, contentStream, null);

So i would also like to set for example, title and description aswell as keywords, references etc ... but I don't know how.

I tried something like that:

properties["cm:title"] = "some title";

OR

properties["cmis:title"] = "some title";

But still no success any idea, how to do it?

Note: i also tried to return all properties from document, but those are not in there, so how do i set them then?

I have this:

    string queryGetDoc = "SELECT * FROM cmis:document WHERE cmis:name='document.doc'";
    IItemEnumerable<IQueryResult> docResults = session.Query(queryGetDoc, false);
    IQueryResult docHit = docResults.FirstOrDefault();
    string docId = docHit["cmis:objectId"].FirstValue.ToString();

      IDocument document = session.GetObject(docId) as IDocument;

        IList<IProperty> listOfProperties = document.Properties;

        foreach(IProperty p in listOfProperties)
        {
            Console.WriteLine(p.QueryName); 
        }

And i receive this:

cmis:isLatestMajorVersion
cmis:contentStreamLength
cmis:contentStreamId
cmis:versionSeriesCheckedOutBy
cmis:objectTypeId
cmis:versionSeriesCheckedOutId
cmis:name
cmis:contentStreamMimeType
cmis:versionSeriesId
cmis:creationDate
cmis:changeToken
cmis:versionLabel
cmis:isLatestVersion
cmis:isVersionSeriesCheckedOut
cmis:lastModifiedBy
cmis:createdBy
cmis:checkinComment
cmis:objectId
cmis:isImmutable
cmis:isMajorVersion
cmis:baseTypeId
cmis:contentStreamFileName
cmis:lastModificationDate

Does it mean that other props do not exist on the document? Although in graphical user interface i can set the Title and Description, aswell as keywords and reference ...

What is going on, anyone any idea?

Zlatko
  • 18,936
  • 14
  • 70
  • 123
Alnedru
  • 2,573
  • 9
  • 50
  • 88
  • Have you tried setting a title and description on a document using Alfresco, then querying it via CMIS? The query you did will only return the properties that have been set, it won't tell you the ones available to be set – Gagravarr Mar 25 '13 at 08:59
  • yes i did, firstly i did set title and description of the document and only then tried to get all the possible properties but they were not in. Although document was at released state and available, really have no idea what it could be, maybe the properties are not exposed outside of alfresco protal itself :( – Alnedru Mar 26 '13 at 06:45
  • They should be - all sorts of things will break if they're not! Are you sure you're querying the correct node for its properties? – Gagravarr Mar 26 '13 at 08:30
  • what do you mean the correct node? I'm just saying document.Properties, i dont understand what you mean about node? – Alnedru Mar 27 '13 at 06:36
  • Step #1 - create a document in Alfresco. Step #2 - set a title and description on it. Step #3 - fetch all the properties on *that node* back via CMIS. If you query a different node, you won't see the correct properties... – Gagravarr Mar 27 '13 at 06:39

1 Answers1

3

If you're new to CMIS, and want to easily check what properties / options / etc your repository contains, the best way to learn and investigate is with the Apache Chemistry CMIS Workbench. It's a standalone Java tool for querying and browsing your repo

First, as mentioned in the comments, create a test file in Alfresco with a Title and Description set: Properties

Next, fire up the Apache Chemistry CMIS Workbench, connect to your repo, browse to the node in question, and view the standard properties:

CMIS Props

Finally, look at the extensions, to see how the Alfresco specific parts (such as Title and Description) are exposed:

extensions

So, you'll need to work with the the Title and Description as extensions, as Documented on the Alfresco Wiki. You'll likely also want to look at the Alfresco Extension for OpenCMIS and then do something similar for .Net

Gagravarr
  • 47,320
  • 10
  • 111
  • 156
  • so does this mean that dotCMIS (.net version) doesn't implement does aspects? Because i was trying like in opencmis doing this stuff, but i always got an error that this cmis:description doesnt exits etc – Alnedru Mar 27 '13 at 07:34
  • dotCMIS works just fine with extensions (which is how Alfresco Aspects get mapped onto CMIS), there's just no helper like there is for Java. `cmis:description` doesn't exist, that's correct, `cm:description` in Alfresco comes through as an extension `cm:description` in the Alfresco namespace, as shown in the workbench – Gagravarr Mar 27 '13 at 07:37
  • Yes, you are right in extensions i see that there is cm:description – Alnedru Mar 27 '13 at 07:46
  • so basically in dotCMIS i have to work somehow with the extensions to be able to set it right? i see that there is something like document.GetExtensions(...), i don't know how to do it tho yet ... – Alnedru Mar 27 '13 at 07:47
  • Yes i succeeded to retreive them successfully, but how to set them, that is the question now :( – Alnedru Mar 27 '13 at 08:26
  • nah, not really, i only can view, but i still have no idea how to update it, or add something :( and then save it – Alnedru Mar 27 '13 at 12:19