Adding some minor features
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / ResourceDictionaryController.kt
index 1dcfa2f..a9a2e69 100644 (file)
@@ -21,10 +21,14 @@ import io.swagger.annotations.ApiOperation
 import io.swagger.annotations.ApiParam
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ResourceDictionaryHandler
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.DictionarySortByOption
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping
+import org.springframework.data.domain.Page
+import org.springframework.data.domain.PageRequest
+import org.springframework.data.domain.Sort
 import org.springframework.http.MediaType
 import org.springframework.web.bind.annotation.DeleteMapping
 import org.springframework.web.bind.annotation.GetMapping
@@ -32,50 +36,71 @@ import org.springframework.web.bind.annotation.PathVariable
 import org.springframework.web.bind.annotation.PostMapping
 import org.springframework.web.bind.annotation.RequestBody
 import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RequestParam
 import org.springframework.web.bind.annotation.ResponseBody
 import org.springframework.web.bind.annotation.RestController
 
 @RestController
 @RequestMapping(value = ["/api/v1/dictionary"])
 @Api(
-    value = "Resource dictionary",
-    description = "Interaction with stored dictionaries."
+    value = "Resource Dictionary",
+    description = "Interaction with stored dictionaries"
 )
 open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) {
 
     @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
     @ApiOperation(
-        value = "Retrieve a resource dictionary.",
+        value = "Retrieve a resource dictionary",
         notes = "Retrieve a resource dictionary by name provided.",
         response = ResourceDictionary::class
     )
     @ResponseBody
     @Throws(BluePrintException::class)
     suspend fun getResourceDictionaryByName(
-        @ApiParam(value = "Name of the resource.", required = true, example = "\"hostname\"")
+        @ApiParam(value = "Name of the resource", required = true, example = "\"hostname\"")
         @PathVariable(value = "name") name: String
     ): ResourceDictionary =
         mdcWebCoroutineScope {
             resourceDictionaryHandler.getResourceDictionaryByName(name)
         }
 
+    @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE])
+    @ApiOperation(
+        value = "Get Blueprints Dictionary ordered",
+        notes = "Lists all blueprint Dictionary which are saved in CDS in an ordered mode.",
+        nickname = "BlueprintModelController_allBlueprintDictionaryPaged_GET.org.onap.ccsdk.cds.blueprintsprocessor.designer.api"
+    )
+    @ResponseBody
+    suspend fun allBlueprintModel(
+        @ApiParam(value = "Maximum number of returned blueprint dictionary") @RequestParam(defaultValue = "20") limit: Int,
+        @ApiParam(value = "Offset") @RequestParam(defaultValue = "0") offset: Int,
+        @ApiParam(value = "Order of returned blueprint dictionary") @RequestParam(defaultValue = "DATE") sort: DictionarySortByOption,
+        @ApiParam(value = "Ascend or descend ordering") @RequestParam(defaultValue = "ASC") sortType: String
+    ): Page<ResourceDictionary> {
+        val pageRequest = PageRequest.of(
+            offset, limit,
+            Sort.Direction.fromString(sortType), sort.columnName
+        )
+        return resourceDictionaryHandler.getAllDictionary(pageRequest)
+    }
+
     @PostMapping(
         produces = [MediaType.APPLICATION_JSON_VALUE],
         consumes = [MediaType.APPLICATION_JSON_VALUE]
     )
     @ApiOperation(
-        value = "Saves a resource dictionary.",
-        notes = "Saves a resource dictionary by dictionary provided.",
+        value = "Save a resource dictionary",
+        notes = "Save a resource dictionary by dictionary provided.",
         response = ResourceDictionary::class
     )
     @ResponseBody
     @Throws(BluePrintException::class)
     suspend fun saveResourceDictionary(
-        @ApiParam(value = "Resource dictionary to store.", required = true)
-        @RequestBody dataDictionary: ResourceDictionary
+        @ApiParam(value = "Resource dictionary to store", required = true)
+        @RequestBody resourceDictionary: ResourceDictionary
     ): ResourceDictionary =
         mdcWebCoroutineScope {
-            resourceDictionaryHandler.saveResourceDictionary(dataDictionary)
+            resourceDictionaryHandler.saveResourceDictionary(resourceDictionary)
         }
 
     @PostMapping(
@@ -84,28 +109,49 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R
         consumes = [MediaType.APPLICATION_JSON_VALUE]
     )
     @ApiOperation(
-        value = "Saves a resource dictionary.",
-        notes = "Saves a resource dictionary by resource definition provided.",
+        value = "Save a resource dictionary",
+        notes = "Save a resource dictionary by provided resource definition json.",
         nickname = "ResourceDictionaryController_saveResourceDictionary_1_POST.org.onap.ccsdk.cds.blueprintsprocessor.designer.api",
-        response = ResourceDefinition::class
+        response = ResourceDictionary::class
     )
     @ResponseBody
     @Throws(BluePrintException::class)
-    suspend fun saveResourceDictionary(
-        @ApiParam(value = "Resource definition to generate.", required = true)
+    suspend fun saveResourceDefinition(
+        @ApiParam(value = "Resource definition to generate Resource Dictionary", required = true)
         @RequestBody resourceDefinition: ResourceDefinition
-    ): ResourceDefinition =
+    ): ResourceDictionary =
         mdcWebCoroutineScope {
             resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
         }
 
+    @PostMapping(
+        path = ["/definition-bulk"],
+        produces = [MediaType.APPLICATION_JSON_VALUE],
+        consumes = [MediaType.APPLICATION_JSON_VALUE]
+    )
+    @ApiOperation(
+        value = "Save multiple resource dictionaries",
+        notes = "Save multiple resource dictionaries by provided resource definition json array.",
+        nickname = "ResourceDictionaryController_saveAllResourceDictionary_1_POST.org.onap.ccsdk.cds.blueprintsprocessor.designer.api",
+        response = ResourceDictionary::class
+    )
+    @ResponseBody
+    @Throws(BluePrintException::class)
+    suspend fun saveAllResourceDictionary(
+        @ApiParam(value = "Resource definition json array to generate Resource Dictionaries", required = true)
+        @RequestBody resourceDefinition: List<ResourceDefinition>
+    ): MutableList<ResourceDictionary> =
+        mdcWebCoroutineScope {
+            resourceDictionaryHandler.saveAllResourceDefinition(resourceDefinition)
+        }
+
     @DeleteMapping(path = ["/{name}"])
     @ApiOperation(
-        value = "Removes a resource dictionary.",
-        notes = "Removes a resource dictionary by name provided."
+        value = "Remove a resource dictionary",
+        notes = "Remove a resource dictionary by name provided."
     )
     suspend fun deleteResourceDictionaryByName(
-        @ApiParam(value = "Name of the resource.", required = true)
+        @ApiParam(value = "Name of the resource", required = true)
         @PathVariable(value = "name") name: String
     ) = mdcWebCoroutineScope {
         resourceDictionaryHandler.deleteResourceDictionary(name)
@@ -117,14 +163,14 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R
         consumes = [MediaType.APPLICATION_JSON_VALUE]
     )
     @ApiOperation(
-        value = "Searches for a resource dictionary.",
-        notes = "Searches for a resource dictionary by names provided.",
+        value = "Search for a resource dictionary",
+        notes = "Search for a resource dictionary by names provided.",
         responseContainer = "List",
         response = ResourceDictionary::class
     )
     @ResponseBody
     suspend fun searchResourceDictionaryByNames(
-        @ApiParam(value = "List of names.", required = true)
+        @ApiParam(value = "List of names", required = true)
         @RequestBody names: List<String>
     ): List<ResourceDictionary> =
         mdcWebCoroutineScope {
@@ -133,14 +179,14 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R
 
     @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
     @ApiOperation(
-        value = "Searches for a resource dictionary.",
-        notes = "Searches for a resource dictionary by tags provided.",
+        value = "Search for a resource dictionary",
+        notes = "Search for a resource dictionary by tags provided.",
         responseContainer = "List",
         response = ResourceDictionary::class
     )
     @ResponseBody
     suspend fun searchResourceDictionaryByTags(
-        @ApiParam(value = "Tags list.", required = true, example = "\"status\"")
+        @ApiParam(value = "Tags list", required = true, example = "\"status\"")
         @PathVariable(value = "tags") tags: String
     ): List<ResourceDictionary> =
         mdcWebCoroutineScope {
@@ -149,8 +195,8 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R
 
     @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE])
     @ApiOperation(
-        value = "Searches for a source mapping.",
-        notes = "Searches for a source mapping.",
+        value = "Search for a source mapping",
+        notes = "Search for a source mapping.",
         response = ResourceSourceMapping::class
     )
     @ResponseBody
@@ -160,7 +206,7 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R
 
     @GetMapping(path = ["/resource_dictionary_group"], produces = [MediaType.APPLICATION_JSON_VALUE])
     @ApiOperation(
-        value = "Retrieve all resource dictionary groups.",
+        value = "Retrieve all resource dictionary groups",
         notes = "Retrieve all resource dictionary groups.",
         responseContainer = "List",
         response = String::class