use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.
the class AbstractRuleWebScript method parseRequestForNodeRef.
/**
* Parses the request and providing it's valid returns the NodeRef.
*
* @param req The webscript request
* @return The NodeRef passed in the request
*/
protected NodeRef parseRequestForNodeRef(WebScriptRequest req) {
// get the parameters that represent the NodeRef, we know they are present
// otherwise this webscript would not have matched
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String storeType = templateVars.get("store_type");
String storeId = templateVars.get("store_id");
String nodeId = templateVars.get("id");
// create the NodeRef and ensure it is valid
StoreRef storeRef = new StoreRef(storeType, storeId);
NodeRef nodeRef = new NodeRef(storeRef, nodeId);
if (!this.nodeService.exists(nodeRef)) {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef.toString());
}
return nodeRef;
}
use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.
the class AbstractBlogWebScript 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;
BlogPostInfo blog = null;
if (templateVars.containsKey("site")) {
// Site, and Optionally Blog Post
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 blog post name too?
if (templateVars.containsKey("path")) {
String name = templateVars.get("path");
blog = blogService.getBlogPost(siteName, name);
if (blog == null) {
String error = "Could not find blog '" + name + "' for site '" + site.getShortName() + "'";
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
}
nodeRef = blog.getNodeRef();
} else {
// The NodeRef is the container (if it exists)
if (siteService.hasContainer(siteName, BlogServiceImpl.BLOG_COMPONENT)) {
nodeRef = siteService.getContainer(siteName, BlogServiceImpl.BLOG_COMPONENT);
}
}
} else if (templateVars.containsKey("store_type") && templateVars.containsKey("store_id") && templateVars.containsKey("id")) {
// NodeRef, should be a Blog Post
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
blog = blogService.getForNodeRef(nodeRef);
// See if it's actually attached to a site
if (blog != null) {
NodeRef container = blog.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, blog, req, json, status, cache);
}
use of org.alfresco.service.cmr.repository.StoreRef 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>();
}
use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.
the class DownloadStatusGet 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);
}
DownloadStatus downloadStatus = downloadService.getDownloadStatus(nodeRef);
Map<String, Object> result = new HashMap<String, Object>();
result.put("downloadStatus", downloadStatus);
return result;
}
use of org.alfresco.service.cmr.repository.StoreRef in project acs-community-packaging by Alfresco.
the class AdminNodeBrowseBean method getStores.
/**
* Gets the list of repository stores
*
* @return stores
*/
public DataModel getStores() {
if (stores == null) {
List<StoreRef> storeRefs = getNodeService().getStores();
stores = new ListDataModel(storeRefs);
}
return stores;
}
Aggregations