add get blueprints API with pagination and sorting 49/97949/1
authorAhmed Abbas <ahmad.helmy@orange.com>
Tue, 5 Nov 2019 10:38:25 +0000 (12:38 +0200)
committerAhmed Abbas <ahmad.helmy@orange.com>
Tue, 5 Nov 2019 10:38:25 +0000 (12:38 +0200)
Issue-ID: CCSDK-1770
Signed-off-by: Ahmed Abbas <ahmad.helmy@orange.com>
Change-Id: Ia9bd9b78df1d7dc5c0b6e67af2d58922f9c9a935

ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/SortByOptionsEnum.kt [new file with mode: 0644]

index bf251f6..10cc0a4 100644 (file)
@@ -21,9 +21,13 @@ import io.swagger.annotations.ApiOperation
 import io.swagger.annotations.ApiParam
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BlueprintSortByOption
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.monoMdc
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
 import org.springframework.core.io.Resource
+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.http.ResponseEntity
 import org.springframework.http.codec.multipart.FilePart
@@ -56,6 +60,16 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
         return this.bluePrintModelHandler.allBlueprintModel()
     }
 
+    @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE])
+    @ResponseBody
+    @PreAuthorize("hasRole('USER')")
+    fun allBlueprintModel(@RequestParam(defaultValue = "20") limit: Int,
+                          @RequestParam(defaultValue = "0") offset: Int,
+                          @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption): Page<BlueprintModelSearch> {
+        val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName)
+        return this.bluePrintModelHandler.allBlueprintModel(pageRequest)
+    }
+
     @DeleteMapping("/{id}")
     @Throws(BluePrintException::class)
     @PreAuthorize("hasRole('USER')")
index 526e92c..f4b0068 100644 (file)
@@ -33,6 +33,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCach
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
 import org.springframework.core.io.ByteArrayResource
 import org.springframework.core.io.Resource
+import org.springframework.data.domain.Page
 import org.springframework.http.HttpHeaders
 import org.springframework.http.MediaType
 import org.springframework.http.ResponseEntity
@@ -41,6 +42,8 @@ import org.springframework.stereotype.Service
 import org.springframework.transaction.annotation.Transactional
 import java.io.IOException
 import java.util.*
+import org.springframework.data.domain.Pageable
+
 
 /**
  * BlueprintModelHandler Purpose: Handler service to handle the request from BlurPrintModelRest
@@ -68,6 +71,15 @@ open class BluePrintModelHandler(private val blueprintsProcessorCatalogService:
         return blueprintModelSearchRepository.findAll()
     }
 
+    /**
+     * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database
+     *
+     * @return List<BlueprintModelSearch> list of the controller blueprint archives
+    </BlueprintModelSearch> */
+    open fun allBlueprintModel(pageRequest: Pageable): Page<BlueprintModelSearch> {
+        return blueprintModelSearchRepository.findAll(pageRequest)
+    }
+
     /**
      * This is a saveBlueprintModel method
      *
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/SortByOptionsEnum.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/utils/SortByOptionsEnum.kt
new file mode 100644 (file)
index 0000000..6f56365
--- /dev/null
@@ -0,0 +1,6 @@
+package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils
+
+enum class BlueprintSortByOption(val columnName: String) {
+    DATE("createdDate"),
+    NAME("artifactName")
+}
\ No newline at end of file