From 6ae5484164a944e9ad3211c1cbdc89cfc520688d Mon Sep 17 00:00:00 2001 From: Shaaban Ebrahim Date: Mon, 18 Nov 2019 19:39:26 +0200 Subject: add service for searching in meta data pageable Issue-ID: CCSDK-1770 Signed-off-by: Shaaban Ebrahim Change-Id: Ibf718314f2f818108af3133641ab7be48c334dce --- .../repository/BlueprintModelSearchRepository.kt | 24 ++++++++++++++++++++++ .../designer/api/BlueprintModelController.kt | 17 ++++++++++++++- .../designer/api/handler/BluePrintModelHandler.kt | 18 +++++++++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) (limited to 'ms/blueprintsprocessor') diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt index 60ca1fec1..5c7a94034 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/repository/BlueprintModelSearchRepository.kt @@ -18,6 +18,9 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch +import org.springframework.data.domain.Page +import org.springframework.data.domain.PageRequest +import org.springframework.data.domain.Pageable import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository @@ -76,4 +79,25 @@ interface BlueprintModelSearchRepository : JpaRepository + + + /** + * This is a findby some attributes method + * + * @author Shaaban Ebrahim + * + * @param updatedBy + * @param tags + * @param artifactName + * @param artifactVersion + * @param artifactType + * @param pageRequest + * @return Page + */ + fun findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType(updatedBy: String, tags: String, artifactName: String, artifactVersion: String, + artifactType: String,pageRequest: Pageable): Page + + + + } diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt index ea5023cd5..94c095047 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt @@ -35,7 +35,9 @@ import org.springframework.http.ResponseEntity import org.springframework.http.codec.multipart.FilePart import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* +import reactor.core.publisher.Flux import reactor.core.publisher.Mono +import java.time.Duration /** * BlueprintModelController Purpose: Handle controllerBlueprint API request @@ -76,10 +78,23 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @ResponseBody @PreAuthorize("hasRole('USER')") fun allBlueprintModelMetaData(@NotNull @PathVariable(value = "keyword") keyWord: String): List { - return this.bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord) + return this.bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord) } + @GetMapping("/paged/meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @PreAuthorize("hasRole('USER')") + fun allBlueprintModelMetaDataPaged(@NotNull @PathVariable(value = "keyword") keyWord: String, + @RequestParam(defaultValue = "20") limit: Int, + @RequestParam(defaultValue = "0") offset: Int, + @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption + ): Page { + val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName) + return this.bluePrintModelHandler.searchBluePrintModelsByKeyWordPaged(keyWord,pageRequest) + + } + @DeleteMapping("/{id}") @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt index 19076c681..216648369 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt @@ -35,6 +35,7 @@ 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.data.domain.PageRequest import org.springframework.http.HttpHeaders import org.springframework.http.MediaType import org.springframework.http.ResponseEntity @@ -245,7 +246,22 @@ open class BluePrintModelHandler(private val blueprintsProcessorCatalogService: findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType( keyWord,keyWord,keyWord,keyWord,keyWord) } - + + + + /** + * This is a searchBluePrintModelsByKeyWordPagebale method to retrieve specific BlueprintModel in Database + * where keyword equals updatedBy or tags or artifcat name or artifcat version or artifact type and pageable + * @author Shaaban Ebrahim + * @param keyWord + * + * @return List list of the controller blueprint + */ + open fun searchBluePrintModelsByKeyWordPaged(keyWord: String, pageRequest: PageRequest): Page + { + return blueprintModelSearchRepository. + findByUpdatedByOrTagsOrOrArtifactNameOrOrArtifactVersionOrArtifactType(keyWord,keyWord,keyWord,keyWord,keyWord,pageRequest) + } /** * This is a deleteBlueprintModel method * -- cgit 1.2.3-korg