Merge from ECOMP's repository
[vid.git] / vid-app-common / src / main / java / org / onap / vid / controller / AaiController2.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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  */
20
21 package org.onap.vid.controller;
22
23 import org.onap.vid.aai.AaiClientInterface;
24 import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
25 import org.onap.vid.aai.model.Permissions;
26 import org.onap.vid.model.aaiTree.RelatedVnf;
27 import org.onap.vid.roles.RoleProvider;
28 import org.onap.vid.services.AaiService;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.http.HttpStatus;
31 import org.springframework.http.MediaType;
32 import org.springframework.web.bind.annotation.*;
33
34 import javax.servlet.http.HttpServletRequest;
35 import java.util.List;
36
37 /**
38  * Controller to handle a&ai new requests.
39  */
40
41 @RestController
42 public class AaiController2 extends VidRestrictedBaseController {
43
44     private final AaiService aaiService;
45     private final RoleProvider roleProvider;
46     private final AaiClientInterface aaiClient;
47
48     @Autowired
49     public AaiController2(AaiService aaiService, RoleProvider roleProvider, AaiClientInterface aaiClient) {
50         this.aaiService = aaiService;
51         this.roleProvider = roleProvider;
52         this.aaiClient = aaiClient;
53     }
54
55     @RequestMapping(value = "/aai_get_homing_by_vfmodule/{vnfInstanceId}/{vfModuleId}", method = RequestMethod.GET)
56     public GetTenantsResponse getHomingDataByVfModule(@PathVariable("vnfInstanceId") String vnfInstanceId,
57                                                       @PathVariable("vfModuleId") String vfModuleId){
58         return aaiService.getHomingDataByVfModule(vnfInstanceId, vfModuleId);
59     }
60
61     @RequestMapping(value = "/aai_get_service_instance_topology/{subscriberId}/{serviceType}/{serviceInstanceId}",
62             method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
63     public String getServiceInstanceTree(@PathVariable("subscriberId") String globalCustomerId,
64                                          @PathVariable("serviceType") String serviceInstanceType,
65                                          @PathVariable("serviceInstanceId") String serviceInstanceId) {
66         return aaiService.getAAIServiceTree(globalCustomerId, serviceInstanceType, serviceInstanceId);
67     }
68
69     @RequestMapping(value = "/aai_reset_cache/{cacheName}", method = RequestMethod.DELETE)
70     @ResponseStatus(HttpStatus.ACCEPTED)
71     public void resetCache(@PathVariable("cacheName") String cacheName) {
72         aaiClient.resetCache(cacheName);
73     }
74
75     @RequestMapping(value = "/roles/service_permissions", method = RequestMethod.GET)
76     public Permissions servicePermissions(HttpServletRequest request,
77                                           @RequestParam(value = "subscriberId") String subscriberId,
78                                           @RequestParam(value = "serviceType") String serviceType) {
79
80         final boolean isEditPermitted = roleProvider
81                 .getUserRolesValidator(request)
82                 .isServicePermitted(subscriberId, serviceType);
83
84         return new Permissions(isEditPermitted);
85     }
86
87     @RequestMapping(value = "/aai_search_group_members",
88             method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
89     public List<RelatedVnf> searchGroupMembers(@RequestParam("subscriberId") String globalCustomerId,
90                                                @RequestParam("serviceType") String serviceType,
91                                                @RequestParam("serviceInvariantId") String invariantId,
92                                                @RequestParam("groupType") String groupType,
93                                                @RequestParam("groupRole") String groupRole) {
94         return aaiService.searchGroupMembers(globalCustomerId, serviceType, invariantId, groupType, groupRole);
95     }
96
97
98 }