use of org.alfresco.repo.discussion.TopicInfoImpl in project alfresco-remote-api by Alfresco.
the class ForumTopicsFilteredGet method wrap.
/**
* Wrap up search results as {@link TopicInfo} instances
*
* @param finalResults ResultSet
* @param paging PagingRequest
*/
protected PagingResults<TopicInfo> wrap(final ResultSet finalResults, PagingRequest paging) {
int maxItems = paging.getMaxItems();
Comparator<TopicInfo> lastPostDesc = new Comparator<TopicInfo>() {
@Override
public int compare(TopicInfo t1, TopicInfo t2) {
Date t1LastPostDate = t1.getCreatedAt();
if (discussionService.getMostRecentPost(t1) != null) {
t1LastPostDate = discussionService.getMostRecentPost(t1).getCreatedAt();
}
Date t2LastPostDate = t2.getCreatedAt();
if (discussionService.getMostRecentPost(t2) != null) {
t2LastPostDate = discussionService.getMostRecentPost(t2).getCreatedAt();
}
return t2LastPostDate.compareTo(t1LastPostDate);
}
};
final Set<TopicInfo> topics = new TreeSet<TopicInfo>(lastPostDesc);
for (ResultSetRow row : finalResults) {
Pair<TopicInfo, PostInfo> pair = discussionService.getForNodeRef(row.getNodeRef());
TopicInfo topic = pair.getFirst();
if (topic != null) {
String path = nodeService.getPath(topic.getNodeRef()).toDisplayPath(nodeService, permissionService);
String site = path.split("/")[3];
TopicInfoImpl tii = (TopicInfoImpl) topic;
tii.setShortSiteName(site);
topics.add(tii);
if (topics.size() >= maxItems) {
break;
}
}
}
// Wrap
return new PagingResults<TopicInfo>() {
@Override
public boolean hasMoreItems() {
try {
return finalResults.hasMore();
} catch (UnsupportedOperationException e) {
// Not all search results support paging
return false;
}
}
@Override
public Pair<Integer, Integer> getTotalResultCount() {
int skipCount = 0;
int itemsRemainingAfterThisPage = 0;
try {
skipCount = finalResults.getStart();
} catch (UnsupportedOperationException e) {
}
try {
itemsRemainingAfterThisPage = finalResults.length();
} catch (UnsupportedOperationException e) {
}
final int totalItemsInUnpagedResultSet = skipCount + itemsRemainingAfterThisPage;
return new Pair<Integer, Integer>(totalItemsInUnpagedResultSet, totalItemsInUnpagedResultSet);
}
@Override
public List<TopicInfo> getPage() {
return new ArrayList<TopicInfo>(topics);
}
@Override
public String getQueryExecutionId() {
return null;
}
};
}
Aggregations