org.springframework.extensions.webscripts.Status Java Examples
The following examples show how to use
org.springframework.extensions.webscripts.Status.
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: PropertiesGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected QName getClassQName(WebScriptRequest req) { QName classQName = null; String prefix = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PREFIX); String shortName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_SHORT_CLASS_NAME); if (prefix != null && prefix.length() != 0 && shortName != null && shortName.length()!= 0) { classQName = createClassQName(prefix, shortName); if (classQName == null) { // Error throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + prefix + ":" + shortName + " - parameter in the URL"); } } return classQName; }
Example #2
Source File: RatingDelete.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); NodeRef nodeRef = parseRequestForNodeRef(req); String ratingSchemeName = parseRequestForScheme(req); Rating deletedRating = ratingService.removeRatingByCurrentUser(nodeRef, ratingSchemeName); if (deletedRating == null) { // There was no rating in the specified scheme to delete. throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Unable to delete non-existent rating: " + ratingSchemeName + " from " + nodeRef.toString()); } model.put(NODE_REF, nodeRef.toString()); model.put(AVERAGE_RATING, ratingService.getAverageRating(nodeRef, ratingSchemeName)); model.put(RATINGS_TOTAL, ratingService.getTotalRating(nodeRef, ratingSchemeName)); model.put(RATINGS_COUNT, ratingService.getRatingsCount(nodeRef, ratingSchemeName)); return model; }
Example #3
Source File: StreamACP.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Converts the given comma delimited string of NodeRefs to an array * of NodeRefs. If the string is null a WebScriptException is thrown. * * @param nodeRefsParam Comma delimited string of NodeRefs * @return Array of NodeRef objects */ protected NodeRef[] getNodeRefs(String nodeRefsParam) { // check the list of NodeRefs is present if (nodeRefsParam == null) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Mandatory 'nodeRefs' parameter was not provided in form data"); } List<NodeRef> listNodeRefs = new ArrayList<NodeRef>(8); StringTokenizer tokenizer = new StringTokenizer(nodeRefsParam, ","); while (tokenizer.hasMoreTokens()) { listNodeRefs.add(new NodeRef(tokenizer.nextToken().trim())); } NodeRef[] nodeRefs = new NodeRef[listNodeRefs.size()]; nodeRefs = listNodeRefs.toArray(nodeRefs); return nodeRefs; }
Example #4
Source File: BulkFilesystemImportStatusWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(WebScriptRequest, Status, Cache) */ @Override protected Map<String, Object> executeImpl(WebScriptRequest request, Status status, Cache cache) { Map<String, Object> result = new HashMap<String, Object>(); cache.setNeverCache(true); LicenseDescriptor licenseDescriptor = descriptorService.getLicenseDescriptor(); boolean isEnterprise = (licenseDescriptor == null ? false : (licenseDescriptor.getLicenseMode() == LicenseMode.ENTERPRISE)); result.put(IS_ENTERPRISE, Boolean.valueOf(isEnterprise)); result.put(RESULT_IMPORT_STATUS, bulkImporter.getStatus()); return(result); }
Example #5
Source File: PropertiesGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected QName getClassQName(WebScriptRequest req) { QName classQName = null; String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); if (className != null && className.length() != 0) { classQName = createClassQName(className); if (classQName == null) { // Error throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL"); } } return classQName; }
Example #6
Source File: SubscriptionServiceRestApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected List<String> getFollowing(String user) throws Exception { String url = getUrl(URL_FOLLOWING, user); Response response = sendRequest(new GetRequest(url), Status.STATUS_OK); JSONObject resultObject = new JSONObject(response.getContentAsString()); assertTrue(resultObject.has("people")); List<String> result = new ArrayList<String>(); JSONArray people = resultObject.getJSONArray("people"); for (int i = 0; i < people.length(); i++) { JSONObject person = people.getJSONObject(i); assertTrue(person.has("userName")); assertTrue(person.has("firstName")); assertTrue(person.has("lastName")); result.add(person.getString("userName")); } return result; }
Example #7
Source File: UserCalendarEntriesGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); // Site is optional SiteInfo site = null; String siteName = templateVars.get("site"); if (siteName != null) { site = siteService.getSite(siteName); // MNT-3053 fix, siteName was provided in request but it doesn't exists or user has no permissions to access it. if (site == null) { status.setCode(HttpServletResponse.SC_NOT_FOUND, "Site '" + siteName + "' does not exist or user has no permissions to access it."); return null; } } return executeImpl(site, null, req, null, status, cache); }
Example #8
Source File: BulkImportStopWebScript.java From alfresco-bulk-import with Apache License 2.0 | 6 votes |
/** * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache) */ @Override protected Map<String, Object> executeImpl(final WebScriptRequest request, final Status status, final Cache cache) { Map<String, Object> result = new HashMap<>(); cache.setNeverCache(true); if (importer.getStatus().inProgress()) { result.put("result", "stop requested"); importer.stop(); status.setCode(Status.STATUS_ACCEPTED, "Stop requested."); status.setRedirect(true); // Make sure the custom 202 status template is used (why this is needed at all is beyond me...) } else { result.put("result", "no imports in progress"); status.setCode(Status.STATUS_BAD_REQUEST, "No bulk imports are in progress."); } return(result); }
Example #9
Source File: LargeContentTestPut.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); try { req.getContent().getInputStream().close(); model.put("result", "success"); } catch (IOException e) { throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Fail to read request content."); } return model; }
Example #10
Source File: SubscriptionServiceRestApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected boolean follows(String user1, String user2) throws Exception { JSONArray jsonUsers = new JSONArray(); jsonUsers.put(user2); String url = getUrl(URL_FOLLOWS, user1); Response response = sendRequest(new PostRequest(url, jsonUsers.toString(), "application/json"), Status.STATUS_OK); JSONArray resultArray = new JSONArray(response.getContentAsString()); assertEquals(1, resultArray.length()); JSONObject resultObject = resultArray.getJSONObject(0); assertTrue(resultObject.has(user2)); return resultObject.getBoolean(user2); }
Example #11
Source File: TaskInstanceGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) { Map<String, String> params = req.getServiceMatch().getTemplateVars(); // getting task id from request parameters String taskId = params.get("task_instance_id"); // searching for task in repository WorkflowTask workflowTask = workflowService.getTaskById(taskId); // task was not found -> return 404 if (workflowTask == null) { throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find workflow task with id: " + taskId); } Map<String, Object> model = new HashMap<String, Object>(); // build the model for ftl model.put("workflowTask", modelBuilder.buildDetailed(workflowTask)); return model; }
Example #12
Source File: LoginTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Negative test - missing parameters */ public void testMissingParameters() throws Exception { /** * Login via get method missing pw */ String loginURL = "/api/login?u=" + USER_ONE; sendRequest(new GetRequest(loginURL), Status.STATUS_BAD_REQUEST); /** * Login via get method missing u */ String login2URL = "/api/login?&pw=" + USER_ONE; sendRequest(new GetRequest(login2URL), Status.STATUS_BAD_REQUEST); }
Example #13
Source File: LoginTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Positive test - login and retrieve a ticket, * - via json method */ public void testAuthenticationGetJSON() throws Exception { /** * Login via get method to return json */ String loginURL = "/api/login.json?u=" + USER_ONE + "&pw=" + USER_ONE ; Response resp = sendRequest(new GetRequest(loginURL), Status.STATUS_OK); JSONObject result = new JSONObject(resp.getContentAsString()); JSONObject data = result.getJSONObject("data"); String ticket = data.getString("ticket"); assertNotNull("ticket is null", ticket); /** * This is now testing the framework ... With a different format. */ String login2URL = "/api/login?u=" + USER_ONE + "&pw=" + USER_ONE + "&format=json"; Response resp2 = sendRequest(new GetRequest(login2URL), Status.STATUS_OK); JSONObject result2 = new JSONObject(resp2.getContentAsString()); JSONObject data2 = result2.getJSONObject("data"); String ticket2 = data2.getString("ticket"); assertNotNull("ticket is null", ticket2); }
Example #14
Source File: InviteServiceTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
private JSONObject getInviteInfo(String inviteId, String inviteTicket, String inviteeUid) throws Exception { String url = "/api/invite/" + inviteId + "/" + inviteTicket + "?inviteeUserName=" + inviteeUid; String runAsUser = AuthenticationUtil.getRunAsUser(); Response response = sendRequest(new GetRequest(url), Status.STATUS_OK); if (!runAsUser.equals(AuthenticationUtil.getRunAsUser())) { AuthenticationUtil.setRunAsUser(runAsUser); } JSONObject result = new JSONObject(response.getContentAsString()); return result; }
Example #15
Source File: DiscussionRestApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
private JSONObject doCreatePost(String url, String title, String content, int expectedStatus) throws Exception { JSONObject post = new JSONObject(); post.put("title", title); post.put("content", content); Response response = sendRequest(new PostRequest(url, post.toString(), "application/json"), expectedStatus); if (expectedStatus != Status.STATUS_OK) { return null; } JSONObject result = new JSONObject(response.getContentAsString()); JSONObject item = result.getJSONObject("item"); posts.add(item.getString("name")); return item; }
Example #16
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 #17
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 #18
Source File: TransferWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { if (enabled) { log.debug("Transfer webscript invoked by user: " + AuthenticationUtil.getFullyAuthenticatedUser() + " running as " + AuthenticationUtil.getRunAsAuthentication().getName()); processCommand(req.getServiceMatch().getTemplateVars().get("command"), req, res); } else { res.setStatus(Status.STATUS_NOT_FOUND); } }
Example #19
Source File: InviteServiceTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public void testCancelInvite() throws Exception { // inviter starts invite workflow JSONObject result = startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_1, Status.STATUS_CREATED); // get hold of invite ID of started invite JSONObject data = result.getJSONObject("data"); String inviteId = data.getString("inviteId"); // Inviter cancels pending invitation cancelInvite(inviteId, SITE_SHORT_NAME_INVITE_1, Status.STATUS_OK); }
Example #20
Source File: ReadGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> executeImpl(final WebScriptRequest req, Status status, Cache cache) { if (! isEnabled()) { throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide"); } // create map of params (template vars) Map<String, String> params = req.getServiceMatch().getTemplateVars(); final String sharedId = params.get("shared_id"); if (sharedId == null) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !"); } try { boolean canRead = quickShareService.canRead(sharedId); Map<String, Object> result = new HashMap<String, Object>(); result.put("canRead", canRead); return result; } catch (InvalidSharedIdException ex) { logger.error("Unable to find: "+sharedId); throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId); } catch (InvalidNodeRefException inre) { logger.error("Unable to find: "+sharedId+" ["+inre.getNodeRef()+"]"); throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId); } }
Example #21
Source File: BlogGet.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! } if (containerNodeRef == null && site != null) { // They want to know about a blog container on a // site where nothing has lazy-created the container // Give them info on the site for now, should be close enough! containerNodeRef = site.getNodeRef(); } if (containerNodeRef == null) { // Looks like they've asked for something that isn't there throw new WebScriptException(Status.STATUS_NOT_FOUND, "Blog Not Found"); } // Build the response // (For now, we just supply the noderef, but when we have a // proper blog details object we'll use that) Map<String, Object> model = new HashMap<String, Object>(); model.put(ITEM, containerNodeRef); return model; }
Example #22
Source File: GroupsTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private JSONArray getDataArray(String url) throws IOException, JSONException, UnsupportedEncodingException { Response response = sendRequest(new GetRequest(url), Status.STATUS_OK); JSONObject top = new JSONObject(response.getContentAsString()); JSONArray data = top.getJSONArray("data"); return data; }
Example #23
Source File: BlogPostDelete.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef, BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache) { final ResourceBundle rb = getResources(); if (blog == null) { throw new WebScriptException(Status.STATUS_NOT_FOUND, "Blog Post Not Found"); } // TODO Get this from the BlogPostInfo Object final boolean isDraftBlogPost = blogService.isDraftBlogPost(blog.getNodeRef()); // Have it deleted blogService.deleteBlogPost(blog); // If we're in a site, and it isn't a draft, add an activity if (site != null && !isDraftBlogPost) { addActivityEntry("deleted", blog, site, req, json, nodeRef); } // Report it as deleted Map<String, Object> model = new HashMap<String, Object>(); String message = rb.getString(MSG_BLOG_DELETED); model.put("message",MessageFormat.format(message, blog.getNodeRef())); return model; }
Example #24
Source File: TestCredentialsCommandProcessor.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public int process(WebScriptRequest req, WebScriptResponse resp) { //Since all the checks that are needed are actually carried out by the transfer web script, this processor //effectively becomes a no-op. int result = Status.STATUS_OK; resp.setStatus(result); return result; }
Example #25
Source File: PersonServiceTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public void testDeletePerson() throws Exception { // Create a new person String userName = RandomStringUtils.randomNumeric(6); createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation", "myJobTitle", "[email protected]", "myBio", "images/avatar.jpg", 0, Status.STATUS_OK); // Delete the person deletePerson(userName, Status.STATUS_OK); // Make sure that the person has been deleted and no longer exists deletePerson(userName, Status.STATUS_NOT_FOUND); }
Example #26
Source File: CustomModelUploadPost.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
protected File createTempFile(InputStream inputStream) { try { File tempFile = TempFileProvider.createTempFile(inputStream, TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX); return tempFile; } catch (Exception ex) { throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "cmm.rest_api.model.import_process_zip_file_failure", ex); } }
Example #27
Source File: ReplicationDefinitionDelete.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> buildModel(ReplicationModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) { // Which definition did they ask for? String replicationDefinitionName = req.getServiceMatch().getTemplateVars().get("replication_definition_name"); ReplicationDefinition replicationDefinition = replicationService.loadReplicationDefinition(replicationDefinitionName); // Does it exist? if(replicationDefinition == null) { throw new WebScriptException( Status.STATUS_NOT_FOUND, "No Replication Definition found with that name" ); } // Delete it replicationService.deleteReplicationDefinition(replicationDefinition); // Report that we have deleted it status.setCode(Status.STATUS_NO_CONTENT); status.setMessage("Replication Definition deleted"); status.setRedirect(true); return null; }
Example #28
Source File: AuditControlPost.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(7); String appName = getParamAppName(req); String path = getParamPath(req); boolean enable = getParamEnableDisable(req); if (appName == null) { // Global operation auditService.setAuditEnabled(enable); } else { // Apply to a specific application if (enable) { auditService.enableAudit(appName, path); } else { auditService.disableAudit(appName, path); } } model.put(JSON_KEY_ENABLED, enable); // Done if (logger.isDebugEnabled()) { logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model); } return model; }
Example #29
Source File: AbstractReplicationWebscript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { ReplicationModelBuilder modelBuilder = new ReplicationModelBuilder( nodeService, replicationService, actionTrackingService ); return buildModel(modelBuilder, req, status, cache); }
Example #30
Source File: AbstractSolrFacetConfigAdminWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> executeImpl(final WebScriptRequest req, final Status status, final Cache cache) { validateCurrentUser(); return unprotectedExecuteImpl(req, status, cache); }