2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.controllerblueprints.service.rs;
\r
19 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
\r
20 import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService;
\r
21 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;
\r
22 import org.springframework.http.MediaType;
\r
23 import org.springframework.web.bind.annotation.*;
\r
25 import java.util.List;
\r
31 @RequestMapping(value = "/api/v1/config-model")
\r
32 public class ConfigModelRest {
\r
34 private ConfigModelService configModelService;
\r
37 * This is a ConfigModelRest constructor.
\r
39 * @param configModelService Config Model Service
\r
41 public ConfigModelRest(ConfigModelService configModelService) {
\r
42 this.configModelService = configModelService;
\r
46 @GetMapping(path = "/initial/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
47 public @ResponseBody
\r
48 ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException {
\r
50 return this.configModelService.getInitialConfigModel(name);
\r
51 } catch (Exception e) {
\r
52 throw new BluePrintException(2000, e.getMessage(), e);
\r
56 @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
\r
57 public @ResponseBody
\r
58 ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException {
\r
60 return this.configModelService.saveConfigModel(configModel);
\r
61 } catch (Exception e) {
\r
62 throw new BluePrintException(2200, e.getMessage(), e);
\r
66 @DeleteMapping(path = "/{id}")
\r
67 public void deleteConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {
\r
69 this.configModelService.deleteConfigModel(id);
\r
70 } catch (Exception e) {
\r
71 throw new BluePrintException(2400, e.getMessage(), e);
\r
75 @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
76 public @ResponseBody
\r
77 ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {
\r
79 return this.configModelService.publishConfigModel(id);
\r
80 } catch (Exception e) {
\r
81 throw new BluePrintException(2500, e.getMessage(), e);
\r
85 @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
86 public @ResponseBody
\r
87 ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {
\r
89 return this.configModelService.getConfigModel(id);
\r
90 } catch (Exception e) {
\r
91 throw new BluePrintException(2001, e.getMessage(), e);
\r
95 @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
96 public @ResponseBody
\r
97 ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name,
\r
98 @PathVariable(value = "version") String version) throws BluePrintException {
\r
100 return this.configModelService.getConfigModelByNameAndVersion(name, version);
\r
101 } catch (Exception e) {
\r
102 throw new BluePrintException(2002, e.getMessage(), e);
\r
106 @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
107 public @ResponseBody
\r
108 List<ConfigModel> searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException {
\r
110 return this.configModelService.searchConfigModels(tags);
\r
111 } catch (Exception e) {
\r
112 throw new BluePrintException(2003, e.getMessage(), e);
\r
116 @GetMapping(path = "/clone/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
117 public @ResponseBody
\r
118 ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {
\r
120 return this.configModelService.getCloneConfigModel(id);
\r
121 } catch (Exception e) {
\r
122 throw new BluePrintException(2004, e.getMessage(), e);
\r