How to retrieve all document content from alfresco

2019-05-10 22:32发布

I Want to retrieve All document content from alfresco repository. So can anyone help me that how can i traverse the repository using CMIS. And while traversing i also want to separate the documents based on its type.

At this moment i am able to get any one document by specifying the path. but now my requirement is to traverse whole repository and get all the documents.

So can any one help me with this. Also suggest me that "Traversal of all folders and later separate by specific type" will be the good approach OR "Search specific type of document using CMIS query" will be the good approach.

Thanks in Advance.

2条回答
够拽才男人
2楼-- · 2019-05-10 23:06

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

查看更多
啃猪蹄的小仙女
3楼-- · 2019-05-10 23:10

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.

查看更多
登录 后发表回答