CSIT Support for ServiceLevel PNF Software Upgrade
[integration/csit.git] / plans / usecases-pnf-sw-upgrade / pnf-sw-upgrade / sorch / simulator / aai-simulator / src / main / java / org / onap / aaisimulator / controller / ServiceDesignAndCreationController.java
index ddc2b62..1375387 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 package org.onap.aaisimulator.controller;
 
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import javax.ws.rs.core.MediaType;
+import org.onap.aaisimulator.models.ServiceModelVersion;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -50,25 +53,27 @@ public class ServiceDesignAndCreationController {
     @Value("${SERVICE_DESIGN_AND_CREATION_RESPONSES_LOCATION:./}")
     private String responsesLocation;
 
-    @GetMapping(path = "/models/model/{model-invariant-id}/model-vers",
-            produces = MediaType.APPLICATION_XML_VALUE)
+    @GetMapping(path = "/models/model/{model-invariant-id}/model-vers",  produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public ResponseEntity<String> getModelVers(@PathVariable("model-invariant-id") String modelInvariantId) {
         Path responsesPath = Paths.get(responsesLocation).toAbsolutePath();
         LOGGER.info("Will get ModelVer for 'model-invariant-id': {}, looking under {}",
                 modelInvariantId, responsesPath.toString());
 
-        Path responsePath = responsesPath.resolve(modelInvariantId + ".xml");
+        Path responsePath = responsesPath.resolve(modelInvariantId + ".json");
         if (!responsePath.toFile().exists()) {
             LOGGER.error("{} not found", responsePath.toString());
             return ResponseEntity.notFound().build();
         }
         try {
             String content = new String(Files.readAllBytes(responsePath), StandardCharsets.UTF_8);
+            Gson gson = new GsonBuilder().setPrettyPrinting().create();
+            ServiceModelVersion json = gson.fromJson(content, ServiceModelVersion.class);
+            String jsonInString = gson.toJson(json);
             LOGGER.info("{} found with {} characters", responsePath.toString(), content.length());
-            return ResponseEntity.ok().body(content);
+            return ResponseEntity.ok().body(jsonInString);
         } catch (IOException e) {
             LOGGER.error("Failed to read response from {}: {}}", responsePath.toString(), e.getMessage());
             return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
         }
     }
-}
+}
\ No newline at end of file