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.controllers;
23 import org.onap.vid.asdc.AsdcCatalogException;
24 import org.onap.vid.asdc.beans.SecureServices;
25 import org.onap.vid.exceptions.VidServiceUnavailableException;
26 import org.onap.vid.model.PombaInstance.PombaRequest;
27 import org.onap.vid.model.ServiceModel;
28 import org.onap.vid.roles.Role;
29 import org.onap.vid.roles.RoleProvider;
30 import org.onap.vid.services.AaiService;
31 import org.onap.vid.services.PombaService;
32 import org.onap.vid.services.VidService;
33 import org.onap.portalsdk.core.controller.RestrictedBaseController;
34 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.web.bind.annotation.*;
38 import org.springframework.web.servlet.ModelAndView;
40 import javax.servlet.http.HttpServletRequest;
41 import java.util.List;
43 //import org.onap.vid.model.Service;
46 public class VidController extends RestrictedBaseController {
48 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class);
50 private final VidService service;
53 public VidController(VidService vidService) {
58 private AaiService aaiService;
61 RoleProvider roleProvider;
64 private PombaService pombaService;
67 // * Gets the services.
69 // * @param request the request
70 // * @return the services
71 // * @throws VidServiceUnavailableException the vid service unavailable exception
73 // @RequestMapping(value={"/rest/models/services"}, method = RequestMethod.GET)
74 // public SecureServices getServices(HttpServletRequest request) throws VidServiceUnavailableException {
76 // AaiService aaiService = new AaiServiceImpl();
77 // LOG.info("Start API for browse ASDC was called");
78 // SecureServices secureServices = new SecureServices();
79 // Map<String, String[]> requestParams = request.getParameterMap();
80 // List<Role> roles = roleProvider.getUserRoles(request);
81 // secureServices.setServices(aaiService.getServicesByDistributionStatus());
82 // secureServices.setServices(service.getServices(requestParams));
83 // secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles));
84 // return secureServices;
85 // } catch (AsdcCatalogException e) {
86 // LOG.error("Failed to retrieve service definitions from SDC", e);
87 // throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
88 // } catch (Throwable t) {
89 // LOG.debug("Unexpected error while retrieving service definitions from SDC: " + t.getMessage() + ":", t);
90 // t.printStackTrace();
91 // throw new VidServiceUnavailableException("Unexpected error while retrieving service definitions from SDC: " + t.getMessage(), t);
98 * @param request the request
99 * @return the services
100 * @throws VidServiceUnavailableException the vid service unavailable exception
102 @RequestMapping(value={"/rest/models/services"}, method = RequestMethod.GET)
103 public SecureServices getServices(HttpServletRequest request) throws VidServiceUnavailableException {
105 LOG.info("Start API for browse ASDC was called");
106 SecureServices secureServices = new SecureServices();
107 List<Role> roles = roleProvider.getUserRoles(request);
108 secureServices.setServices(aaiService.getServicesByDistributionStatus());
109 //Disable roles until AAF integration finishes
110 //secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles));
111 secureServices.setReadOnly(false);
112 return secureServices;
114 catch (Exception t) {
115 LOG.debug("Unexpected error while retrieving service definitions from A&AI: " + t.getMessage() + ":", t);
116 throw new VidServiceUnavailableException("Unexpected error while retrieving service definitions from A&AI: " + t.getMessage(), t);
125 * @param uuid the uuid
126 * @return the services
127 * @throws VidServiceUnavailableException the vid service unavailable exception
129 @RequestMapping(value={"/rest/models/services/{uuid}"}, method = RequestMethod.GET)
130 public ServiceModel getServices(@PathVariable("uuid") String uuid, HttpServletRequest request) throws VidServiceUnavailableException {
132 return service.getService(uuid);
133 } catch (AsdcCatalogException e) {
134 LOG.error("Failed to retrieve service definitions from SDC. Error: "+e.getMessage() , e);
135 throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
139 @RequestMapping(value = "/rest/models/reset", method = RequestMethod.POST)
140 @ResponseStatus(HttpStatus.ACCEPTED)
141 public void invalidateServiceModelCache(HttpServletRequest request) {
142 service.invalidateServiceCache();
146 * Gets the services view.
148 * @param request the request
149 * @return the services view
150 * @throws VidServiceUnavailableException the vid service unavailable exception
152 @RequestMapping(value={"/serviceModels"}, method=RequestMethod.GET)
153 public ModelAndView getServicesView(HttpServletRequest request) {
154 return new ModelAndView("serviceModels");
157 @RequestMapping(value = {"/rest/models/services/verifyService"}, method = RequestMethod.POST)
158 public void verifyServiceInstance(HttpServletRequest request, @RequestBody PombaRequest pombaRequest) {
159 pombaService.verify(pombaRequest);