2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright 2018 Nokia
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.vid.controllers;
25 import org.onap.vid.asdc.AsdcCatalogException;
26 import org.onap.vid.asdc.beans.SecureServices;
27 import org.onap.vid.exceptions.VidServiceUnavailableException;
28 import org.onap.vid.model.PombaInstance.PombaRequest;
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.PombaService;
34 import org.onap.vid.services.VidService;
35 import org.onap.portalsdk.core.controller.RestrictedBaseController;
36 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.web.bind.annotation.*;
40 import org.springframework.web.servlet.ModelAndView;
42 import javax.servlet.http.HttpServletRequest;
43 import java.util.List;
46 public class VidController extends RestrictedBaseController {
48 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class);
50 private final VidService vidService;
51 private final AaiService aaiService;
52 private final RoleProvider roleProvider;
53 private final PombaService pombaService;
56 public VidController(VidService vidService, AaiService aaiService, RoleProvider roleProvider,
57 PombaService pombaService) {
58 this.vidService = vidService;
59 this.aaiService = aaiService;
60 this.roleProvider = roleProvider;
61 this.pombaService = pombaService;
65 * @param request the request
66 * @return the services
68 @RequestMapping(value = {"/rest/models/services"}, method = RequestMethod.GET)
69 public SecureServices getServices(HttpServletRequest request) {
70 LOG.info("Start API for browse ASDC was called");
71 SecureServices secureServices = new SecureServices();
72 List<Role> roles = roleProvider.getUserRoles(request);
73 secureServices.setServices(aaiService.getServicesByDistributionStatus());
74 //Disable roles until AAF integration finishes
75 //secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles));
76 secureServices.setReadOnly(false);
77 return secureServices;
82 * @param uuid the uuid
83 * @return the services
84 * @throws VidServiceUnavailableException the vid service unavailable exception
86 @RequestMapping(value = {"/rest/models/services/{uuid}"}, method = RequestMethod.GET)
87 public ServiceModel getService(@PathVariable("uuid") String uuid) throws VidServiceUnavailableException {
89 return vidService.getService(uuid);
90 } catch (AsdcCatalogException e) {
91 LOG.error("Failed to retrieve service definitions from SDC. Error: " + e.getMessage(), e);
92 throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
96 @RequestMapping(value = "/rest/models/reset", method = RequestMethod.POST)
97 @ResponseStatus(HttpStatus.ACCEPTED)
98 public void invalidateServiceModelCache() {
99 vidService.invalidateServiceCache();
103 * @return the services view
104 * @throws VidServiceUnavailableException the vid service unavailable exception
106 // FIX ME: Circular view path [serviceModels]: would dispatch back to the current handler URL [/serviceModels] again.
107 @RequestMapping(value = {"/serviceModels"}, method = RequestMethod.GET)
108 public ModelAndView getServicesView() {
109 return new ModelAndView("serviceModels");
112 @RequestMapping(value = {"/rest/models/services/verifyService"}, method = RequestMethod.POST)
113 public void verifyServiceInstance(@RequestBody PombaRequest pombaRequest) {
114 pombaService.verify(pombaRequest);