Java Code Examples for org.springframework.extensions.webscripts.Status#STATUS_BAD_REQUEST
The following examples show how to use
org.springframework.extensions.webscripts.Status#STATUS_BAD_REQUEST .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ForumPostGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef, TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json, Status status, Cache cache) { // Build the common model parts Map<String, Object> model = buildCommonModel(site, topic, post, req); // Did they want just one post, or the whole of the topic? if (post != null) { model.put(KEY_POSTDATA, renderPost(post, site)); } else if (topic != null) { model.put(KEY_POSTDATA, renderTopic(topic, site)); } else { String error = "Node was of the wrong type, only Topic and Post are supported"; throw new WebScriptException(Status.STATUS_BAD_REQUEST, error); } // All done return model; }
Example 2
Source File: SolrFacetConfigAdminDelete.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) { // get the filterID parameter. Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); String filterID = templateVars.get("filterID"); if (filterID == null) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Filter id not provided"); } facetService.deleteFacet(filterID); Map<String, Object> model = new HashMap<String, Object>(1); model.put("success", true); if (logger.isDebugEnabled()) { logger.debug("Facet [" + filterID + "] has been deleted successfully"); } return model; }
Example 3
Source File: AbstractAuditWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
private Long getLongParam(String paramStr, Long defaultVal) { if (paramStr == null) { // note: defaultVal can be null return defaultVal; } try { return Long.parseLong(paramStr); } catch (NumberFormatException e) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, e.getMessage()); } }
Example 4
Source File: StreamACP.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Attempts to retrieve and convert a JSON array of * NodeRefs from the given JSON object. If the nodeRefs * property is not present a WebScriptException is thrown. * * @param json JSONObject * @return Array of NodeRef objects */ protected NodeRef[] getNodeRefs(JSONObject json) throws JSONException { // check the list of NodeRefs is present if (!json.has(PARAM_NODE_REFS)) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Mandatory 'nodeRefs' parameter was not provided in request body"); } NodeRef[] nodeRefs = new NodeRef[0]; JSONArray jsonArray = json.getJSONArray(PARAM_NODE_REFS); if (jsonArray.length() != 0) { // build the list of NodeRefs nodeRefs = new NodeRef[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { NodeRef nodeRef = new NodeRef(jsonArray.getString(i)); nodeRefs[i] = nodeRef; } } return nodeRefs; }
Example 5
Source File: DocLinkPost.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Create link for sourceNodeRef in destinationNodeRef location * * @param destinationNodeRef * @param sourceNodeRef * @return */ private NodeRef createLink(NodeRef destinationNodeRef, NodeRef sourceNodeRef) { NodeRef linkNodeRef = null; try { linkNodeRef = documentLinkService.createDocumentLink(sourceNodeRef, 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"); } return linkNodeRef; }
Example 6
Source File: ActionsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private Map<String, Serializable> extractActionParams(org.alfresco.service.cmr.action.ActionDefinition actionDefinition, Map<String, String> params) { Map<String, Serializable> parameterValues = new HashMap<>(); try { for (Map.Entry<String, String> entry : params.entrySet()) { String propertyName = entry.getKey(); Object propertyValue = entry.getValue(); // Get the parameter definition we care about ParameterDefinition paramDef = actionDefinition.getParameterDefintion(propertyName); if (paramDef == null && !actionDefinition.getAdhocPropertiesAllowed()) { throw new AlfrescoRuntimeException("Invalid parameter " + propertyName + " for action/condition " + actionDefinition.getName()); } if (paramDef != null) { QName typeQName = paramDef.getType(); // Convert the property value Serializable value = convertValue(typeQName, propertyValue); parameterValues.put(propertyName, value); } else { // If there is no parameter definition we can only rely on the .toString() // representation of the ad-hoc property parameterValues.put(propertyName, propertyValue.toString()); } } } catch (JSONException je) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je); } return parameterValues; }
Example 7
Source File: InvitationDelete.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private void validateParameters(String siteShortName, String invitationId) { if ((invitationId == null) || (invitationId.length() == 0)) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid invitation id provided"); } SiteInfo site = siteService.getSite(siteShortName); if (site == null) { throw new WebScriptException(Status.STATUS_NOT_FOUND, "Invalid site id provided"); } }
Example 8
Source File: AbstractLinksWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Builds up a listing Paging request, based on the arguments * specified in the URL */ protected PagingRequest buildPagingRequest(WebScriptRequest req) { if (req.getParameter("page") == null || req.getParameter("pageSize") == null) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters missing"); } return new ScriptPagingDetails(req, 100); }
Example 9
Source File: CustomModelUploadPost.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
protected String getExtensionModule(InputStream inputStream, String fileName) { Element rootElement = null; try { final DocumentBuilder db = XMLUtil.getDocumentBuilder(); rootElement = db.parse(inputStream).getDocumentElement(); } catch (IOException io) { throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "cmm.rest_api.model.import_process_ext_module_file_failure", io); } catch (SAXException ex) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "cmm.rest_api.model.import_invalid_ext_module_entry", new Object[] { fileName }, ex); } if (rootElement != null && SHARE_EXT_MODULE_ROOT_ELEMENT.equals(rootElement.getNodeName())) { StringWriter sw = new StringWriter(); XMLUtil.print(rootElement, sw, false); return sw.toString(); } return null; }
Example 10
Source File: AbstractAuditWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private int getIntParam(String paramStr, int defaultVal) { if (paramStr == null) { return defaultVal; } try { return Integer.parseInt(paramStr); } catch (NumberFormatException e) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, e.getMessage()); } }
Example 11
Source File: DeclarativeSpreadsheetWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status) */ @Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { Map<String, Object> model = new HashMap<String, Object>(); model.put("success", Boolean.TRUE); // What format are they after? String format = req.getFormat(); if("csv".equals(format) || "xls".equals(format) || "xlsx".equals(format) || "excel".equals(format)) { // Identify the thing to process Object resource = identifyResource(format, req); // Generate the spreadsheet try { generateSpreadsheet(resource, format, req, status, model); return model; } catch(IOException e) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Unable to generate template file", e); } } // If we get here, then it isn't a spreadsheet version if(allowHtmlFallback()) { // There's some sort of help / upload form return model; } else { throw new WebScriptException("Web Script format '" + format + "' is not supported"); } }
Example 12
Source File: BlogPut.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> executeImpl(SiteInfo site, NodeRef containerNodeRef, BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache) { if (blog != null) { // They appear to have supplied a blog post itself... // Oh well, let's hope for the best! throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Blog post should not be updated via this web script."); } if (site != null && containerNodeRef == null) { // Force the lazy creation // This is a bit icky, but it'll have to do for now... containerNodeRef = siteService.createContainer( site.getShortName(), BlogServiceImpl.BLOG_COMPONENT, null, null); } // Do the work updateBlog(containerNodeRef, json); // Record it as done Map<String, Object> model = new HashMap<String, Object>(); model.put("item", containerNodeRef); return model; }
Example 13
Source File: AbstractDocLink.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
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; }
Example 14
Source File: DocLinksDelete.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@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; }
Example 15
Source File: StreamACP.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see org.springframework.extensions.webscripts.WebScript#execute(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.WebScriptResponse) */ public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { File tempACPFile = null; try { NodeRef[] nodeRefs = null; String contentType = req.getContentType(); if (MULTIPART_FORMDATA.equals(contentType)) { // get nodeRefs parameter from form nodeRefs = getNodeRefs(req.getParameter(PARAM_NODE_REFS)); } else { // presume the request is a JSON request so get nodeRefs from JSON body nodeRefs = getNodeRefs(new JSONObject(new JSONTokener(req.getContent().getContent()))); } // setup the ACP parameters ExporterCrawlerParameters params = new ExporterCrawlerParameters(); params.setCrawlSelf(true); params.setCrawlChildNodes(true); params.setExportFrom(new Location(nodeRefs)); // create an ACP of the nodes tempACPFile = createACP(params, ACPExportPackageHandler.ACP_EXTENSION, false); // stream the ACP back to the client as an attachment (forcing save as) streamContent(req, res, tempACPFile, true, tempACPFile.getName(), null); } catch (IOException ioe) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", ioe); } catch (JSONException je) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je); } finally { // try and delete the temporary file if (tempACPFile != null) { if (logger.isDebugEnabled()) logger.debug("Deleting temporary archive: " + tempACPFile.getAbsolutePath()); tempACPFile.delete(); } } }
Example 16
Source File: ForumTopicsMineGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@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); } // If they did a site based search, and the component hasn't // 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; }
Example 17
Source File: ForumTopicPost.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@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 adding to an existing Post or Topic if (topic != null || post != null) { String error = "Can't create a new Topic inside an existing Topic or Post"; throw new WebScriptException(Status.STATUS_BAD_REQUEST, error); } // Grab the details of the new Topic and Post String title = ""; String contents = ""; if (json.containsKey("title")) { title = (String)json.get("title"); } if (json.containsKey("content")) { contents = (String)json.get("content"); } List<String> tags = getTags(json); // Have the topic created if (site != null) { topic = discussionService.createTopic(site.getShortName(), title); } else { topic = discussionService.createTopic(nodeRef, title); } if (tags != null && tags.size() > 0) { topic.getTags().clear(); topic.getTags().addAll(tags); discussionService.updateTopic(topic); } // Have the primary post created post = discussionService.createPost(topic, contents); // Record the activity addActivityEntry("post", "created", topic, post, site, req, json); // Build the common model parts Map<String, Object> model = buildCommonModel(site, topic, post, req); // Build the JSON for the whole topic model.put(KEY_POSTDATA, renderTopic(topic, site)); // All done return model; }
Example 18
Source File: AclsGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private Map<String, Object> buildModel(WebScriptRequest req) throws JSONException, IOException { List<Long> aclChangeSetIds = null; Content content = req.getContent(); if (content == null) { throw new WebScriptException("Request content is empty"); } JSONObject o = new JSONObject(content.getContent()); JSONArray aclChangeSetIdsJSON = o.has("aclChangeSetIds") ? o.getJSONArray("aclChangeSetIds") : null; if (aclChangeSetIdsJSON == null) { throw new WebScriptException( Status.STATUS_BAD_REQUEST, "Parameter 'aclChangeSetIds' not provided in request content."); } else if (aclChangeSetIdsJSON.length() == 0) { throw new WebScriptException( Status.STATUS_BAD_REQUEST, "Parameter 'aclChangeSetIds' must hold from 1 or more IDs."); } aclChangeSetIds = new ArrayList<Long>(aclChangeSetIdsJSON.length()); for (int i = 0; i < aclChangeSetIdsJSON.length(); i++) { aclChangeSetIds.add(aclChangeSetIdsJSON.getLong(i)); } String fromIdParam = req.getParameter("fromId"); String maxResultsParam = req.getParameter("maxResults"); Long fromId = (fromIdParam == null ? null : Long.valueOf(fromIdParam)); int maxResults = (maxResultsParam == null ? 1024 : Integer.valueOf(maxResultsParam)); // Request according to the paging query style required List<Acl> acls = solrTrackingComponent.getAcls(aclChangeSetIds, fromId, maxResults); Map<String, Object> model = new HashMap<String, Object>(1, 1.0f); model.put("acls", acls); if (logger.isDebugEnabled()) { logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model); } return model; }
Example 19
Source File: ArchivedNodePut.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); // Current user String userID = AuthenticationUtil.getFullyAuthenticatedUser(); if (userID == null) { throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Web Script [" + req.getServiceMatch().getWebScript().getDescription() + "] requires user authentication."); } NodeRef nodeRefToBeRestored = parseRequestForNodeRef(req); if (nodeRefToBeRestored == null) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "nodeRef not recognised. Could not restore."); } // check if the current user has the permission to restore the node validatePermission(nodeRefToBeRestored, userID); RestoreNodeReport report = nodeArchiveService.restoreArchivedNode(nodeRefToBeRestored); // Handling of some error scenarios if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_INVALID_ARCHIVE_NODE)) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find archive node: " + nodeRefToBeRestored); } else if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_PERMISSION)) { throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Unable to restore archive node: " + nodeRefToBeRestored); } else if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_DUPLICATE_CHILD_NODE_NAME)) { throw new WebScriptException(HttpServletResponse.SC_CONFLICT, "Unable to restore archive node: " + nodeRefToBeRestored +". Duplicate child node name"); } else if (report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_INVALID_PARENT) || report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_INTEGRITY) || report.getStatus().equals(RestoreNodeReport.RestoreStatus.FAILURE_OTHER)) { throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to restore archive node: " + nodeRefToBeRestored); } model.put("restoreNodeReport", report); return model; }
Example 20
Source File: AbstractRuleWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 2 votes |
protected Rule parseJsonRule(JSONObject jsonRule) throws JSONException { Rule result = new Rule(); if (jsonRule.has("title") == false || jsonRule.getString("title").length() == 0) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Title missing when creating rule"); } result.setTitle(jsonRule.getString("title")); result.setDescription(jsonRule.has("description") ? jsonRule.getString("description") : ""); if (jsonRule.has("ruleType") == false || jsonRule.getJSONArray("ruleType").length() == 0) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Rule type missing when creating rule"); } JSONArray types = jsonRule.getJSONArray("ruleType"); List<String> ruleTypes = new ArrayList<String>(); for (int i = 0; i < types.length(); i++) { ruleTypes.add(types.getString(i)); } result.setRuleTypes(ruleTypes); result.applyToChildren(jsonRule.has("applyToChildren") ? jsonRule.getBoolean("applyToChildren") : false); result.setExecuteAsynchronously(jsonRule.has("executeAsynchronously") ? jsonRule.getBoolean("executeAsynchronously") : false); result.setRuleDisabled(jsonRule.has("disabled") ? jsonRule.getBoolean("disabled") : false); JSONObject jsonAction = jsonRule.getJSONObject("action"); // parse action object Action ruleAction = parseJsonAction(jsonAction); result.setAction(ruleAction); return result; }