use of org.alfresco.service.cmr.discussion.TopicInfo in project alfresco-remote-api by Alfresco.
the class ForumTopicsRecentGet 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_SEARCH_PERIOD_DAYS;
if (numDaysS != null) {
numDays = Integer.parseInt(numDaysS);
}
Date now = new Date();
Date from = new Date(now.getTime() - numDays * ONE_DAY_MS);
Date to = new Date(now.getTime() + ONE_DAY_MS);
// Get the recent topics, newest first
PagingResults<TopicInfo> topics = null;
PagingRequest paging = buildPagingRequest(req);
if (site != null) {
topics = discussionService.listTopics(site.getShortName(), from, to, false, paging);
} else {
topics = discussionService.listTopics(nodeRef, from, to, false, 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;
}
use of org.alfresco.service.cmr.discussion.TopicInfo in project alfresco-remote-api by Alfresco.
the class AbstractDiscussionWebScript method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
if (templateVars == null) {
String error = "No parameters supplied";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
}
// Parse the JSON, if supplied
JSONObject json = null;
String contentType = req.getContentType();
if (contentType != null && contentType.indexOf(';') != -1) {
contentType = contentType.substring(0, contentType.indexOf(';'));
}
if (MimetypeMap.MIMETYPE_JSON.equals(contentType)) {
JSONParser parser = new JSONParser();
try {
json = (JSONObject) parser.parse(req.getContent().getContent());
} catch (IOException io) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + io.getMessage());
} catch (ParseException pe) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + pe.getMessage());
}
}
// Did they request it by node reference or site?
NodeRef nodeRef = null;
SiteInfo site = null;
TopicInfo topic = null;
PostInfo post = null;
if (templateVars.containsKey("site")) {
// Site, and optionally topic
String siteName = templateVars.get("site");
site = siteService.getSite(siteName);
if (site == null) {
String error = "Could not find site: " + siteName;
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
}
// Did they give a topic name too?
if (templateVars.containsKey("path")) {
String name = templateVars.get("path");
topic = discussionService.getTopic(site.getShortName(), name);
if (topic == null) {
String error = "Could not find topic '" + name + "' for site '" + site.getShortName() + "'";
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
}
nodeRef = topic.getNodeRef();
} else {
// The NodeRef is the container (if it exists)
if (siteService.hasContainer(siteName, DiscussionServiceImpl.DISCUSSION_COMPONENT)) {
nodeRef = siteService.getContainer(siteName, DiscussionServiceImpl.DISCUSSION_COMPONENT);
}
}
} else if (templateVars.containsKey("store_type") && templateVars.containsKey("store_id") && templateVars.containsKey("id")) {
// NodeRef, normally Topic or Discussion
StoreRef store = new StoreRef(templateVars.get("store_type"), templateVars.get("store_id"));
nodeRef = new NodeRef(store, templateVars.get("id"));
if (!nodeService.exists(nodeRef)) {
String error = "Could not find node: " + nodeRef;
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
}
// Try to build the appropriate object for it
Pair<TopicInfo, PostInfo> objects = discussionService.getForNodeRef(nodeRef);
if (objects != null) {
topic = objects.getFirst();
post = objects.getSecond();
}
// See if it's actually attached to a site
if (topic != null) {
NodeRef container = topic.getContainerNodeRef();
if (container != null) {
NodeRef maybeSite = nodeService.getPrimaryParent(container).getParentRef();
if (maybeSite != null) {
// Try to make it a site, will return Null if it isn't one
site = siteService.getSite(maybeSite);
}
}
}
} else {
String error = "Unsupported template parameters found";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
}
// Have the real work done
return executeImpl(site, nodeRef, topic, post, req, json, status, cache);
}
use of org.alfresco.service.cmr.discussion.TopicInfo 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.service.cmr.discussion.TopicInfo 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