341d63bf0a1047fb1e0fe41e36575acdb9214d87
[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.controllerblueprints.service.controller
19
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType
22 import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler
23 import kotlinx.coroutines.runBlocking
24 import org.springframework.http.MediaType
25 import org.springframework.web.bind.annotation.*
26
27 @RestController
28 @RequestMapping(value = arrayOf("/api/v1/model-type"))
29 open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) {
30
31     @GetMapping(path = arrayOf("/{name}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
32     fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = runBlocking {
33         modelTypeHandler.getModelTypeByName(name)
34     }
35
36     @GetMapping(path = arrayOf("/search/{tags}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
37     fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = runBlocking {
38         modelTypeHandler.searchModelTypes(tags)
39     }
40
41     @GetMapping(path = arrayOf("/by-definition/{definitionType}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
42     @ResponseBody
43     fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> = runBlocking {
44         modelTypeHandler.getModelTypeByDefinitionType(definitionType)
45     }
46
47     @PostMapping(path = arrayOf(""), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE))
48     @ResponseBody
49     @Throws(BluePrintException::class)
50     fun saveModelType(@RequestBody modelType: ModelType): ModelType = runBlocking {
51         modelTypeHandler.saveModel(modelType)
52     }
53
54     @DeleteMapping(path = arrayOf("/{name}"))
55     fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = runBlocking {
56         modelTypeHandler.deleteByModelName(name)
57     }
58 }