Get all users of alfresco on java action

Showing results for 
Search instead for 
Did you mean: 
Senior Member

Get all users of alfresco on java action

Hi, i need to retrieve all the users of alfresco on a java action here the code i use :

   private NodeService nodeService;
    private OwnableService ownableService;
    private PersonService personService;
    private PermissionService permissionService;
    private AuthorityService authorityService;

 protected void executeImpl(Action action, NodeRef actionedUponNodeRef)  {
      PagingResults<PersonInfo> users =



            new ArrayList<QName>(),

            new ArrayList<Pair<QName,Boolean>>(),

            new PagingRequest(personService.countPeople())


  "The number of users in the system: " + personService.countPeople());
            for(;users.hasMoreItems()Smiley Wink //always false ???????
                for(PersonInfo personInfo : users.getPage()) {

                     //THIS PART OF CODE IS NEVER REACHED
                    String authority = personInfo.getUserName();
          "Analizzo Nodo Utente: " + authority);




It's the code right?

Because it's seem i never reach the code in the inner loop of users.getPage().


Just like Faust said i use the pagingResult in a wrong way. For anyone found it useful here is how resolve the problemastic by using a lucene query:

ResultSet rs = null;
                SearchParameters sp = new SearchParameters();
                sp.addLocale(new Locale("it", "IT"));
                sp.setQuery("TYPE:\"cmSmiley Tongueerson\"");
                //little hack to remove the limit from the query
                sp.addSort(new SortDefinition(SortType.FIELD,ContentModel.PROP_USERNAME.toString(), true));
                rs = searchService.query(sp);        
                long count = rs.getNumberFound();
      "The number of users in the system: " + personService.countPeople());
      "The number of users in the query : " + String.valueOf(count));
                for(int i=0;i<rs.length();i++){    
                    ResultSetRow row = rs.getRow(i);
                        NodeRef personNodeRef = row.getNodeRef();    
                        String authority = (String)nodeService.getProperty(personNodeRef,ContentModel.PROP_USERNAME);


             "Username:" + authority);


1 Reply

Re: Get all users of alfresco on java action

The pattern can be null, but your pattern of "*" is equally valid as both result in a DB SQL '%' (though Alfresco would be more efficient if it did not do the LIKE condition in this case at all).

Your use of the PagingResult is incorrect (check the JavaDoc!). getPage is always guaranteed to give you the current page of results, while hasMoreItems only specifies that you can get another page in another call with a different PagingRequest. Since you retrieved all people in one request, hasMoreItems will always yield false, causing your code not to be reached. PagingResult are not to be confused with regular Java iterators where your pattern of access would be correct.