Preparing the request payload for calling SO macro flow.
[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.ArrayList;
20 import java.util.LinkedHashMap;
21 import java.util.List;
22 import java.util.Map;
23 import org.onap.nbi.OnapComponentsUrlPaths;
24 import org.onap.nbi.commons.JsonRepresentation;
25 import org.onap.nbi.commons.ResourceManagement;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.http.MediaType;
28 import org.springframework.http.ResponseEntity;
29 import org.springframework.util.MultiValueMap;
30 import org.springframework.web.bind.annotation.GetMapping;
31 import org.springframework.web.bind.annotation.PathVariable;
32 import org.springframework.web.bind.annotation.RequestMapping;
33 import org.springframework.web.bind.annotation.RequestParam;
34 import org.springframework.web.bind.annotation.RestController;
35
36 @RestController
37 @RequestMapping(OnapComponentsUrlPaths.SERVICE_SPECIFICATION_PATH)
38 public class ServiceSpecificationResource extends ResourceManagement {
39
40     @Autowired
41     ServiceSpecificationService serviceSpecificationService;
42
43     @GetMapping(value = "/{serviceSpecId}", produces = MediaType.APPLICATION_JSON_VALUE)
44     public ResponseEntity<Object> getServiceSpecification(@PathVariable String serviceSpecId,
45             @RequestParam MultiValueMap<String, String> params) {
46         Map response = serviceSpecificationService.get(serviceSpecId);
47
48         if (response != null) {
49            ArrayList<Map<String, Object>> resourseSpecificationMap= (ArrayList<Map<String, Object>>) response.get("resourceSpecification");
50            for (Map<String, Object> map : resourseSpecificationMap) {
51                map.remove("childResourceSpecification");
52                map.remove("InstanceSpecification");
53            }
54            response.put("resourceSpecification", resourseSpecificationMap);
55         }
56
57         JsonRepresentation filter = new JsonRepresentation(params);
58         if (response.get("serviceSpecCharacteristic") != null) {
59             return this.getResponse(response, filter);
60         } else {
61             return this.getPartialResponse(response, filter);
62
63         }
64     }
65
66     @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
67     public ResponseEntity<Object> findServiceSpecification(@RequestParam MultiValueMap<String, String> params) {
68         List<LinkedHashMap> response = serviceSpecificationService.find(params);
69         JsonRepresentation filter = new JsonRepresentation(params);
70         return this.findResponse(response, filter, null);
71     }
72
73     @GetMapping(value = "/{serviceSpecId}/specificationInputSchema", produces = MediaType.APPLICATION_JSON_VALUE)
74     public ResponseEntity<Object> findSpecificationInputSchema(@PathVariable String serviceSpecId,
75             @RequestParam MultiValueMap<String, String> params) {
76         String response = serviceSpecificationService.getInputSchema(serviceSpecId);
77         JsonRepresentation filter = new JsonRepresentation(params);
78         return this.getResponse(response, filter);
79     }
80
81 }