eda6f961d9f5669e8e75312ab8a582c6424f25a8
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / serviceinventory / ServiceInventoryResource.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 package org.onap.nbi.apis.serviceinventory;
17
18 import java.util.LinkedHashMap;
19 import java.util.List;
20 import java.util.Map;
21 import org.onap.nbi.OnapComponentsUrlPaths;
22 import org.onap.nbi.commons.JsonRepresentation;
23 import org.onap.nbi.commons.ResourceManagement;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.http.MediaType;
26 import org.springframework.http.ResponseEntity;
27 import org.springframework.util.MultiValueMap;
28 import org.springframework.web.bind.annotation.GetMapping;
29 import org.springframework.web.bind.annotation.PathVariable;
30 import org.springframework.web.bind.annotation.RequestMapping;
31 import org.springframework.web.bind.annotation.RequestParam;
32 import org.springframework.web.bind.annotation.RestController;
33
34 @RestController
35 @RequestMapping(OnapComponentsUrlPaths.SERVICE_INVENTORY_PATH)
36 public class ServiceInventoryResource extends ResourceManagement {
37
38     @Autowired
39     ServiceInventoryService serviceInventoryService;
40
41     @GetMapping(value = "/{serviceId}", produces = MediaType.APPLICATION_JSON_VALUE)
42     public ResponseEntity<Object> getServiceInventory(@PathVariable String serviceId,
43             @RequestParam MultiValueMap<String, String> params) {
44
45         Map response = serviceInventoryService.get(serviceId, params);
46
47         JsonRepresentation filter = new JsonRepresentation(params);
48         return this.getResponse(response, filter);
49
50     }
51
52     @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
53     public ResponseEntity<Object> findServiceInventory(@RequestParam MultiValueMap<String, String> params) {
54
55         List<LinkedHashMap> response = serviceInventoryService.find(params);
56         JsonRepresentation filter = new JsonRepresentation(params);
57         return this.findResponse(response, filter, null);
58
59     }
60
61
62 }