Remove jersey and aai-rest-client dependencies from model-loader 99/137799/1
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 26 Apr 2024 14:08:17 +0000 (16:08 +0200)
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 26 Apr 2024 14:08:17 +0000 (16:08 +0200)
- aai-rest-client has been fully replaced with RestTemplate
- use spring provided imports in ModelController

Issue-ID: AAI-3836
Change-Id: If2471c8a68c273823bef138626534df1894a91d7
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
pom.xml
src/main/java/org/onap/aai/modelloader/entity/ArtifactHandler.java
src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler.java
src/main/java/org/onap/aai/modelloader/service/ModelController.java
src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java [deleted file]
src/test/java/org/onap/aai/modelloader/service/TestModelController.java
src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java

diff --git a/pom.xml b/pom.xml
index 633350a..45f8a77 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                                </exclusion>
                        </exclusions>
                </dependency>
-               <dependency>
-                       <groupId>org.glassfish.jersey.core</groupId>
-                       <artifactId>jersey-common</artifactId>
-                       <scope>test</scope>
-               </dependency>
-               <dependency>
-                       <groupId>org.onap.aai</groupId>
-                       <artifactId>rest-client</artifactId>
-                       <version>${aai.rest.client.version}</version>
-               </dependency>
                <dependency>
                        <groupId>com.google.code.gson</groupId>
                        <artifactId>gson</artifactId>
index c630822..50abdd0 100644 (file)
@@ -23,7 +23,6 @@ package org.onap.aai.modelloader.entity;
 import java.util.List;\r
 import org.onap.aai.modelloader.config.ModelLoaderConfig;\r
 import org.onap.aai.modelloader.restclient.AaiRestClient;\r
-import org.springframework.web.client.RestTemplate;\r
 \r
 public abstract class ArtifactHandler {\r
 \r
index 95d3426..9b05024 100644 (file)
@@ -46,7 +46,6 @@ import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;\r
 import org.springframework.http.ResponseEntity;\r
 import org.springframework.stereotype.Component;\r
-import org.springframework.web.client.RestTemplate;\r
 import org.w3c.dom.Document;\r
 import org.w3c.dom.Element;\r
 import org.w3c.dom.Node;\r
index 41a7c86..343fdca 100644 (file)
@@ -25,9 +25,6 @@ import java.util.ArrayList;
 import java.util.Base64;
 import java.util.List;
 
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
 import org.onap.aai.cl.api.Logger;
 import org.onap.aai.cl.eelf.LoggerFactory;
 import org.onap.aai.modelloader.config.ModelLoaderConfig;
@@ -37,7 +34,11 @@ import org.onap.aai.modelloader.notification.NotificationDataImpl;
 import org.onap.aai.modelloader.notification.NotificationPublisher;
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.notification.IArtifactInfo;
+import org.springframework.http.ResponseEntity;
+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.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -47,7 +48,7 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @RestController
 @RequestMapping("/services/model-loader/v1/model-service")
-public class ModelController implements ModelLoaderInterface {
+public class ModelController {
 
     private static final Logger logger = LoggerFactory.getInstance().getLogger(ModelController.class);
 
@@ -63,47 +64,37 @@ public class ModelController implements ModelLoaderInterface {
         this.artifactDownloadManager = artifactDownloadManager;
     }
 
-    /**
-     * (non-Javadoc)
-     *
-     * @see org.onap.aai.modelloader.service.ModelLoaderInterface#loadModel(java.lang.String)
-     */
-    @Override
-    public Response loadModel(@PathVariable String modelid) {
-        return Response.ok("{\"model_loaded\":\"" + modelid + "\"}").build();
+    @GetMapping(value = "/loadModel/{modelid}", produces = "application/json")
+    public ResponseEntity<String> loadModel(@PathVariable String modelid) {
+        return ResponseEntity.ok("{\"model_loaded\":\"" + modelid + "\"}");
     }
 
-    /**
-     * (non-Javadoc)
-     *
-     * @see org.onap.aai.modelloader.service.ModelLoaderInterface#saveModel(java.lang.String, java.lang.String)
-     */
-    @Override
-    public Response saveModel(@PathVariable String modelid, @PathVariable String modelname) {
-        return Response.ok("{\"model_saved\":\"" + modelid + "-" + modelname + "\"}").build();
+    @PutMapping(value = "/saveModel/{modelid}/{modelname}", produces = "application/json")
+    public ResponseEntity<String> saveModel(@PathVariable String modelid, @PathVariable String modelname) {
+        return ResponseEntity.ok("{\"model_saved\":\"" + modelid + "-" + modelname + "\"}");
     }
 
-    @Override
-    public Response ingestModel(@PathVariable String modelName, @PathVariable String modelVersion,
+    @PostMapping(value = "/ingestModel/{modelName}/{modelVersion}", produces = "application/json")
+    public ResponseEntity<String> ingestModel(@PathVariable String modelName, @PathVariable String modelVersion,
             @RequestBody String payload) throws IOException {
-        Response response;
+        ResponseEntity<String> response;
 
         if (config.getIngestSimulatorEnabled()) {
             response = processTestArtifact(modelName, modelVersion, payload);
         } else {
             logger.debug("Simulation interface disabled");
-            response = Response.serverError().build();
+            response = ResponseEntity.internalServerError().build();
         }
 
         return response;
     }
 
-    private Response processTestArtifact(String modelName, String modelVersion, String payload) {
+    private ResponseEntity<String> processTestArtifact(String modelName, String modelVersion, String payload) {
         IArtifactInfo artifactInfo = new ArtifactInfoImpl();
         ((ArtifactInfoImpl) artifactInfo).setArtifactName(modelName);
         ((ArtifactInfoImpl) artifactInfo).setArtifactVersion(modelVersion);
 
-        Response response;
+        ResponseEntity<String> response;
         try {
             logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Received test artifact " + modelName + " " + modelVersion);
 
@@ -125,7 +116,7 @@ public class ModelController implements ModelLoaderInterface {
             boolean success =
                     artifactDeploymentManager.deploy(notificationData, modelArtifacts, catalogArtifacts);
             logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Deployment success was " + success);
-            response = success ? Response.ok().build() : Response.serverError().build();
+            response = success ? ResponseEntity.ok().build() : ResponseEntity.internalServerError().build();
         } catch (Exception e) {
             String responseMessage = e.getMessage();
             logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Exception handled: " + responseMessage);
@@ -135,7 +126,7 @@ public class ModelController implements ModelLoaderInterface {
             } else {
                 responseMessage += "\nSDC publishing is enabled but has been bypassed";
             }
-            response = Response.serverError().entity(responseMessage).type(MediaType.APPLICATION_XML).build();
+            response = ResponseEntity.internalServerError().body(responseMessage);
         }
         return response;
     }
diff --git a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java
deleted file mode 100644 (file)
index 4c7b182..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 European Software Marketing Ltd.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.modelloader.service;
-
-import java.io.IOException;
-import javax.ws.rs.core.Response;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-public interface ModelLoaderInterface {
-
-    @GetMapping(value = "/loadModel/{modelid}", produces = "application/json")
-    @ResponseBody
-    Response loadModel(String modelid);
-
-    @PutMapping(value = "/saveModel/{modelid}/{modelname}", produces = "application/json")
-    @ResponseBody
-    Response saveModel(String modelid, String modelname);
-
-    @PostMapping(value = "/ingestModel/{modelName}/{modelVersion}", produces = "application/json")
-    @ResponseBody
-    Response ingestModel(String modelid, String modelVersion, String payload) throws IOException;
-}
index 970aa7a..6cfeb65 100644 (file)
@@ -29,8 +29,6 @@ import java.io.IOException;
 import java.util.Base64;
 import java.util.Collections;
 
-import javax.ws.rs.core.Response;
-
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.mockito.InjectMocks;
@@ -47,6 +45,8 @@ import org.onap.aai.modelloader.util.ArtifactTestUtils;
 import org.onap.sdc.api.IDistributionClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.test.context.TestPropertySource;
 
 /**
@@ -80,28 +80,28 @@ public class TestModelController {
 
     @Test
     public void testLoadModel() {
-        Response response = modelController.loadModel("");
-        assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+        ResponseEntity<String> response = modelController.loadModel("");
+        assertThat(response.getStatusCode(), is(HttpStatus.OK));
     }
 
     @Test
     public void testSaveModel() {
-        Response response = modelController.saveModel("", "");
-        assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+        ResponseEntity<String> response = modelController.saveModel("", "");
+        assertThat(response.getStatusCode(), is(HttpStatus.OK));
     }
 
     @Test
     public void testIngestModel() throws IOException {
         byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
-        Response response = modelController.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
-        assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+        ResponseEntity<String> response = modelController.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
+        assertThat(response.getStatusCode(), is(HttpStatus.OK));
     }
 
     @Test
     public void testIngestModelMissingName() throws IOException {
         byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
-        Response response = modelController.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
-        assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+        ResponseEntity<String> response = modelController.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
+        assertThat(response.getStatusCode(), is(HttpStatus.INTERNAL_SERVER_ERROR));
     }
 
 }
index 6dc1b3d..e9ab7c0 100644 (file)
@@ -26,12 +26,12 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import java.io.IOException;
 import java.util.Base64;
 
-import javax.ws.rs.core.Response;
-
 import org.junit.jupiter.api.Test;
 import org.onap.aai.modelloader.util.ArtifactTestUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.test.context.TestPropertySource;
 
 /**
@@ -48,8 +48,8 @@ public class TestModelLoaderServiceWithSdc {
     @Test
     public void testIngestModel() throws IOException {
         byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
-        Response response = controller.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
-        assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+        ResponseEntity<String> response = controller.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
+        assertThat(response.getStatusCode(), is(HttpStatus.INTERNAL_SERVER_ERROR));
     }