use of org.alfresco.query.PagingRequest in project acs-community-packaging by Alfresco.
the class BaseReassignDialog 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;
UserTransaction tx = null;
ResultSet resultSet = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
int maxResults = Application.getClientConfig(context).getInviteUsersMaxResults();
if (maxResults <= 0) {
maxResults = Utils.getPersonMaxResults();
}
List<PersonInfo> persons = getPersonService().getPeople(Utils.generatePersonFilter(contains.trim()), true, Utils.generatePersonSort(), new PagingRequest(maxResults, null)).getPage();
ArrayList<SelectItem> itemList = new ArrayList<SelectItem>(persons.size());
for (PersonInfo person : persons) {
String username = person.getUserName();
if (AuthenticationUtil.getGuestUserName().equals(username) == false) {
String firstName = person.getFirstName();
String lastName = person.getLastName();
String name = (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : "");
SelectItem item = new SortableSelectItem(username, name + " [" + username + "]", lastName != null ? lastName : username);
itemList.add(item);
}
}
items = new SelectItem[itemList.size()];
itemList.toArray(items);
Arrays.sort(items);
// commit the transaction
tx.commit();
} 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];
} finally {
if (resultSet != null) {
resultSet.close();
}
}
return items;
}
use of org.alfresco.query.PagingRequest in project acs-community-packaging by Alfresco.
the class DeleteUserDialog method search.
public String search() {
if (this.searchCriteria == null || this.searchCriteria.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 = ISO9075.encode(this.searchCriteria);
List<Pair<QName, String>> filter = Utils.generatePersonFilter(search);
if (logger.isDebugEnabled()) {
logger.debug("Query filter: " + filter);
}
List<PersonInfo> persons = getPersonService().getPeople(filter, 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();
props.put("fullName", ((String) props.get("firstName")) + ' ' + ((String) props.get("lastName")));
NodeRef homeFolderNodeRef = (NodeRef) props.get("homeFolder");
if (homeFolderNodeRef != null) {
props.put("homeSpace", homeFolderNodeRef);
}
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 AddUsersDialog method pickerCallback.
// ------------------------------------------------------------------------------
// Helpers
/**
* 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, final String contains) {
final FacesContext context = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try {
// getUserTransaction(context);
RetryingTransactionHelper txHelper = Repository.getRetryingTransactionHelper(context);
return txHelper.doInTransaction(new RetryingTransactionCallback<SelectItem[]>() {
public SelectItem[] execute() throws Exception {
SelectItem[] items = new SelectItem[0];
// Use the Person Service to retrieve user details
String term = contains.trim();
if (term.length() != 0) {
List<PersonInfo> persons = getPersonService().getPeople(Utils.generatePersonFilter(contains.trim()), true, Utils.generatePersonSort(), new PagingRequest(Utils.getPersonMaxResults(), null)).getPage();
ArrayList<SelectItem> itemList = new ArrayList<SelectItem>(persons.size());
for (PersonInfo person : persons) {
String username = person.getUserName();
if (AuthenticationUtil.getGuestUserName().equals(username) == false) {
String firstName = person.getFirstName();
String lastName = person.getLastName();
// build a sensible label for display
String name = (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : "");
SelectItem item = new SortableSelectItem(username, name + " [" + username + "]", lastName != null ? lastName : username);
itemList.add(item);
}
}
items = new SelectItem[itemList.size()];
itemList.toArray(items);
}
return items;
}
});
} catch (BooleanQuery.TooManyClauses clauses) {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), "too_many_users"));
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
return new SelectItem[0];
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
return new SelectItem[0];
}
}
use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class GroupsImpl method getAuthoritiesInfo.
private PagingResults<AuthorityInfo> getAuthoritiesInfo(AuthorityType authorityType, Boolean isRootParam, String zoneFilter, Set<String> rootAuthorities, Pair<String, Boolean> sortProp, Paging paging) {
PagingResults<AuthorityInfo> pagingResult;
if (isRootParam != null) {
List<AuthorityInfo> groupList;
if (isRootParam) {
// Limit the post processing work by using the already loaded
// list of root authorities.
List<AuthorityInfo> authorities = rootAuthorities.stream().map(this::getAuthorityInfo).filter(auth -> zonePredicate(auth.getAuthorityName(), zoneFilter)).collect(Collectors.toList());
groupList = new ArrayList<>(rootAuthorities.size());
groupList.addAll(authorities);
// Post process sorting - this should be moved to service
// layer. It is done here because sorting is not supported at
// service layer.
AuthorityInfoComparator authorityComparator = new AuthorityInfoComparator(sortProp.getFirst(), sortProp.getSecond());
Collections.sort(groupList, authorityComparator);
} else {
PagingRequest pagingNoMaxItems = new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE);
// Get authorities using canned query but without using
// the requested paginating now because we need to filter out
// the root authorities.
PagingResults<AuthorityInfo> nonPagingResult = authorityService.getAuthoritiesInfo(authorityType, zoneFilter, null, sortProp.getFirst(), sortProp.getSecond(), pagingNoMaxItems);
// Post process filtering - this should be moved to service
// layer. It is done here because filtering by "isRoot" is not
// supported at service layer.
groupList = nonPagingResult.getPage();
if (groupList != null) {
for (Iterator<AuthorityInfo> i = groupList.iterator(); i.hasNext(); ) {
AuthorityInfo authorityInfo = i.next();
if (!isRootParam.equals(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName()))) {
i.remove();
}
}
}
}
// Post process paging - this should be moved to service layer.
pagingResult = Util.wrapPagingResults(paging, groupList);
} else {
PagingRequest pagingRequest = Util.getPagingRequest(paging);
// Get authorities using canned query.
pagingResult = authorityService.getAuthoritiesInfo(authorityType, zoneFilter, null, sortProp.getFirst(), sortProp.getSecond(), pagingRequest);
}
return pagingResult;
}
use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class PeopleImpl method getPeople.
@Override
public CollectionWithPagingInfo<Person> getPeople(final Parameters parameters) {
Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging);
List<Pair<QName, Boolean>> sortProps = getSortProps(parameters);
// For now the results are not filtered
// please see REPO-555
final PagingResults<PersonService.PersonInfo> pagingResult = personService.getPeople(null, null, sortProps, pagingRequest);
final List<PersonService.PersonInfo> page = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
List<Person> people = new AbstractList<Person>() {
@Override
public Person get(int index) {
PersonService.PersonInfo personInfo = page.get(index);
Person person = getPersonWithProperties(personInfo.getUserName(), parameters.getInclude());
return person;
}
@Override
public int size() {
return page.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, people, pagingResult.hasMoreItems(), totalItems);
}
Aggregations