<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Extract groups that have no users. in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/extract-groups-that-have-no-users/m-p/107075#M30196</link>
    <description>&lt;P&gt;Thank you very much &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://connect.hyland.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 12 May 2020 15:47:28 GMT</pubDate>
    <dc:creator>ALfreSara</dc:creator>
    <dc:date>2020-05-12T15:47:28Z</dc:date>
    <item>
      <title>Extract groups that have no users.</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/extract-groups-that-have-no-users/m-p/107073#M30194</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to extract groups that have no users.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The execution of the script JavaScript console runs until it crashes, Because there are several groups in Alfresco but I know how to deal with this problem.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var pagingGroup = utils.createPaging(-1,0);&lt;BR /&gt;var siteGroups = groups.getGroups(null, pagingGroup);&lt;/P&gt;&lt;P&gt;for (var i=0; i&amp;lt;siteGroups.length; i++)&lt;BR /&gt;{&lt;BR /&gt;userCount = siteGroups[i].getUserCount();&lt;BR /&gt;if(userCount==0){&lt;BR /&gt;logger.log(siteGroups[i].displayName);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Any help please!!&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2020 10:54:12 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/extract-groups-that-have-no-users/m-p/107073#M30194</guid>
      <dc:creator>ALfreSara</dc:creator>
      <dc:date>2020-05-11T10:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Extract groups that have no users.</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/extract-groups-that-have-no-users/m-p/107074#M30195</link>
      <description>&lt;P&gt;There are several ways i can think of. And your code works as well but crashes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;U&gt;&lt;STRONG&gt;1- Using AuthorityService in a java backed webscript&lt;/STRONG&gt;&lt;/U&gt;:&lt;/P&gt;

&lt;PRE&gt;final Set&amp;lt;String&amp;gt; groups = authorityService.getAllAuthoritiesInZone("APP.DEFAULT",AuthorityType.GROUP);
for (final String groupFQN : groups) {
  final Set&amp;lt;String&amp;gt; users = authorityService.getContainedAuthorities(AuthorityType.USER, groupFQN, true);
  LOGGER.info("Users in '{}' group are: {}", groupFQN, users);
  if(users.isEmpty()) {
&lt;STRONG&gt;    LOGGER.info("########## Group '{}' has no users ########", groupFQN);
&lt;/STRONG&gt;  }
}&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;U&gt;&lt;STRONG&gt;2- Using javascript with zone filtering:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;//When targetting to default zone. &lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;PRE&gt;var paging = utils.createPaging(-1,0);&lt;BR /&gt;&lt;STRONG&gt;//When targetting to default zone. &lt;/STRONG&gt;
var defaultZone = groups.getGroupsInZone("*", "APP.DEFAULT", paging, "displayName");

for (var each=0; each&amp;lt;defaultZone.length; each++)
{
  var userCount = defaultZone[each].getUserCount();
  if(userCount==0){
   logger.log("Group '" + defaultZone[each].displayName+"' doesn't have members");
  }
}&lt;/PRE&gt;

&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;//When targetting to share site zone. &lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;PRE&gt;var paging = utils.createPaging(-1,0);&lt;BR /&gt;//When targetting to site zone.
var siteGroups = groups.getGroupsInZone("*", "APP.SHARE", paging, "displayName");

for (var each=0; each&amp;lt;siteGroups.length; each++)
{
  var userCount = siteGroups[each].getUserCount();
  if(userCount==0){
     logger.log("Group '" + siteGroups[each].displayName+"' doesn't have members");
    }
}&lt;/PRE&gt;
&lt;P&gt;You may be looking for groups in APP.DEFAULT zone most probably, so no need to get all the groups from all the zones. This might be reason why your code takes a lot of time to complete and browser crashes.&lt;/P&gt;
&lt;P&gt;Depending on number of groups and number of sites the processing will take time and browser will hang if you try to get all the groups via JS.&lt;BR /&gt;If you still intend to fetch groups from all zones then i would suggest to go with &lt;STRONG&gt;Java backed webscript&lt;/STRONG&gt; and use the approach given in &lt;STRONG&gt;option 1 above&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Refer this doc for more details: &lt;A href="https://docs.alfresco.com/4.1/references/API-JS-getGroupsInZone.html" target="_blank" rel="noopener nofollow noreferrer"&gt;https://docs.alfresco.com/4.1/references/API-JS-getGroupsInZone.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;3- Using REST API:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;- Get the groups by calling: &lt;A href="http://127.0.0.1:8080/alfresco/service/api/groups?shortNameFilter=*&amp;amp;zone=APP.DEFAULT&amp;amp;maxItems=250&amp;amp;sortBy=displayName" target="_blank" rel="noopener nofollow noreferrer"&gt;http://127.0.0.1:8080/alfresco/service/api/groups?shortNameFilter=*&amp;amp;zone=APP.DEFAULT&amp;amp;maxItems=250&amp;amp;sortBy=displayName&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;- Parse the json response and iterate by each group FQN and then call the following api to get the members: &lt;BR /&gt;&lt;A href="http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/groups/{id}/members" target="_blank" rel="noopener nofollow noreferrer"&gt;http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/groups/{id}/members&lt;/A&gt;, where id is the FQN of group.&lt;BR /&gt;&lt;BR /&gt;e.g.: &lt;A href="http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/groups/" target="_blank" rel="noopener nofollow noreferrer"&gt;http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/groups/&lt;/A&gt;&lt;EM&gt;&lt;STRONG&gt;GROUP_ALFRESCO_ADMINISTRATORS&lt;/STRONG&gt;&lt;/EM&gt;/members&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;- Parse the response and calculate whether there are users in the selected group&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2020 21:44:05 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/extract-groups-that-have-no-users/m-p/107074#M30195</guid>
      <dc:creator>abhinavmishra14</dc:creator>
      <dc:date>2020-05-11T21:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extract groups that have no users.</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/extract-groups-that-have-no-users/m-p/107075#M30196</link>
      <description>&lt;P&gt;Thank you very much &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://connect.hyland.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 15:47:28 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/extract-groups-that-have-no-users/m-p/107075#M30196</guid>
      <dc:creator>ALfreSara</dc:creator>
      <dc:date>2020-05-12T15:47:28Z</dc:date>
    </item>
  </channel>
</rss>

