简体   繁体   中英

Selecting users,groups and site from alfresco database

I would like to select users,in which groups they belong to, and their sites. I want it with a single postgre sql query.

I've found these queries, but i want them combined with join if possible.

select * from alf_permission

select * from ALF_AUTHORITY 

select * from ALF_CHILD_ASSOC where CHILD_NODE_NAME like ‘group%’

select * from ALF_CHILD_ASSOC where QNAME_LOCALNAME like ‘GROUP%’



select
    node_id,
    string_agg(string_value, ',')
from (
    select
        node_id,
        qname_id,
        (select local_name from alf_qname where id = qname_id) as qname_type,
        string_value
    from alf_node_properties
    where node_id in (
        select id from alf_node 
        where type_qname_id = (
            select id from alf_qname where local_name = 'person'
        )
        and qname_id in (
            select id
            from  alf_qname 
            where local_name in (
                'username',
                'firstName',
                'lastName',
                'email'     
            )
        )
    )
) alf_users
group by node_id;

我建议尽可能用Java创建网络脚本,以实现快速高效的操作!

I found a solution! I put the script in Company Home > Data Dictionary > Web Scripts > org > alfresco > test

As you can see i created the "test" folder in "alfresco" folder, and in it i put these three files.

hello.get.html.ftl file

<table border>
<tr>
    <th>Username</th>
    <th>Groups</th>
    <th>Sites</th>
</tr>

<#list test as child>
<tr>
    <td>${child['username']}</td>
    <td>${child['groups']}</td>
    <td>${child['sites']}</td>
</tr>
</#list>
</table>

hello.get.desc.xml

<webscript>
  <shortname>Hello</shortname>
  <description>Polite greeting</description>
  <url>/test/hello</url>
  <authentication>user</authentication>
</webscript>

hello.get.js

var gens = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}person\"");
var a = [];

for (var i=0; i<gens.length;i++) {
 var username = gens[i].properties["cm:userName"];

 var b = [];
 var groups = people.getContainerGroups(gens[i]);
 for(var j=0; j<groups.length; j++) {
  b.push(groups[j].properties['authorityDisplayName']);
 }

 var sites = siteService.listUserSites(username);
 var g=[]
 for(var j=0; j<sites.length; j++) {
        g.push(sites[j]['shortName']);
 }

 //a.push('\n\n\n'+username+'\groups--> '+ b.join(', ') + '\nsites--> '+g.join(', '));
 a.push({
    'username' : username,
    'groups' : b.join(', '),
    'sites' : g.join(', ')
 })
}

model.test = a;

you can access the result in your_domain_name/alfresco/service/test/hello

Try this query to get persons and groups

select 
ca.id,
ca.parent_node_id,
ca.child_node_id,
ca.qname_localname,
np.string_value
from alf_child_assoc as ca
join alf_node as child on child.id = ca.child_node_id
join alf_node as parent on parent.id = ca.parent_node_id
join alf_qname as q1 on q1.id = parent.type_qname_id
join alf_qname as q2 on q2.id = child.type_qname_id
join alf_node_properties as np on np.node_id = parent.id
where q1.local_name = 'authorityContainer'
and q2.local_name = 'person'
and np.qname_id = (select id from alf_qname where local_name = 
 'authorityDisplayName')
order by ca.qname_localname;`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM