From a76addbf764d0662e1a7534e455971f22c19eb67 Mon Sep 17 00:00:00 2001 From: Shiv Kandikuppa Date: Fri, 30 Jun 2017 11:18:02 +0530 Subject: [PATCH] Updated delete resource API request type from POST to DELETE (#668) Signed-off-by: shiv12095 --- .../http/request/DeleteResourceRequest.java | 34 ------------------- .../web/controller/ProjectController.java | 15 ++++---- .../data/project/ProjectDataService.js | 5 +-- 3 files changed, 11 insertions(+), 43 deletions(-) delete mode 100644 server/devtool/webeditor/src/main/java/org/eclipse/vorto/server/devtool/http/request/DeleteResourceRequest.java diff --git a/server/devtool/webeditor/src/main/java/org/eclipse/vorto/server/devtool/http/request/DeleteResourceRequest.java b/server/devtool/webeditor/src/main/java/org/eclipse/vorto/server/devtool/http/request/DeleteResourceRequest.java deleted file mode 100644 index 36edc82ff7..0000000000 --- a/server/devtool/webeditor/src/main/java/org/eclipse/vorto/server/devtool/http/request/DeleteResourceRequest.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Bosch Software Innovations GmbH and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * The Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Bosch Software Innovations GmbH - Please refer to git log - *******************************************************************************/ -package org.eclipse.vorto.server.devtool.http.request; - -public class DeleteResourceRequest { - - private String projectName; - private String resourceId; - - public String getProjectName() { - return projectName; - } - public void setProjectName(String projectName) { - this.projectName = projectName; - } - public String getResourceId() { - return resourceId; - } - public void setResourceId(String resourceId) { - this.resourceId = resourceId; - } -} diff --git a/server/devtool/webeditor/src/main/java/org/eclipse/vorto/server/devtool/web/controller/ProjectController.java b/server/devtool/webeditor/src/main/java/org/eclipse/vorto/server/devtool/web/controller/ProjectController.java index d0806154ed..118b09dd29 100644 --- a/server/devtool/webeditor/src/main/java/org/eclipse/vorto/server/devtool/web/controller/ProjectController.java +++ b/server/devtool/webeditor/src/main/java/org/eclipse/vorto/server/devtool/web/controller/ProjectController.java @@ -28,7 +28,6 @@ import org.eclipse.vorto.devtool.projectrepository.file.ProjectRepositoryFileConstants; import org.eclipse.vorto.devtool.projectrepository.model.ProjectResource; import org.eclipse.vorto.devtool.projectrepository.model.Resource; -import org.eclipse.vorto.server.devtool.http.request.DeleteResourceRequest; import org.eclipse.vorto.server.devtool.http.response.Response; import org.eclipse.vorto.server.devtool.models.ModelResource; import org.eclipse.vorto.server.devtool.service.IEditorSession; @@ -177,18 +176,20 @@ public Resource openProject( } @ApiOperation(value = "Deletes a resource from the project") - @RequestMapping(value = "/{projectName}/delete", method = RequestMethod.POST) - public void deleteResource(@RequestBody DeleteResourceRequest deleteResourceRequest, + @RequestMapping(value = "/{projectName}/{resourceId:.+}", method = RequestMethod.DELETE) + public void deleteResource( @ApiParam(value = "ProjectName", required = true) @PathVariable String projectName, + @ApiParam(value = "resourceId", required = true) @PathVariable String resourceId, @ApiParam(value = "Request", required = true) final HttpServletRequest request) { Objects.requireNonNull(projectName, "projectName must not be null"); - + Objects.requireNonNull(resourceId, "resourceId must not be null"); + projectName = webUtils.getUserProjectName(projectName); ResourceSet resourceSet = webUtils.getResourceSet(request); - devtoolReferenceLinker.removeResourceFromResourceSet(deleteResourceRequest.getResourceId(), resourceSet); - projectService.deleteResource(projectName, deleteResourceRequest.getResourceId()); - webUtils.removeDeletedModelFromSessionAttributes(request, deleteResourceRequest.getResourceId()); + devtoolReferenceLinker.removeResourceFromResourceSet(resourceId, resourceSet); + projectService.deleteResource(projectName, resourceId); + webUtils.removeDeletedModelFromSessionAttributes(request, resourceId); } @ApiOperation(value = "Deletes a resource from the project") diff --git a/server/devtool/webeditor/src/main/resources/static/dist/js/services/data/project/ProjectDataService.js b/server/devtool/webeditor/src/main/resources/static/dist/js/services/data/project/ProjectDataService.js index 129e604826..08f1e520cf 100644 --- a/server/devtool/webeditor/src/main/resources/static/dist/js/services/data/project/ProjectDataService.js +++ b/server/devtool/webeditor/src/main/resources/static/dist/js/services/data/project/ProjectDataService.js @@ -56,8 +56,9 @@ define(["../../init/AppService"], function(services) { function deleteProjectResource(params) { var projectName = params.projectName; - var url = "./rest/project/" + projectName + "/delete"; - return $http.post(url, params).then(httpCallSuccess).catch(httpCallFailure); + var resourceId = params.resourceId; + var url = "./rest/project/" + projectName + "/" + resourceId; + return $http.delete(url).then(httpCallSuccess).catch(httpCallFailure); } function httpCallSuccess(response) {