512b088d9da29d3c477833a5a54e740d6d16ceb5
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / servicecatalog / ServiceSpecificationResource.java
1 package org.onap.nbi.apis.servicecatalog;
2
3 import java.util.LinkedHashMap;
4 import java.util.List;
5 import org.onap.nbi.commons.JsonRepresentation;
6 import org.onap.nbi.commons.Resource;
7 import org.onap.nbi.commons.ResourceManagement;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.http.MediaType;
10 import org.springframework.http.ResponseEntity;
11 import org.springframework.util.MultiValueMap;
12 import org.springframework.web.bind.annotation.GetMapping;
13 import org.springframework.web.bind.annotation.PathVariable;
14 import org.springframework.web.bind.annotation.RequestMapping;
15 import org.springframework.web.bind.annotation.RequestParam;
16 import org.springframework.web.bind.annotation.RestController;
17
18 @RestController
19 @RequestMapping("/serviceSpecification")
20 public class ServiceSpecificationResource extends ResourceManagement<Resource> {
21
22
23     @Autowired
24     ServiceSpecificationService serviceSpecificationService;
25
26     @GetMapping(value = "/{serviceSpecId}", produces = MediaType.APPLICATION_JSON_VALUE)
27     public ResponseEntity<Object> getServiceSpecification(@PathVariable String serviceSpecId,
28             @RequestParam MultiValueMap<String, String> params) {
29         LinkedHashMap response = serviceSpecificationService.get(serviceSpecId);
30         JsonRepresentation filter = new JsonRepresentation(params);
31         if (response.get("serviceSpecCharacteristic") != null) {
32             return this.getResponse(response, filter);
33         } else {
34             return this.getPartialResponse(response, filter);
35
36         }
37     }
38
39     @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
40     public ResponseEntity<Object> findServiceSpecification(@RequestParam MultiValueMap<String, String> params) {
41         List<LinkedHashMap> response = serviceSpecificationService.find(params);
42         JsonRepresentation filter = new JsonRepresentation(params);
43         return this.findResponse(response, filter, null);
44     }
45
46 }