2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2019 Bell Canada.
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
18 package org.onap.ccsdk.apps.controllerblueprints.service.rs;
\r
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
\r
21 import org.onap.ccsdk.apps.controllerblueprints.service.BlueprintModelService;
\r
22 import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch;
\r
23 import org.springframework.beans.factory.annotation.Autowired;
\r
24 import org.springframework.core.io.Resource;
\r
25 import org.springframework.http.MediaType;
\r
26 import org.springframework.http.ResponseEntity;
\r
27 import org.springframework.http.codec.multipart.FilePart;
\r
28 import org.springframework.web.bind.annotation.*;
\r
29 import reactor.core.publisher.Mono;
\r
31 import java.util.List;
\r
37 @RequestMapping(value = "/api/v1/blueprint-model")
\r
38 public class BlueprintModelRest {
\r
41 private BlueprintModelService blueprintModelService;
\r
43 @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
\r
44 public @ResponseBody
\r
45 Mono<BlueprintModelSearch> saveBlueprint(@RequestPart("file") FilePart file) throws BluePrintException{
\r
46 return blueprintModelService.saveBlueprintModel(file);
\r
49 @DeleteMapping(path = "/{id}")
\r
50 public void deleteBlueprint(@PathVariable(value = "id") String id) throws BluePrintException {
\r
51 this.blueprintModelService.deleteBlueprintModel(id);
\r
54 @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
55 public @ResponseBody
\r
56 BlueprintModelSearch getBlueprintByNameAndVersion(@PathVariable(value = "name") String name,
\r
57 @PathVariable(value = "version") String version) throws BluePrintException {
\r
58 return this.blueprintModelService.getBlueprintModelSearchByNameAndVersion(name, version);
\r
61 @GetMapping(path = "/download/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
62 public @ResponseBody
\r
63 ResponseEntity<Resource> downloadBlueprintByNameAndVersion(@PathVariable(value = "name") String name,
\r
64 @PathVariable(value = "version") String version) throws BluePrintException {
\r
65 return this.blueprintModelService.downloadBlueprintModelFileByNameAndVersion(name, version);
\r
68 @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
69 public @ResponseBody
\r
70 BlueprintModelSearch getBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException {
\r
71 return this.blueprintModelService.getBlueprintModelSearch(id);
\r
74 @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE)
\r
75 public @ResponseBody
\r
76 List<BlueprintModelSearch> getAllBlueprintModel() {
\r
77 return this.blueprintModelService.getAllBlueprintModel();
\r
80 @GetMapping(path = "/download/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
81 public @ResponseBody
\r
82 ResponseEntity<Resource> downloadBluePrint(@PathVariable(value = "id") String id) throws BluePrintException {
\r
83 return this.blueprintModelService.downloadBlueprintModelFile(id);
\r
86 @PutMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
87 public @ResponseBody
\r
88 BlueprintModelSearch publishBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException {
\r
89 return this.blueprintModelService.publishBlueprintModel(id);
\r
92 @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE)
\r
93 public @ResponseBody
\r
94 List<BlueprintModelSearch> searchBlueprintModels(@PathVariable(value = "tags") String tags) {
\r
95 return this.blueprintModelService.searchBlueprintModels(tags);
\r