3651ec863ac227288d0e835716ef0346a92ba8c2
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / servicecatalog / ServiceSpecificationResource.java
1 /**
2  *     Copyright (c) 2018 Orange
3  *
4  *     Licensed under the Apache License, Version 2.0 (the "License");
5  *     you may not use this file except in compliance with the License.
6  *     You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *     Unless required by applicable law or agreed to in writing, software
11  *     distributed under the License is distributed on an "AS IS" BASIS,
12  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *     See the License for the specific language governing permissions and
14  *     limitations under the License.
15  */
16
17 package org.onap.nbi.apis.servicecatalog;
18
19 import java.util.LinkedHashMap;
20 import java.util.List;
21 import java.util.Map;
22 import org.onap.nbi.OnapComponentsUrlPaths;
23 import org.onap.nbi.commons.JsonRepresentation;
24 import org.onap.nbi.commons.ResourceManagement;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.http.MediaType;
27 import org.springframework.http.ResponseEntity;
28 import org.springframework.util.MultiValueMap;
29 import org.springframework.web.bind.annotation.GetMapping;
30 import org.springframework.web.bind.annotation.PathVariable;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.bind.annotation.RequestParam;
33 import org.springframework.web.bind.annotation.RestController;
34
35 @RestController
36 @RequestMapping(OnapComponentsUrlPaths.SERVICE_SPECIFICATION_PATH)
37 public class ServiceSpecificationResource extends ResourceManagement {
38
39     @Autowired
40     ServiceSpecificationService serviceSpecificationService;
41
42     @GetMapping(value = "/{serviceSpecId}", produces = MediaType.APPLICATION_JSON_VALUE)
43     public ResponseEntity<Object> getServiceSpecification(@PathVariable String serviceSpecId,
44             @RequestParam MultiValueMap<String, String> params) {
45         Map response = serviceSpecificationService.get(serviceSpecId);
46         JsonRepresentation filter = new JsonRepresentation(params);
47         if (response.get("serviceSpecCharacteristic") != null) {
48             return this.getResponse(response, filter);
49         } else {
50             return this.getPartialResponse(response, filter);
51
52         }
53     }
54
55     @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
56     public ResponseEntity<Object> findServiceSpecification(@RequestParam MultiValueMap<String, String> params) {
57         List<LinkedHashMap> response = serviceSpecificationService.find(params);
58         JsonRepresentation filter = new JsonRepresentation(params);
59         return this.findResponse(response, filter, null);
60     }
61
62     @GetMapping(value = "/{serviceSpecId}/specificationInputSchema", produces = MediaType.APPLICATION_JSON_VALUE)
63     public ResponseEntity<Object> findSpecificationInputSchema(@PathVariable String serviceSpecId,
64             @RequestParam MultiValueMap<String, String> params) {
65         String response = serviceSpecificationService.getInputSchema(serviceSpecId);
66         JsonRepresentation filter = new JsonRepresentation(params);
67         return this.getResponse(response, filter);
68     }
69
70 }