How to retrieve all document content from alfresco repository with seperation of document types using Open CMIS

痴心易碎 提交于 2019-12-06 02:30:00
Jeff Potts

Yagami's answer is a good start, but there are a few things to add.

First, do not do "select *" unless you actually need every single property the repository has. That is a potential performance problem. Only ask for what you need.

Second, one of your comments talks about segmenting results by type. In CMIS, a type is kind of like a SQL table. So in your case, you would do three different queries using each of your three custom types as a different type in the from clause:

select * from test:mainContract;
select * from test:subContract;
select * from test:royaltyStatement;

Finally, unless you have just a handful of documents in your repository, you are almost certainly going to want to use a paged result set. Otherwise, you will only get back the maximum number of results the server is configured to return. That may not be large enough to get the entire set.

For an example showing paging the result set, see Apache CMIS: Paging query result

To perform an action like this (getting all the document content) you need to follow this steps

Step 1 : Create a saver Class

What i mean with sever class, it will hold two information (for me it's the most valuable informations) the two of them most be character varying

1 - The document ID

2 - The document Name

Step 2 : Get all the document

To get all the document we have to use a query

String query;
query = "SELECT * FROM cmis:document ";

You will get all the document that you have in your repository.

You can add some condition to make your research more easier like in this example :

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

In this example you will get document of a particular folder.

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

and finally

for (QueryResult qr : resultList) {    
String idDocument = qr.getPropertyByQueryName("cmis:objectId").getFirstValue().toString();
String name = qr.getPropertyByQueryName("cmis:name").getFirstValue().toString();
Document doc = (Document) session.getObject(idDocument);// this is how you can get document with add that's mean no need of path     
}

You can read more about query in CMIS query.

Step 3 : Save every time the information in the saver class

I think it's clear that you have to save every time you use the loop (in step 2) in an occurence of saver class.

I hope that helped you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!