2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.vid.controller;
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.*;
34 import javax.servlet.http.HttpServletRequest;
35 import java.util.List;
38 * Controller to handle a&ai new requests.
42 public class AaiController2 extends VidRestrictedBaseController {
44 private final AaiService aaiService;
45 private final RoleProvider roleProvider;
46 private final AaiClientInterface aaiClient;
49 public AaiController2(AaiService aaiService, RoleProvider roleProvider, AaiClientInterface aaiClient) {
50 this.aaiService = aaiService;
51 this.roleProvider = roleProvider;
52 this.aaiClient = aaiClient;
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);
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);
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);
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) {
80 final boolean isEditPermitted = roleProvider
81 .getUserRolesValidator(request)
82 .isServicePermitted(subscriberId, serviceType);
84 return new Permissions(isEditPermitted);
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);