0

Is it possible to do mass update using CMIS in alfresco.

I have Different Documents Types and Every Document type is having multiple documents in alfresco repository.

Now my requirement is, If i will Update any single property of any document, then it should reflect with all the documents of same type.

Can i do this USING CMIS?

If yes, please provide the steps and sample code to do this.

Thanks in Advance

Deepak Talape
  • 997
  • 1
  • 9
  • 35

2 Answers2

5

The hard way (and chatty way) is to query for your documents and then set the properties on each one. But the CMIS spec actually provides a better way: Bulk updates.

Here is what the code looks like:

ArrayList<CmisObject> docList = new ArrayList<CmisObject>();
Document doc1 = (Document) getSession().getObjectByPath("/bulk/bulktest1.txt");
docList.add(doc1);
Document doc2 = (Document) getSession().getObjectByPath("/bulk/bulktest2.txt");
docList.add(doc2);
Document doc3 = (Document) getSession().getObjectByPath("/bulk/bulktest3.txt");
docList.add(doc3);

HashMap<String, Object> props = new HashMap<String, Object>();
props.put("cmis:description", "description set in bulk");
List<BulkUpdateObjectIdAndChangeToken> updatedIds = getSession().bulkUpdateProperties(docList, props, null, null);

System.out.println("Updated " + updatedIds.size() + " docs.");

In my example I am grabbing each document by path, but of course you could run a query and build your list that way as well.

To use this with Alfresco you must use CMIS 1.1 and the browser binding so make sure your service URL is http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser.

Jeff Potts
  • 10,468
  • 17
  • 40
  • i am wrong when i am saying that there is no much difference between your solution and mine ?!? – Yagami Light Sep 14 '16 at 07:03
  • 1
    @YagamiLight This solution is handling the "in mass" part with the bulkupdate. Your is not. – Akah Sep 14 '16 at 07:12
  • 2
    The difference between my solution and yours (iterating over the results in a search set and setting the properties on each search result) is that each time you set the properties on an individual document, that's a trip to the server. In my solution, the client tells the server, "Make these changes on all of these documents", then the server does all of the changes which is more efficient, in part because it only involves a single trip to the server. – Jeff Potts Sep 14 '16 at 18:14
  • @JeffPotts Thank you for your answer – Yagami Light Sep 15 '16 at 13:44
  • @JeffPotts Do you have any experiences with concrete numbers here? For instance, should I be worried about updating, say, a million nodes this way? – Lista Sep 19 '16 at 09:17
  • I don't think it is possible to make a blanket statement about that. It's going to depend on the server implementation and server resources. But if you need to update a million nodes with the same value at once and you are using a CMIS repository, I'd want to step back and understand whether or not the right technology/approach is being applied to this problem. – Jeff Potts Sep 19 '16 at 15:13
1

the solution that i suggest to do in purpose of doing a lot of updates is to use CMIS query to select object with the same type (document,folder ...) you can learn more about it with Cmis Query

First Step

String query;
query = "SELECT * FROM cmis:document WHERE IN_FOLDER('" + objectId + "')";

and to get all the children

ItemIterable<QueryResult> resultList = session.query(query, false);

Note that for a purpose testing i selected in this query all the document that is inside a particular folder

Second Step

for (QueryResult qr : resultList) {

String idDocument = qr.getPropertyByQueryName("cmis:objectId").getFirstValue().toString();
Document doc = (Document) session.getObject(idDocument);

}

Now i use my query to get all the document that i want to update the properties.

Hope that helped you.

Yagami Light
  • 1,756
  • 4
  • 19
  • 39