From a0da7f6b3e04ee6f06f4580f8a14e60f3438d5e7 Mon Sep 17 00:00:00 2001 From: niamhcore Date: Fri, 11 Dec 2020 12:37:35 +0000 Subject: Remove depredcated code/classes Issue-ID: CPS-93 Signed-off-by: niamhcore Change-Id: I49db5244400d5eb4206d59e73aaf801b7f90c61c --- cps-rest/docs/api/swagger/openapi.yml | 43 --------- .../cps/rest/controller/CpsRestController.java | 104 --------------------- .../exceptions/CpsRestExceptionHandlerSpec.groovy | 10 +- 3 files changed, 5 insertions(+), 152 deletions(-) (limited to 'cps-rest') diff --git a/cps-rest/docs/api/swagger/openapi.yml b/cps-rest/docs/api/swagger/openapi.yml index 441d5e52cd..2eed7e633d 100755 --- a/cps-rest/docs/api/swagger/openapi.yml +++ b/cps-rest/docs/api/swagger/openapi.yml @@ -252,49 +252,6 @@ paths: 404: description: Not Found content: {} - post: - tags: - - cps-rest - summary: Create modules for the given dataspace - operationId: createModules - parameters: - - name: dataspace-name - in: path - description: dataspace-name - required: true - schema: - type: string - requestBody: - content: - multipart/form-data: - schema: - required: - - file - properties: - multipartFile: - type: string - description: multipartFile - format: binary - required: true - responses: - 200: - description: OK - content: - application/json: - schema: - type: object - 201: - description: Created - content: {} - 401: - description: Unauthorized - content: {} - 403: - description: Forbidden - content: {} - 404: - description: Not Found - content: {} /v1/dataspaces/{dataspace-name}/nodes: get: tags: diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java index 32ea35c5e0..1802ce7a79 100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestController.java @@ -20,43 +20,21 @@ package org.onap.cps.rest.controller; -import com.google.gson.Gson; -import com.google.gson.JsonSyntaxException; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; import java.util.Collection; import javax.validation.Valid; import org.modelmapper.ModelMapper; -import org.onap.cps.api.CpService; import org.onap.cps.api.CpsAdminService; -import org.onap.cps.api.CpsModuleService; import org.onap.cps.rest.api.CpsRestApi; -import org.onap.cps.spi.exceptions.CpsException; -import org.onap.cps.spi.exceptions.DataValidationException; import org.onap.cps.spi.model.Anchor; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RestController public class CpsRestController implements CpsRestApi { - @Autowired - private CpService cpService; - - @Autowired - private CpsModuleService cpsModuleService; - @Autowired private CpsAdminService cpsAdminService; @@ -79,14 +57,6 @@ public class CpsRestController implements CpsRestApi { return new ResponseEntity<>(anchorName, HttpStatus.CREATED); } - @Override - public ResponseEntity createModules(@Valid final MultipartFile multipartFile, final String dataspaceName) { - final File fileToParse = saveToFile(multipartFile); - final SchemaContext schemaContext = cpsModuleService.parseAndValidateModel(fileToParse); - cpsModuleService.storeSchemaContext(schemaContext, dataspaceName); - return new ResponseEntity<>("Resource successfully created", HttpStatus.CREATED); - } - @Override public ResponseEntity createNode(@Valid final MultipartFile multipartFile, final String dataspaceName) { return null; @@ -129,78 +99,4 @@ public class CpsRestController implements CpsRestApi { public ResponseEntity getNodeByDataspaceAndAnchor(final String dataspaceName, final String anchorName) { return null; } - - /* - Old rest endpoints before contract first approach (Need to be removed). - */ - - /** - * Upload a JSON file. - * - * @param uploadedFile the JSON Multipart file. - * @return a ResponseEntity. - */ - @PostMapping("/upload-yang-json-data-file") - public final ResponseEntity uploadYangJsonDataFile(@RequestParam("file") final MultipartFile uploadedFile) { - validateJsonStructure(uploadedFile); - final int persistenceObjectId = cpService.storeJsonStructure(getJsonString(uploadedFile)); - return new ResponseEntity<>( - "Object stored in CPS with identity: " + persistenceObjectId, HttpStatus.OK); - } - - /** - * Read a JSON Object using the object identifier. - * - * @param jsonObjectId the JSON object identifier. - * @return a ResponseEntity. - */ - @GetMapping("/json-object/{id}") - public final ResponseEntity getJsonObjectById( - @PathVariable("id") final int jsonObjectId) { - return new ResponseEntity<>(cpService.getJsonById(jsonObjectId), HttpStatus.OK); - } - - /** - * Delete a JSON Object using the object identifier. - * - * @param jsonObjectId the JSON object identifier. - * @return a ResponseEntity. - */ - @DeleteMapping("json-object/{id}") - public final ResponseEntity deleteJsonObjectById( - @PathVariable("id") final int jsonObjectId) { - cpService.deleteJsonById(jsonObjectId); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - private static void validateJsonStructure(final MultipartFile multipartFile) { - try { - final Gson gson = new Gson(); - gson.fromJson(getJsonString(multipartFile), Object.class); - } catch (final JsonSyntaxException e) { - throw new DataValidationException("Not a valid JSON file.", e.getMessage(), e); - } - } - - private static File saveToFile(final MultipartFile multipartFile) { - try { - final File file = File.createTempFile("tempFile", ".yang"); - file.deleteOnExit(); - try (final OutputStream outputStream = new FileOutputStream(file)) { - outputStream.write(multipartFile.getBytes()); - } - return file; - - } catch (final IOException e) { - throw new CpsException(e); - } - } - - private static String getJsonString(final MultipartFile multipartFile) { - try { - return new String(multipartFile.getBytes()); - } catch (final IOException e) { - throw new CpsException(e); - } - } } diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy index d951cbeb69..e427c6063e 100644 --- a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy +++ b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy @@ -20,7 +20,7 @@ package org.onap.cps.rest.exceptions import groovy.json.JsonSlurper -import org.onap.cps.api.CpService +import org.onap.cps.api.CpsAdminService import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException import org.onap.cps.spi.exceptions.CpsException import org.onap.cps.spi.exceptions.DataValidationException @@ -50,12 +50,12 @@ class CpsRestExceptionHandlerSpec extends Specification { def existingObjectName = 'MyAdminObject' def cpsRestController = new CpsRestController() - def mockCpService = Mock(CpService.class) + def mockCpsAdminService = Mock(CpsAdminService.class) def objectUnderTest = new CpsRestExceptionHandler() def mockMvc = standaloneSetup(cpsRestController).setControllerAdvice(objectUnderTest).build() def setup() { - cpsRestController.cpService = mockCpService + cpsRestController.cpsAdminService = mockCpsAdminService } def 'Get request with runtime exception returns HTTP Status Internal Server Error'() { @@ -130,11 +130,11 @@ class CpsRestExceptionHandlerSpec extends Specification { */ def setupTestException(exception) { - mockCpService.getJsonById(_) >> { throw exception } + mockCpsAdminService.getAnchors(_) >> { throw exception} } def performTestRequest() { - return mockMvc.perform(get('/json-object/1')).andReturn().response + return mockMvc.perform(get('/v1/dataspaces/dataspace-name/anchors')).andReturn().response } void assertTestResponse(response, expectedStatus, expectedErrorMessage, expectedErrorDetails) { -- cgit 1.2.3-korg