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.portalsdk.core.controller.RestrictedBaseController;
24 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
25 import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
26 import org.onap.vid.asdc.AsdcCatalogException;
27 import org.onap.vid.asdc.beans.SecureServices;
28 import org.onap.vid.exceptions.VidServiceUnavailableException;
29 import org.onap.vid.model.ServiceModel;
30 import org.onap.vid.roles.Role;
31 import org.onap.vid.roles.RoleProvider;
32 import org.onap.vid.services.AaiService;
33 import org.onap.vid.services.VidService;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.web.bind.annotation.PathVariable;
36 import org.springframework.web.bind.annotation.RequestMapping;
37 import org.springframework.web.bind.annotation.RequestMethod;
38 import org.springframework.web.bind.annotation.RestController;
39 import org.springframework.web.servlet.ModelAndView;
41 import javax.servlet.http.HttpServletRequest;
42 import java.util.List;
44 //import org.onap.vid.model.Service;
47 public class VidController extends RestrictedBaseController {
49 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class);
51 private final VidService service;
54 public VidController(VidService vidService) throws SdcToscaParserException{
60 private AaiService aaiService;
63 RoleProvider roleProvider;
66 // * Gets the services.
68 // * @param request the request
69 // * @return the services
70 // * @throws VidServiceUnavailableException the vid service unavailable exception
72 // @RequestMapping(value={"/rest/models/services"}, method = RequestMethod.GET)
73 // public SecureServices getServices(HttpServletRequest request) throws VidServiceUnavailableException {
75 // AaiService aaiService = new AaiServiceImpl();
76 // LOG.info("Start API for browse ASDC was called");
77 // SecureServices secureServices = new SecureServices();
78 // Map<String, String[]> requestParams = request.getParameterMap();
79 // List<Role> roles = roleProvider.getUserRoles(request);
80 // secureServices.setServices(aaiService.getServicesByDistributionStatus());
81 // secureServices.setServices(service.getServices(requestParams));
82 // secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles));
83 // return secureServices;
84 // } catch (AsdcCatalogException e) {
85 // LOG.error("Failed to retrieve service definitions from SDC", e);
86 // throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
87 // } catch (Throwable t) {
88 // LOG.debug("Unexpected error while retrieving service definitions from SDC: " + t.getMessage() + ":", t);
89 // t.printStackTrace();
90 // throw new VidServiceUnavailableException("Unexpected error while retrieving service definitions from SDC: " + t.getMessage(), t);
97 * @param request the request
98 * @return the services
99 * @throws VidServiceUnavailableException the vid service unavailable exception
101 @RequestMapping(value={"/rest/models/services"}, method = RequestMethod.GET)
102 public SecureServices getServices(HttpServletRequest request) throws VidServiceUnavailableException {
104 LOG.info("Start API for browse ASDC was called");
105 SecureServices secureServices = new SecureServices();
106 List<Role> roles = roleProvider.getUserRoles(request);
107 secureServices.setServices(aaiService.getServicesByDistributionStatus());
108 //Disable roles until AAF integration finishes
109 //secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles));
110 secureServices.setReadOnly(false);
111 return secureServices;
113 catch (Exception t) {
114 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", e);
135 throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
141 * Gets the services view.
143 * @param request the request
144 * @return the services view
145 * @throws VidServiceUnavailableException the vid service unavailable exception
147 @RequestMapping(value={"/serviceModels"}, method=RequestMethod.GET)
148 public ModelAndView getServicesView(HttpServletRequest request) throws VidServiceUnavailableException {
149 return new ModelAndView("serviceModels");