How to get the name of a document in Alfresco with

2019-06-12 04:19发布

How to retrieve the name of a document from the Alfresco database (PostgreSQL)? I'm trying to get a list of documents created by a given user, e.g. admin, from a starting date, e.g. 2015-05-03:

SELECT child.child_node_name, node.audit_created
FROM alf_child_assoc child, alf_node node, alf_node_properties prop, alf_qname qname
WHERE child.child_node_id = node.id
AND node.id = prop.node_id
AND prop.qname_id = qname.id
AND qname.local_name = 'content'
AND node.audit_creator = 'admin'
AND node.audit_created > '2015-05-03'
ORDER BY node.audit_created

How do I get actual documents and not all content items? Because now it also displays full node references and I just want the human readable name of a document. Any suggestions?

By the way, I'm working on the back-end (Repository), not on Share. And I'm using Alfresco 5.0.1.

4条回答
beautiful°
2楼-- · 2019-06-12 04:45

Based on the other anwsers I created this query:

SELECT string_value AS document_name, audit_created AS creation_date
FROM alf_node node
INNER JOIN alf_node_properties ON (id=node_id)
INNER JOIN alf_qname ON (qname_id=alf_qname.id)
WHERE ns_id IN
(SELECT ns.id FROM alf_namespace AS ns
WHERE ns.uri='http://www.alfresco.org/model/content/1.0')
AND local_name='name'
AND audit_creator = 'admin'
AND audit_created > '2015-05-06'
ORDER BY audit_created;

This way you don't have to know the qname_id.

Thank you Sam, Gagravarr and streetturtle.

查看更多
聊天终结者
3楼-- · 2019-06-12 04:46

Updated

So here is SQL you need to use, this one for cm:content type:

select nd.audit_creator as creator, 
       np.string_value as document_name, 
       nd.audit_created as created_on
  from alf_node as nd, alf_node_properties as np, 
       alf_namespace ns, alf_qname qn, alf_qname qn1
 where nd.id=np.node_id
   and qn.ns_id = ns.id
   and nd.type_qname_id = qn.id
   and ns.uri = 'http://www.alfresco.org/model/content/1.0'
   and qn.local_name = 'content'
   and qn1.ns_id = ns.id
   and np.qname_id = qn1.id
   and qn1.local_name = 'name'
   and nd.audit_created > '2015-05-06 14:59:00';

It will return human readable document name, username of creator and date when this document was created.

And if you have some custom type of document, let's say ep:content with namespace http://www.mycomp.com/model/epersonnel/1.0 this query will do the work:

select nd.audit_creator as creator, 
       np.string_value as document_name, 
       nd.audit_created as created_on
  from alf_node as nd, alf_node_properties as np, 
       alf_namespace ns, alf_namespace ns1, alf_qname qn, alf_qname qn1
 where nd.id=np.node_id
   and qn.ns_id = ns.id
   and nd.type_qname_id = qn.id
   and ns.uri = 'http://www.mycomp.com/model/epersonnel/1.0'
   and qn.local_name = 'content'
   and ns1.uri = 'http://www.alfresco.org/model/content/1.0'
   and np.qname_id = qn1.id
   and qn1.ns_id = ns1.id
   and qn1.local_name = 'name'
   and nd.audit_created > '2015-05-06 14:59:00';
查看更多
走好不送
4楼-- · 2019-06-12 04:55

In Alfresco, the name of a document is a property of of type cm:name / http://www.alfresco.org/model/content/1.0:name

So, first up, find the ID of that qname. It may vary between Alfresco installs, depending on the order things got added during setup, but it will be constant for an Alfresco repository. Query is:

=> select * from alf_qname where ns_id IN 
     (select ns.id from alf_namespace as ns 
     where ns.uri='http://www.alfresco.org/model/content/1.0') 
   and local_name='name';
 id | version | ns_id | local_name 
----+---------+-------+------------
 29 |       0 |     6 | name
(1 row)

Now, search for documents by name, using the ID from there:

select uuid, string_value AS name from alf_node 
   inner join alf_node_properties on (id=node_id) 
   where qname_id = 29;

That will give you all the node UUIDs (main part of the noderef) along with their names.

Add more node filters as required!

查看更多
成全新的幸福
5楼-- · 2019-06-12 05:10

I ran this SQL script to find the equivalent qname id for this property

select * from alf_qname where local_name='name';

I got 2 rows with id 21 and 29 but figured out the interesting one is 29.

SELECT * FROM alf_node_properties where qname_id = '29';

You will get name for any node not only files.

You can find useful queries http://streetturtle.ninja/2015/05/01/usefule-alfresco-queries/

Hope this help

Good luck, Sam

查看更多
登录 后发表回答