blob: cf6e6cb9f89fada8f32fc98e0385d6150d4867c9 [file] [log] [blame]
Aharoni, Pavel (pa0916)0a8080c2018-11-22 15:45:19 +02001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20package org.onap.osam.controllers;
21
22
23import org.springframework.beans.factory.annotation.Autowired;
24import org.springframework.core.ParameterizedTypeReference;
25import org.springframework.http.HttpEntity;
26import org.springframework.http.HttpMethod;
27import org.springframework.http.ResponseEntity;
28import org.springframework.web.bind.annotation.*;
29import org.springframework.web.client.RestTemplate;
30
31import java.util.List;
32
33// TODO log
34@RestController
35@RequestMapping("service")
36
37// *** Return and request types should be in osam-common. Types such as SpeedProfile, TechnologyProfile that are under model.dao temporarily reduced to Object *** //
38public class OnapEnablerServiceController extends OnapEnablerController {
39
40 private static final String SERVICE = "service";
41 private static final String SPEED_PROFILE = "speedProfile";
42 private static final String SPEED_PROFILE_ID = "speedProfile/{id}";
43 private static final String TECH_PROFILE = "technologyProfile";
44 private static final String TECH_PROFILE_ID = "technologyProfile/{id}";
45
46 @Autowired
47 public OnapEnablerServiceController(RestTemplate restTemplate){
48 this.restTemplate = restTemplate;
49 }
50
51 @RequestMapping(method = RequestMethod.GET, value = SPEED_PROFILE)
52 public ResponseEntity<List</*SpeedProfile*/Object>> getSpeedProfiles() {
53 return restTemplate.exchange(buildRequestPath(SERVICE, SPEED_PROFILE), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<List</*SpeedProfile*/Object>>(){});
54 }
55
56 @RequestMapping(method = RequestMethod.GET, value = SPEED_PROFILE_ID)
57 public ResponseEntity</*SpeedProfile*/Object> getSpeedProfile(@PathVariable Long id) {
58 return restTemplate.getForEntity(buildRequestPath(SERVICE, SPEED_PROFILE, String.valueOf(id)), /*SpeedProfile*/Object.class);
59 }
60
61 @RequestMapping(method = RequestMethod.DELETE, value = SPEED_PROFILE_ID)
62 public void deleteSpeedProfile(@PathVariable Long id) {
63 restTemplate.delete(buildRequestPath(SERVICE, SPEED_PROFILE, String.valueOf(id)));
64 }
65
66 @RequestMapping(method = RequestMethod.POST, value = SPEED_PROFILE)
67 public ResponseEntity</*SpeedProfile*/Object> createSpeedProfile(@RequestBody /*SpeedProfile*/ Object speedProfile) {
68 return restTemplate.postForEntity(buildRequestPath(SERVICE, SPEED_PROFILE), speedProfile, /*SpeedProfile*/Object.class);
69 }
70
71 @RequestMapping(method = RequestMethod.GET, value = TECH_PROFILE)
72 public ResponseEntity<List</*TechnologyProfile*/Object>> getTechnologyProfiles() {
73 return restTemplate.exchange(buildRequestPath(SERVICE, TECH_PROFILE), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<List</*TechnologyProfile*/Object>>(){});
74 }
75
76 @RequestMapping(method = RequestMethod.GET, value = TECH_PROFILE_ID)
77 public ResponseEntity</*TechnologyProfile*/Object> getTechnologyProfile(@PathVariable Long id) {
78 return restTemplate.getForEntity(buildRequestPath(SERVICE, TECH_PROFILE, String.valueOf(id)), /*TechnologyProfile*/Object.class);
79 }
80
81 @RequestMapping(method = RequestMethod.DELETE, value = TECH_PROFILE_ID)
82 public void deleteTechnologyProfile(@PathVariable Long id) {
83 restTemplate.delete(buildRequestPath(SERVICE, TECH_PROFILE, String.valueOf(id)));
84 }
85
86 @RequestMapping(method = RequestMethod.POST, value = TECH_PROFILE)
87 public ResponseEntity</*TechnologyProfile*/Object> createTechnologyProfile(@RequestBody /*TechnologyProfile*/ Object technologyProfile) {
88 return restTemplate.postForEntity(buildRequestPath(SERVICE, TECH_PROFILE), technologyProfile, /*TechnologyProfile*/Object.class);
89 }
90}