use of org.alfresco.query.PagingRequest in project acs-community-packaging by Alfresco.
the class BaseInviteUsersWizard method getGroups.
protected Set<String> getGroups(String search, boolean includeEveryone) {
Set<String> groups;
if (search != null && search.startsWith("*")) {
// if the search term starts with a wildcard use Lucene based search to find groups (results will be inconsistent)
String term = search.trim() + "*";
groups = getAuthorityService().findAuthorities(AuthorityType.GROUP, null, false, term, AuthorityService.ZONE_APP_DEFAULT);
} else {
// all other searches use the canned query so search results are consistent
PagingResults<String> pagedResults = getAuthorityService().getAuthorities(AuthorityType.GROUP, AuthorityService.ZONE_APP_DEFAULT, search, true, true, new PagingRequest(10000));
groups = new LinkedHashSet<String>(pagedResults.getPage());
}
if (includeEveryone) {
// add the EVERYONE group to the results
groups.addAll(getAuthorityService().getAllAuthorities(AuthorityType.EVERYONE));
}
return groups;
}
use of org.alfresco.query.PagingRequest in project acs-community-packaging by Alfresco.
the class GroupsDialog method displayGroups.
/**
* Searches for groups or lists groups of the current group context
*/
private void displayGroups() {
// empty the list before we begin the search for a new list
this.groupsRichList.setValue(null);
List<String> authorities;
if (this.group == null) {
// Use the search criteria if we are not searching for everything
String search = null;
if (!this.searchAll) {
if (this.groupsSearchCriteria == null) {
search = null;
} else {
search = groupsSearchCriteria.trim();
if (search.length() == 0) {
search = null;
} else {
// Let's make it search on the short name/display name prefix
search = search + "*";
}
}
}
if (!this.searchAll && search == null) {
// Do not allow empty searches
this.groups = Collections.<Map<String, String>>emptyList();
return;
} else {
boolean immediate = (this.filterMode.equals(FILTER_CHILDREN));
if ((search != null && search.startsWith("*")) || immediate) {
// if the search term starts with a wildcard or is for immediate children only then use Solr/Lucene based search query to find groups (note:
// results will be eventually consistent if using Solr, rather than embedded Lucene)
Set<String> results = this.authService.findAuthorities(AuthorityType.GROUP, this.group, immediate, search, AuthorityService.ZONE_APP_DEFAULT);
authorities = new ArrayList<String>(results);
} else {
// all other searches use the canned query so search results are consistent
PagingResults<String> pagedResults = this.authService.getAuthorities(AuthorityType.GROUP, AuthorityService.ZONE_APP_DEFAULT, search, true, true, new PagingRequest(10000));
authorities = pagedResults.getPage();
}
}
} else {
// child groups of the current group
Set<String> results = this.getAuthorityService().getContainedAuthorities(AuthorityType.GROUP, this.group, true);
authorities = new ArrayList<String>(results);
}
this.groups = new ArrayList<Map<String, String>>(authorities.size());
for (String authority : authorities) {
Map<String, String> authMap = new HashMap<String, String>(8);
String name = this.authService.getAuthorityDisplayName(authority);
if (name == null) {
name = this.authService.getShortName(name);
}
authMap.put("name", name);
authMap.put("id", authority);
authMap.put("group", authority);
authMap.put("groupName", name);
this.groups.add(authMap);
}
}
use of org.alfresco.query.PagingRequest in project records-management by Alfresco.
the class ExtendedSecurityServiceImpl method findIPRGroup.
/**
* Given a group name prefix and the authorities, finds the exact match existing group.
* <p>
* If the group does not exist then the group returned is null and the index shows the next available
* group index for creation.
*
* @param groupPrefix group name prefix
* @param authorities authorities
* @return Pair<String, Integer> where first is the name of the found group, null if none found and second
* if the next available create index
*/
private Pair<String, Integer> findIPRGroup(String groupPrefix, Set<String> authorities) {
String iprGroup = null;
int nextGroupIndex = 0;
boolean hasMoreItems = true;
int pageCount = 0;
// determine the short name prefix
String groupShortNamePrefix = getIPRGroupPrefixShortName(groupPrefix, authorities);
// iterate over the authorities to find a match
while (hasMoreItems == true) {
// get matching authorities
PagingResults<String> results = authorityService.getAuthorities(AuthorityType.GROUP, RMAuthority.ZONE_APP_RM, groupShortNamePrefix, false, false, new PagingRequest(MAX_ITEMS * pageCount, MAX_ITEMS));
// record the total count
nextGroupIndex = nextGroupIndex + results.getPage().size();
// see if any of the matching groups exactly match
for (String group : results.getPage()) {
// if exists and matches we have found our group
if (isIPRGroupTrueMatch(group, authorities)) {
iprGroup = group;
break;
}
}
// determine if there are any more pages to inspect
hasMoreItems = results.hasMoreItems();
pageCount++;
}
return new Pair<String, Integer>(iprGroup, nextGroupIndex);
}
use of org.alfresco.query.PagingRequest in project acs-community-packaging by Alfresco.
the class UsersDialog method search.
/**
* Event handler called when the user wishes to search for a user
*
* @return The outcome
*/
public String search() {
properties.getUsersRichList().setValue(null);
if (properties.getSearchCriteria() == null || properties.getSearchCriteria().trim().length() == 0) {
this.users = Collections.<Node>emptyList();
} else {
FacesContext context = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
// define the query to find people by their first or last name
String search = properties.getSearchCriteria();
if (logger.isDebugEnabled()) {
logger.debug("Query filter: " + search);
}
List<PersonInfo> persons = properties.getPersonService().getPeople(Utils.generatePersonFilter(search), true, Utils.generatePersonSort(), new PagingRequest(Utils.getPersonMaxResults(), null)).getPage();
if (logger.isDebugEnabled()) {
logger.debug("Found " + persons.size() + " users");
}
this.users = new ArrayList<Node>(persons.size());
for (PersonInfo person : persons) {
// create our Node representation
MapNode node = new MapNode(person.getNodeRef());
// set data binding properties
// this will also force initialisation of the props now during the UserTransaction
// it is much better for performance to do this now rather than during page bind
Map<String, Object> props = node.getProperties();
String firstName = (String) props.get("firstName");
String lastName = (String) props.get("lastName");
props.put("fullName", (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : ""));
NodeRef homeFolderNodeRef = (NodeRef) props.get("homeFolder");
if (homeFolderNodeRef != null) {
props.put("homeSpace", homeFolderNodeRef);
}
node.addPropertyResolver("sizeLatest", this.resolverUserSizeLatest);
node.addPropertyResolver("quota", this.resolverUserQuota);
node.addPropertyResolver("isMutable", this.resolverUserMutable);
this.users.add(node);
}
// commit the transaction
tx.commit();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { "root" }));
this.users = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
this.users = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
// return null to stay on the same page
return null;
}
use of org.alfresco.query.PagingRequest in project acs-community-packaging by Alfresco.
the class BaseInviteUsersWizard method pickerCallback.
/**
* Query callback method executed by the Generic Picker component.
* This method is part of the contract to the Generic Picker, it is up to the backing bean
* to execute whatever query is appropriate and return the results.
*
* @param filterIndex Index of the filter drop-down selection
* @param contains Text from the contains textbox
*
* @return An array of SelectItem objects containing the results to display in the picker.
*/
public SelectItem[] pickerCallback(int filterIndex, String contains) {
FacesContext context = FacesContext.getCurrentInstance();
// quick exit if not enough characters entered for a search
String search = contains.trim();
int searchMin = Application.getClientConfig(context).getPickerSearchMinimum();
if (search.length() < searchMin) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, MSG_SEARCH_MINIMUM), searchMin));
return new SelectItem[0];
}
SelectItem[] items;
this.maxUsersReturned = false;
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
int maxResults = Application.getClientConfig(context).getInviteUsersMaxResults();
if (maxResults <= 0) {
maxResults = Utils.getPersonMaxResults();
}
List<SelectItem> results;
if (filterIndex == 0) {
// Use lucene search to retrieve user details
List<Pair<QName, String>> filter = null;
if (search == null || search.length() == 0) {
// if there is no search term, search for all people
} else {
filter = Utils.generatePersonFilter(search);
}
if (logger.isDebugEnabled()) {
logger.debug("Maximum invite users results size: " + maxResults);
logger.debug("Using query filter to find users: " + filter);
}
List<PersonInfo> persons = getPersonService().getPeople(filter, true, Utils.generatePersonSort(), new PagingRequest(maxResults, null)).getPage();
results = new ArrayList<SelectItem>(persons.size());
for (int index = 0; index < persons.size(); index++) {
PersonInfo person = persons.get(index);
String firstName = person.getFirstName();
String lastName = person.getLastName();
String username = person.getUserName();
if (username != null) {
String name = (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : "");
SelectItem item = new SortableSelectItem(username, name + " [" + username + "]", lastName != null ? lastName : username);
results.add(item);
}
}
} else {
results = addGroupItems(search, maxResults);
}
items = new SelectItem[results.size()];
results.toArray(items);
Arrays.sort(items);
// set the maximum users returned flag if appropriate
if (results.size() == maxResults) {
this.maxUsersReturned = true;
}
// commit the transaction
tx.commit();
} catch (BooleanQuery.TooManyClauses clauses) {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), "too_many_users"));
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
items = new SelectItem[0];
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
items = new SelectItem[0];
}
return items;
}
Aggregations