From 3c7739c914b01fae525d7755b4eff5f2c60c955d Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Mon, 11 Mar 2019 13:10:00 -0400 Subject: Code improvement CB controllers Change-Id: I9cc49bb8f93d72e4e642be18381cd562953cc678 Issue-ID: CCSDK-1137 Signed-off-by: Muthuramalingam, Brinda Santh --- .../service/rs/ResourceDictionaryRest.java | 85 ----------------- .../service/controller/BlueprintModelController.kt | 101 +++++++++++++++++++++ .../service/controller/BlueprintModelRest.kt | 100 -------------------- .../controller/ResourceDictionaryController.kt | 68 ++++++++++++++ 4 files changed, 169 insertions(+), 185 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRest.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryController.kt (limited to 'ms/controllerblueprints/modules/service/src/main') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java deleted file mode 100644 index 8b7a95776..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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. - */ - -package org.onap.ccsdk.apps.controllerblueprints.service.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.onap.ccsdk.apps.controllerblueprints.service.handler.ResourceDictionaryHandler; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Deprecated -@RestController -@RequestMapping(value = "/api/v1/dictionary") -public class ResourceDictionaryRest { - - - private ResourceDictionaryHandler resourceDictionaryHandler; - - /** - * This is a DataDictionaryRestImpl, used to save and get the Resource Mapping stored in database - * - * @param resourceDictionaryHandler Data Dictionary Handler - */ - public ResourceDictionaryRest(ResourceDictionaryHandler resourceDictionaryHandler) { - this.resourceDictionaryHandler = resourceDictionaryHandler; - } - - @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) throws BluePrintException { - return resourceDictionaryHandler.saveResourceDictionary(dataDictionary); - } - - @DeleteMapping(path = "/{name}") - public void deleteResourceDictionaryByName(@PathVariable(value = "name") String name) { - resourceDictionaryHandler.deleteResourceDictionary(name); - } - - @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ResourceDictionary getResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { - return resourceDictionaryHandler.getResourceDictionaryByName(name); - } - - @PostMapping(path = "/by-names", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List searchResourceDictionaryByNames(@RequestBody List names) { - return resourceDictionaryHandler.searchResourceDictionaryByNames(names); - } - - @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) { - return resourceDictionaryHandler.searchResourceDictionaryByTags(tags); - - } - - @GetMapping(path = "/source-mapping", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ResourceSourceMapping getResourceSourceMapping() { - return resourceDictionaryHandler.getResourceSourceMapping(); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt new file mode 100644 index 000000000..60c07ad2c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt @@ -0,0 +1,101 @@ +/* + * Copyright © 2019 Bell Canada Intellectual Property. + * Modifications Copyright © 2019 IBM. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.service.controller + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch +import org.onap.ccsdk.apps.controllerblueprints.service.handler.BluePrintModelHandler +import org.springframework.core.io.Resource +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity +import org.springframework.http.codec.multipart.FilePart +import org.springframework.web.bind.annotation.* +import reactor.core.publisher.Mono + +/** + * BlueprintModelController Purpose: Handle controllerBlueprint API request + * + * @author Vinal Patel + * @version 1.0 + */ +@RestController +@RequestMapping("/api/v1/blueprint-model") +open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) { + + @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun saveBlueprint(@RequestPart("file") file: FilePart): Mono { + return bluePrintModelHandler.saveBlueprintModel(file) + } + + @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun allBlueprintModel(): List { + return this.bluePrintModelHandler.allBlueprintModel() + } + + @DeleteMapping("/{id}") + @Throws(BluePrintException::class) + fun deleteBlueprint(@PathVariable(value = "id") id: String) { + this.bluePrintModelHandler.deleteBlueprintModel(id) + } + + @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, + @PathVariable(value = "version") version: String): BlueprintModelSearch { + return this.bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version) + } + + @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, + @PathVariable(value = "version") version: String): ResponseEntity { + return this.bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version) + } + + @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch { + return this.bluePrintModelHandler.getBlueprintModelSearch(id) + } + + @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity { + return this.bluePrintModelHandler.downloadBlueprintModelFile(id) + } + + @PutMapping("/publish/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun publishBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch { + return this.bluePrintModelHandler.publishBlueprintModel(id) + } + + @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List { + return this.bluePrintModelHandler.searchBlueprintModels(tags) + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRest.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRest.kt deleted file mode 100644 index 0fca07b04..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRest.kt +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright © 2019 Bell Canada Intellectual Property. - * - * 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. - */ - -package org.onap.ccsdk.apps.controllerblueprints.service.controller - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch -import org.onap.ccsdk.apps.controllerblueprints.service.handler.BluePrintModelHandler -import org.springframework.core.io.Resource -import org.springframework.http.MediaType -import org.springframework.http.ResponseEntity -import org.springframework.http.codec.multipart.FilePart -import org.springframework.web.bind.annotation.* -import reactor.core.publisher.Mono - -/** - * BlueprintModelRest Purpose: Handle controllerBlueprint API request - * - * @author Vinal Patel - * @version 1.0 - */ -@RestController -@RequestMapping("/api/v1/blueprint-model") -open class BlueprintModelRest(private val bluePrintModelHandler: BluePrintModelHandler) { - - @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun saveBlueprint(@RequestPart("file") file: FilePart): Mono { - return bluePrintModelHandler.saveBlueprintModel(file) - } - - @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - fun allBlueprintModel(): List { - return this.bluePrintModelHandler.allBlueprintModel() - } - - @DeleteMapping("/{id}") - @Throws(BluePrintException::class) - fun deleteBlueprint(@PathVariable(value = "id") id: String) { - this.bluePrintModelHandler.deleteBlueprintModel(id) - } - - @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, - @PathVariable(value = "version") version: String): BlueprintModelSearch { - return this.bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version) - } - - @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, - @PathVariable(value = "version") version: String): ResponseEntity { - return this.bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version) - } - - @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch { - return this.bluePrintModelHandler.getBlueprintModelSearch(id) - } - - @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity { - return this.bluePrintModelHandler.downloadBlueprintModelFile(id) - } - - @PutMapping("/publish/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun publishBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch { - return this.bluePrintModelHandler.publishBlueprintModel(id) - } - - @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List { - return this.bluePrintModelHandler.searchBlueprintModels(tags) - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryController.kt new file mode 100644 index 000000000..38397faa0 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryController.kt @@ -0,0 +1,68 @@ +/* + * Copyright © 2019 IBM. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints.service.controller + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary +import org.onap.ccsdk.apps.controllerblueprints.service.handler.ResourceDictionaryHandler +import org.springframework.http.MediaType +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping(value = ["/api/v1/dictionary"]) +open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) { + + @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary { + return resourceDictionaryHandler.getResourceDictionaryByName(name) + } + + @PostMapping(path = [""], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary { + return resourceDictionaryHandler.saveResourceDictionary(dataDictionary) + } + + @DeleteMapping(path = ["/{name}"]) + fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) { + resourceDictionaryHandler.deleteResourceDictionary(name) + } + + @PostMapping(path = ["/by-names"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun searchResourceDictionaryByNames(@RequestBody names: List): List { + return resourceDictionaryHandler.searchResourceDictionaryByNames(names) + } + + @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List { + return resourceDictionaryHandler.searchResourceDictionaryByTags(tags) + + } + + @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun getResourceSourceMapping(): ResourceSourceMapping { + return resourceDictionaryHandler.getResourceSourceMapping() + } + +} -- cgit 1.2.3-korg