cancel
Showing results for 
Search instead for 
Did you mean: 

How to access to document 'Categories' via CMIS

vodok
Champ in-the-making
Champ in-the-making
Hi,

I am tottaly new as Alfresco applications developer in Java.

I am creating a maven plugin which creates new versions of all documents under a determined folder depending on the category of those documents. I've been able to create new versions of all documents but I don't know how to get all the different document categories defined in Alfresco nor how to get the different categories a document might be associated to. After reading a lot I think it has something to do with "Aspects" but I am using CMIS and I think such aspect is not accessible via CMIS.

1. Am I in the right direction?
2. Do you know how to get categories associated to a document via CMIS?
3. Do you know how to access to Alfresco defined categories via CMIS?

Thank you very much.

I show you a little brief of the code in case I didn't explain myself Smiley Tongue

<java>
….
if (tree.getChildren().isEmpty()) {
   Document doc = (Document) tree.getItem();
   //HERE I WOULD NEED TO CHECK DOCUMENT CATEGORY AND DEPENDING ON CATEGORY I WOULD CREATE NEW VERSION OR NOT
//EXAMPLE PSEUDO CODE
//If (doc.getCategory == Alfresco.getCategoriesByTag(/Languages/spanish){

      

// Versioning…
   getLog().info("\nVersionando documento: "+doc.getName());
   getLog().info("————-");
         
// check whether is versionable or not
      if (((DocumentType) (doc.getType())).isVersionable()) {
   getLog().info("Tipo del archivo: "+doc.getName()+":"+doc.getType().getDisplayName());
   getLog().info(doc.getName() + " es versionable y su BaseType es: "+doc.getBaseType().getDisplayName());
            docsVersionados.add(doc.getName());
            
// realizamos el check out de la última versión del documento,
// modificamos la PWC y realizamos el check in de la nueva versión
      Document pwc = (Document) session.getObject(doc.checkOut());
// Check in the pwc
        try {
     pwc.checkIn(false, null, pwc.getContentStream(),comentarioNuevaVersion);
   } catch (Exception e) {
       e.printStackTrace();
           System.out.println("checkin failed, trying to cancel the checkout");
           pwc.cancelCheckOut();
   }
…..

..
<java>
2 REPLIES 2

jpotts
World-Class Innovator
World-Class Innovator
You will not be able to achieve this using pure CMIS. Even if you do use the OpenCMIS Extension for Alfresco to work with the cm:generalclassifiable aspect, you'll find that the categories property is a list of category objects. Because those objects don't inherit from folder or content or another base object that CMIS recognizes, they are not "CMIS objects" and cannot be referenced from CMIS.

To work around this, I'd create a custom web script that accepts a list of object IDs and returns back the object IDs along with the list of categories for each object. Note that the CMIS object ID is not necessarily equal to the Alfresco object ID, so don't call your new web script with the CMIS object ID. Instead use the value of the alfcmis:nodeRef property.

Alternatively, you could write a rule or behavior that persists the list of actual category names onto the object any time the categorization changes. Then you could access that list via CMIS. Of course the drawback here is that any time a category name changes your documents will be out of sync unless you handle that as well.

Hope that helps,

Jeff

vodok
Champ in-the-making
Champ in-the-making
Hi jpotts!

Thanks for your answer. So I will forget about using OpenCMIS. As I told you I am a total begginer and I must admit I got lost with your two options. In the other hand I've been checking the web services Alfresco provides and I have found these:

Classification Web Service: With this one I could get categories defined in Alfresco, couldn't I?
The version service: With this one I could create new versions of documents
Repository Web Service: And maybe with this one I could get every document associated to a category?

Now you know what I am planning to do, do you think I could try this aproach using only web services in order to create new versions of the documents stored at a certain location depending on the category they are assocated to?

Thanks in advance.