use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class QuickShareLinksImpl method findLinks.
public CollectionWithPagingInfo<QuickShareLink> findLinks(Parameters parameters) {
checkEnabled();
String queryString = "ASPECT:\"" + QuickShareModel.ASPECT_QSHARE.toString() + "\"";
SearchParameters sp = new SearchParameters();
// note: REST API query parameter (ie. where clause filter) - not to be confused with search query ;-)
Query q = parameters.getQuery();
if (q != null) {
// filtering via "where" clause
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(FIND_SHARED_LINKS_QUERY_PROPERTIES, null);
QueryHelper.walk(q, propertyWalker);
String sharedByUserId = propertyWalker.getProperty(PARAM_SHAREDBY, WhereClauseParser.EQUALS, String.class);
if (sharedByUserId != null) {
if (People.DEFAULT_USER.equalsIgnoreCase(sharedByUserId)) {
sharedByUserId = AuthenticationUtil.getFullyAuthenticatedUser();
}
QueryParameterDefinition qpd = new QueryParameterDefImpl(QuickShareModel.PROP_QSHARE_SHAREDBY, dictionaryService.getDataType(DataTypeDefinition.TEXT), true, sharedByUserId);
sp.addQueryParameterDefinition(qpd);
String qsharedBy = QuickShareModel.PROP_QSHARE_SHAREDBY.toPrefixString(namespaceService);
queryString += " +@" + SearchLanguageConversion.escapeLuceneQuery(qsharedBy) + ":\"${" + qsharedBy + "}\"";
}
}
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(queryString);
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging);
sp.setSkipCount(pagingRequest.getSkipCount());
sp.setMaxItems(pagingRequest.getMaxItems());
sp.addSort("@" + ContentModel.PROP_MODIFIED, false);
ResultSet results = searchService.query(sp);
List<QuickShareLink> qsLinks = new ArrayList<>(results.length());
List<String> includeParam = parameters.getInclude();
for (ResultSetRow row : results) {
NodeRef nodeRef = row.getNodeRef();
qsLinks.add(getQuickShareInfo(nodeRef, false, includeParam));
}
results.close();
return CollectionWithPagingInfo.asPaged(paging, qsLinks, results.hasMore(), Long.valueOf(results.getNumberFound()).intValue());
}
use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class SitesImpl method getSites.
public CollectionWithPagingInfo<Site> getSites(final Parameters parameters) {
final BeanPropertiesFilter filter = parameters.getFilter();
Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging);
// pagingRequest.setRequestTotalCountMax(requestTotalCountMax)
List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>();
List<SortColumn> sortCols = parameters.getSorting();
if ((sortCols != null) && (sortCols.size() > 0)) {
for (SortColumn sortCol : sortCols) {
QName sortPropQName = SORT_PARAMS_TO_QNAMES.get(sortCol.column);
if (sortPropQName == null) {
throw new InvalidArgumentException("Invalid sort field: " + sortCol.column);
}
sortProps.add(new Pair<>(sortPropQName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE)));
}
} else {
// default sort order
sortProps.add(new Pair<>(ContentModel.PROP_TITLE, Boolean.TRUE));
}
List<FilterProp> filterProps = getFilterPropListOfSites(parameters);
final PagingResults<SiteInfo> pagingResult = siteService.listSites(filterProps, sortProps, pagingRequest);
final List<SiteInfo> sites = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
List<Site> page = new AbstractList<Site>() {
@Override
public Site get(int index) {
SiteInfo siteInfo = sites.get(index);
String role = null;
if (filter.isAllowed(Site.ROLE)) {
role = siteService.getMembersRole(siteInfo.getShortName(), personId);
}
return new Site(siteInfo, role);
}
@Override
public int size() {
return sites.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, page, pagingResult.hasMoreItems(), totalItems);
}
use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class Util method wrapPagingResults.
public static <T> PagingResults<T> wrapPagingResults(Paging paging, Collection<T> result) {
if (paging == null) {
throw new InvalidArgumentException("paging object can't be null.");
}
if (result == null) {
result = Collections.emptyList();
}
PagingRequest pagingRequest = getPagingRequest(paging);
final int totalSize = result.size();
final PageDetails pageDetails = PageDetails.getPageDetails(pagingRequest, totalSize);
final List<T> page = new ArrayList<>(pageDetails.getPageSize());
Iterator<T> it = result.iterator();
for (int counter = 0, end = pageDetails.getEnd(); counter < end && it.hasNext(); counter++) {
T element = it.next();
if (counter < pageDetails.getSkipCount()) {
continue;
}
if (counter > end - 1) {
break;
}
page.add(element);
}
return new PagingResults<T>() {
@Override
public List<T> getPage() {
return page;
}
@Override
public boolean hasMoreItems() {
return pageDetails.hasMoreItems();
}
@Override
public Pair<Integer, Integer> getTotalResultCount() {
Integer total = totalSize;
return new Pair<>(total, total);
}
@Override
public String getQueryExecutionId() {
return null;
}
};
}
use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class ForumTopicsHotGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef, TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
// They shouldn't be trying to list of an existing Post or Topic
if (topic != null || post != null) {
String error = "Can't list Topics inside an existing Topic or Post";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
}
// Grab the date range to search over
String numDaysS = req.getParameter("numdays");
int numDays = RECENT_POSTS_PERIOD_DAYS;
if (numDaysS != null) {
numDays = Integer.parseInt(numDaysS);
}
Date now = new Date();
Date since = new Date(now.getTime() - numDays * ONE_DAY_MS);
// Get the topics with recent replies
PagingResults<Pair<TopicInfo, Integer>> topicsAndCounts = null;
PagingRequest paging = buildPagingRequest(req);
if (site != null) {
topicsAndCounts = discussionService.listHotTopics(site.getShortName(), since, paging);
} else {
topicsAndCounts = discussionService.listHotTopics(nodeRef, since, paging);
}
// For this, we actually only need the topics, not their counts too
List<TopicInfo> topics = new ArrayList<TopicInfo>();
for (Pair<TopicInfo, Integer> tc : topicsAndCounts.getPage()) {
topics.add(tc.getFirst());
}
// been created yet, use the site for the permissions checking
if (site != null && nodeRef == null) {
nodeRef = site.getNodeRef();
}
// Build the common model parts
Map<String, Object> model = buildCommonModel(site, topic, post, req);
model.put("forum", nodeRef);
// Have the topics rendered
model.put("data", renderTopics(topics, topicsAndCounts.getTotalResultCount(), paging, site));
// All done
return model;
}
use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class ForumTopicsMineGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef, TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
// They shouldn't be trying to list of an existing Post or Topic
if (topic != null || post != null) {
String error = "Can't list Topics inside an existing Topic or Post";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
}
// Grab the current user to list for
String username = AuthenticationUtil.getFullyAuthenticatedUser();
// Get the topics for the user, oldest first
PagingResults<TopicInfo> topics = null;
PagingRequest paging = buildPagingRequest(req);
if (site != null) {
topics = discussionService.listTopics(site.getShortName(), username, true, paging);
} else {
topics = discussionService.listTopics(nodeRef, username, true, paging);
}
// been created yet, use the site for the permissions checking
if (site != null && nodeRef == null) {
nodeRef = site.getNodeRef();
}
// Build the common model parts
Map<String, Object> model = buildCommonModel(site, topic, post, req);
model.put("forum", nodeRef);
// Have the topics rendered
model.put("data", renderTopics(topics, paging, site));
// All done
return model;
}
Aggregations