use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.
the class ForumTopicsGet 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);
}
// Do we need to list or search?
boolean tagSearch = false;
String tag = req.getParameter("tag");
if (tag != null && tag.length() > 0) {
tagSearch = true;
// Tags can be full unicode strings, so decode
tag = URLDecoder.decode(tag);
}
// Get the topics
boolean oldestTopicsFirst = false;
PagingResults<TopicInfo> topics = null;
PagingRequest paging = buildPagingRequest(req);
if (tagSearch) {
// Tag based is a search rather than a listing
if (site != null) {
topics = discussionService.findTopics(site.getShortName(), null, tag, oldestTopicsFirst, paging);
} else {
topics = discussionService.findTopics(nodeRef, null, tag, oldestTopicsFirst, paging);
}
} else {
if (site != null) {
topics = discussionService.listTopics(site.getShortName(), oldestTopicsFirst, paging);
} else {
topics = discussionService.listTopics(nodeRef, oldestTopicsFirst, buildPagingRequest(req));
}
}
// 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.springframework.extensions.webscripts.WebScriptException 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.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.
the class AbstractDocLink method parseNodeRefFromTemplateArgs.
protected NodeRef parseNodeRefFromTemplateArgs(Map<String, String> templateVars) {
if (templateVars == null) {
return null;
}
String storeTypeArg = templateVars.get(PARAM_STORE_TYPE);
String storeIdArg = templateVars.get(PARAM_STORE_ID);
String idArg = templateVars.get(PARAM_ID);
if (storeTypeArg != null) {
ParameterCheck.mandatoryString("storeTypeArg", storeTypeArg);
ParameterCheck.mandatoryString("storeIdArg", storeIdArg);
ParameterCheck.mandatoryString("idArg", idArg);
/*
* NodeRef based request
* <url>URL_BASE/{store_type}/{store_id}/{id}</url>
*/
return new NodeRef(storeTypeArg, storeIdArg, idArg);
} else {
String siteArg = templateVars.get(PARAM_SITE);
String containerArg = templateVars.get(PARAM_CONTAINER);
String pathArg = templateVars.get(PARAM_PATH);
if (siteArg != null) {
ParameterCheck.mandatoryString("siteArg", siteArg);
ParameterCheck.mandatoryString("containerArg", containerArg);
/*
* Site based request <url>URL_BASE/{site}/{container}</url> or
* <url>URL_BASE/{site}/{container}/{path}</url>
*/
SiteInfo site = siteService.getSite(siteArg);
PropertyCheck.mandatory(this, "site", site);
NodeRef node = siteService.getContainer(site.getShortName(), containerArg);
if (node == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid 'container' variable");
}
if (pathArg != null) {
// <url>URL_BASE/{site}/{container}/{path}</url>
StringTokenizer st = new StringTokenizer(pathArg, "/");
while (st.hasMoreTokens()) {
String childName = st.nextToken();
node = nodeService.getChildByName(node, ContentModel.ASSOC_CONTAINS, childName);
if (node == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid 'path' variable");
}
}
}
return node;
}
}
return null;
}
use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.
the class DocLinksDelete method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
NodeRef destinationNodeRef = null;
/* Parse the template vars */
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
destinationNodeRef = parseNodeRefFromTemplateArgs(templateVars);
/* Delete links */
DeleteLinksStatusReport report;
try {
report = documentLinkService.deleteLinksToDocument(destinationNodeRef);
} catch (IllegalArgumentException ex) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid Arguments: " + ex.getMessage());
} catch (AccessDeniedException e) {
throw new WebScriptException(Status.STATUS_FORBIDDEN, "You don't have permission to perform this operation");
}
/* Build response */
Map<String, Object> model = new HashMap<String, Object>();
model.put("total_count", report.getTotalLinksFoundCount());
model.put("deleted_count", report.getDeletedLinksCount());
Map<String, String> errorDetails = new HashMap<String, String>();
Iterator<Entry<NodeRef, Throwable>> it = report.getErrorDetails().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<NodeRef, Throwable> pair = it.next();
Throwable th = pair.getValue();
errorDetails.put(pair.getKey().toString(), th.getMessage());
}
model.put("error_details", errorDetails);
return model;
}
use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.
the class DownloadDelete 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);
}
if (!(templateVars.containsKey("store_type") && templateVars.containsKey("store_id") && templateVars.containsKey("node_id"))) {
String error = "Missing template variables (store_type, store_id or node_id).";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
}
StoreRef store = new StoreRef(templateVars.get("store_type"), templateVars.get("store_id"));
NodeRef nodeRef = new NodeRef(store, templateVars.get("node_id"));
if (!nodeService.exists(nodeRef)) {
String error = "Could not find node: " + nodeRef;
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
}
downloadService.cancelDownload(nodeRef);
status.setCode(HttpServletResponse.SC_OK);
return new HashMap<String, Object>();
}
Aggregations