2 * Copyright © 2019 Bell Canada Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
4 * Modifications Copyright © 2019 Orange.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
21 import io.swagger.annotations.ApiOperation
22 import io.swagger.annotations.ApiParam
23 import org.jetbrains.annotations.NotNull
24 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
25 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler
26 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BlueprintSortByOption
27 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
28 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
29 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString
30 import org.springframework.core.io.Resource
31 import org.springframework.data.domain.Page
32 import org.springframework.data.domain.PageRequest
33 import org.springframework.data.domain.Sort
34 import org.springframework.http.HttpStatus
35 import org.springframework.http.MediaType
36 import org.springframework.http.ResponseEntity
37 import org.springframework.http.codec.multipart.FilePart
38 import org.springframework.security.access.prepost.PreAuthorize
39 import org.springframework.web.bind.annotation.DeleteMapping
40 import org.springframework.web.bind.annotation.GetMapping
41 import org.springframework.web.bind.annotation.PathVariable
42 import org.springframework.web.bind.annotation.PostMapping
43 import org.springframework.web.bind.annotation.RequestBody
44 import org.springframework.web.bind.annotation.RequestMapping
45 import org.springframework.web.bind.annotation.RequestParam
46 import org.springframework.web.bind.annotation.RequestPart
47 import org.springframework.web.bind.annotation.ResponseBody
48 import org.springframework.web.bind.annotation.RestController
51 * BlueprintModelController Purpose: Handle controllerBlueprint API request
57 @RequestMapping("/api/v1/blueprint-model")
58 open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) {
61 path = arrayOf("/bootstrap"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE),
62 consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)
65 @Throws(BluePrintException::class)
66 @PreAuthorize("hasRole('USER')")
67 suspend fun bootstrap(@RequestBody bootstrapRequest: BootstrapRequest): Unit = mdcWebCoroutineScope {
68 bluePrintModelHandler.bootstrapBlueprint(bootstrapRequest)
71 @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
73 @Throws(BluePrintException::class)
74 @PreAuthorize("hasRole('USER')")
75 suspend fun saveBlueprint(@RequestPart("file") filePart: FilePart): BlueprintModelSearch = mdcWebCoroutineScope {
76 bluePrintModelHandler.saveBlueprintModel(filePart)
79 @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
81 @PreAuthorize("hasRole('USER')")
82 fun allBlueprintModel(): List<BlueprintModelSearch> {
83 return this.bluePrintModelHandler.allBlueprintModel()
86 @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE])
88 @PreAuthorize("hasRole('USER')")
89 fun allBlueprintModel(
90 @RequestParam(defaultValue = "20") limit: Int,
91 @RequestParam(defaultValue = "0") offset: Int,
92 @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption,
93 @RequestParam(defaultValue = "ASC") sortType: String
94 ): Page<BlueprintModelSearch> {
95 val pageRequest = PageRequest.of(
97 Sort.Direction.fromString(sortType), sort.columnName
99 return this.bluePrintModelHandler.allBlueprintModel(pageRequest)
102 @GetMapping("meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
104 @PreAuthorize("hasRole('USER')")
105 suspend fun allBlueprintModelMetaData(@NotNull @PathVariable(value = "keyword") keyWord: String): List<BlueprintModelSearch> =
106 mdcWebCoroutineScope {
107 bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord)
110 @GetMapping("/paged/meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
112 @PreAuthorize("hasRole('USER')")
113 fun allBlueprintModelMetaDataPaged(
114 @NotNull @PathVariable(value = "keyword") keyWord: String,
115 @RequestParam(defaultValue = "20") limit: Int,
116 @RequestParam(defaultValue = "0") offset: Int,
117 @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption,
118 @RequestParam(defaultValue = "ASC") sortType: String
119 ): Page<BlueprintModelSearch> {
120 val pageRequest = PageRequest.of(
122 Sort.Direction.fromString(sortType), sort.columnName
124 return this.bluePrintModelHandler.searchBluePrintModelsByKeyWordPaged(keyWord, pageRequest)
127 @DeleteMapping("/{id}")
128 @Throws(BluePrintException::class)
129 @PreAuthorize("hasRole('USER')")
130 suspend fun deleteBlueprint(@PathVariable(value = "id") id: String) = mdcWebCoroutineScope {
131 bluePrintModelHandler.deleteBlueprintModel(id)
134 @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
136 @Throws(BluePrintException::class)
137 @PreAuthorize("hasRole('USER')")
138 suspend fun getBlueprintByNameAndVersion(
139 @PathVariable(value = "name") name: String,
140 @PathVariable(value = "version") version: String
141 ): ResponseEntity<BlueprintModelSearch> = mdcWebCoroutineScope {
142 val bluePrintModel: BlueprintModelSearch? =
143 bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
144 if (bluePrintModel != null)
145 ResponseEntity(bluePrintModel, HttpStatus.OK)
147 ResponseEntity(HttpStatus.NO_CONTENT)
150 @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
152 @Throws(BluePrintException::class)
153 @PreAuthorize("hasRole('USER')")
154 suspend fun downloadBlueprintByNameAndVersion(
155 @PathVariable(value = "name") name: String,
156 @PathVariable(value = "version") version: String
157 ): ResponseEntity<Resource> = mdcWebCoroutineScope {
158 bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
161 @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
163 @Throws(BluePrintException::class)
164 @PreAuthorize("hasRole('USER')")
165 suspend fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch = mdcWebCoroutineScope {
166 bluePrintModelHandler.getBlueprintModelSearch(id)
169 @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
171 @Throws(BluePrintException::class)
172 @PreAuthorize("hasRole('USER')")
173 suspend fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity<Resource> =
174 mdcWebCoroutineScope {
175 bluePrintModelHandler.downloadBlueprintModelFile(id)
179 "/enrich", produces = [MediaType.APPLICATION_JSON_VALUE],
182 .MULTIPART_FORM_DATA_VALUE
186 @Throws(BluePrintException::class)
187 @PreAuthorize("hasRole('USER')")
188 suspend fun enrichBlueprint(@RequestPart("file") file: FilePart): ResponseEntity<Resource> = mdcWebCoroutineScope {
189 bluePrintModelHandler.enrichBlueprint(file)
193 "/enrichandpublish", produces = [MediaType.APPLICATION_JSON_VALUE],
196 .MULTIPART_FORM_DATA_VALUE
200 @Throws(BluePrintException::class)
201 @PreAuthorize("hasRole('USER')")
202 suspend fun enrichAndPubishlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = mdcWebCoroutineScope {
203 bluePrintModelHandler.enrichAndPublishBlueprint(file)
206 @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
208 @Throws(BluePrintException::class)
209 @PreAuthorize("hasRole('USER')")
210 suspend fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = mdcWebCoroutineScope {
211 bluePrintModelHandler.publishBlueprint(file)
214 @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
216 @PreAuthorize("hasRole('USER')")
217 suspend fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> =
218 mdcWebCoroutineScope {
219 bluePrintModelHandler.searchBlueprintModels(tags)
222 @DeleteMapping("/name/{name}/version/{version}")
224 value = "Delete a CBA",
225 notes = "Delete the CBA package identified by its name and version.",
226 nickname = "BlueprintModelController_deleteBlueprint_1_DELETE.org.onap.ccsdk.cds.blueprintsprocessor.designer.api",
227 produces = MediaType.APPLICATION_JSON_VALUE
229 @PreAuthorize("hasRole('USER')")
230 suspend fun deleteBlueprint(
231 @ApiParam(value = "Name of the CBA.", required = true)
232 @PathVariable(value = "name") name: String,
233 @ApiParam(value = "Version of the CBA.", required = true)
234 @PathVariable(value = "version") version: String
235 ) = mdcWebCoroutineScope {
236 bluePrintModelHandler.deleteBlueprintModel(name, version)
240 path = arrayOf("/workflow-spec"),
243 .APPLICATION_JSON_VALUE
245 consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)
248 @Throws(BluePrintException::class)
249 @PreAuthorize("hasRole('USER')")
250 suspend fun workflowSpec(@RequestBody workFlowSpecReq: WorkFlowSpecRequest):
251 ResponseEntity<String> = mdcWebCoroutineScope {
252 var json = bluePrintModelHandler.prepareWorkFlowSpec(workFlowSpecReq)
254 ResponseEntity(json, HttpStatus.OK)
259 "/workflows/blueprint-name/{name}/version/{version" +
262 produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)
265 @Throws(BluePrintException::class)
266 @PreAuthorize("hasRole('USER')")
267 suspend fun getWorkflowList(
268 @ApiParam(value = "Name of the CBA.", required = true)
269 @PathVariable(value = "name") name: String,
270 @ApiParam(value = "Version of the CBA.", required = true)
271 @PathVariable(value = "version") version: String
272 ): ResponseEntity<String> = mdcWebCoroutineScope {
273 var json = bluePrintModelHandler.getWorkflowNames(name, version)
275 ResponseEntity(json, HttpStatus.OK)