04-20-2018 09:41 AM
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;
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
PagingResults<PersonInfo> users =
personService.getPeople(
"*",
new ArrayList<QName>(),
new ArrayList<Pair<QName,Boolean>>(),
new PagingRequest(personService.countPeople())
);
logger.info("The number of users in the system: " + personService.countPeople());
for(;users.hasMoreItems():smileywink: //always false ???????
{
for(PersonInfo personInfo : users.getPage()) {
//THIS PART OF CODE IS NEVER REACHED
String authority = personInfo.getUserName();
logger.info("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().
UPDATE
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.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery("TYPE:\"cmerson\"");
sp.setLimitBy(LimitBy.UNLIMITED);
//little hack to remove the limit from the query
sp.setMaxItems(-1);
sp.setMaxPermissionChecks(100000);
sp.setMaxPermissionCheckTimeMillis(100000);
sp.addSort(new SortDefinition(SortType.FIELD,ContentModel.PROP_USERNAME.toString(), true));
rs = searchService.query(sp);
long count = rs.getNumberFound();
logger.info("The number of users in the system: " + personService.countPeople());
logger.info("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);
...............................................................................
logger.info("Username:" + authority);
}
04-21-2018 06:42 AM
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.
Explore our Alfresco products with the links below. Use labels to filter content by product module.