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.controller;
25 import org.onap.portalsdk.core.controller.RestrictedBaseController;
26 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
27 import org.onap.vid.asdc.AsdcCatalogException;
28 import org.onap.vid.asdc.beans.SecureServices;
29 import org.onap.vid.exceptions.VidServiceUnavailableException;
30 import org.onap.vid.model.PombaInstance.PombaRequest;
31 import org.onap.vid.model.ServiceModel;
32 import org.onap.vid.roles.Role;
33 import org.onap.vid.roles.RoleProvider;
34 import org.onap.vid.services.AaiService;
35 import org.onap.vid.services.PombaService;
36 import org.onap.vid.services.VidService;
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 secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles));
75 return secureServices;
80 * @param uuid the uuid
81 * @return the services
82 * @throws VidServiceUnavailableException the vid service unavailable exception
84 @RequestMapping(value = {"/rest/models/services/{uuid}"}, method = RequestMethod.GET)
85 public ServiceModel getService(@PathVariable("uuid") String uuid) throws VidServiceUnavailableException {
87 return vidService.getService(uuid);
88 } catch (AsdcCatalogException e) {
89 LOG.error("Failed to retrieve service definitions from SDC. Error: " + e.getMessage(), e);
90 throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
94 @RequestMapping(value = "/rest/models/reset", method = RequestMethod.POST)
95 @ResponseStatus(HttpStatus.ACCEPTED)
96 public void invalidateServiceModelCache() {
97 vidService.invalidateServiceCache();
101 * @return the services view
102 * @throws VidServiceUnavailableException the vid service unavailable exception
104 // FIX ME: Circular view path [serviceModels]: would dispatch back to the current handler URL [/serviceModels] again.
105 @RequestMapping(value = {"/serviceModels"}, method = RequestMethod.GET)
106 public ModelAndView getServicesView() {
107 return new ModelAndView("serviceModels");
110 @RequestMapping(value = {"/rest/models/services/verifyService"}, method = RequestMethod.POST)
111 public void verifyServiceInstance(@RequestBody PombaRequest pombaRequest) {
112 pombaService.verify(pombaRequest);