1c550bb3e18b384f8a2f86eb8172d49f7cf37648
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 IBM.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
19
20 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType
21 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ModelTypeHandler
22 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
24 import org.springframework.http.MediaType
25 import org.springframework.web.bind.annotation.DeleteMapping
26 import org.springframework.web.bind.annotation.GetMapping
27 import org.springframework.web.bind.annotation.PathVariable
28 import org.springframework.web.bind.annotation.PostMapping
29 import org.springframework.web.bind.annotation.RequestBody
30 import org.springframework.web.bind.annotation.RequestMapping
31 import org.springframework.web.bind.annotation.ResponseBody
32 import org.springframework.web.bind.annotation.RestController
33
34 @RestController
35 @RequestMapping(value = ["/api/v1/model-type"])
36 open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) {
37
38     @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
39     suspend fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = mdcWebCoroutineScope {
40         modelTypeHandler.getModelTypeByName(name)
41     }
42
43     @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
44     suspend fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = mdcWebCoroutineScope {
45         modelTypeHandler.searchModelTypes(tags)
46     }
47
48     @GetMapping(path = ["/by-definition/{definitionType}"], produces = [MediaType.APPLICATION_JSON_VALUE])
49     @ResponseBody
50     suspend fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> =
51         mdcWebCoroutineScope {
52             modelTypeHandler.getModelTypeByDefinitionType(definitionType)
53         }
54
55     @PostMapping(
56         path = [""],
57         produces = [MediaType.APPLICATION_JSON_VALUE],
58         consumes = [MediaType.APPLICATION_JSON_VALUE]
59     )
60     @ResponseBody
61     @Throws(BluePrintException::class)
62     suspend fun saveModelType(@RequestBody modelType: ModelType): ModelType = mdcWebCoroutineScope {
63         modelTypeHandler.saveModel(modelType)
64     }
65
66     @DeleteMapping(path = ["/{name}"])
67     suspend fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = mdcWebCoroutineScope {
68         modelTypeHandler.deleteByModelName(name)
69     }
70 }