2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright 2018 - 2019 Nokia
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.vid.controller;
24 import java.util.Collection;
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.asdc.beans.Service;
30 import org.onap.vid.exceptions.VidServiceUnavailableException;
31 import org.onap.vid.model.PombaInstance.PombaRequest;
32 import org.onap.vid.model.ServiceModel;
33 import org.onap.vid.roles.Role;
34 import org.onap.vid.roles.RoleProvider;
35 import org.onap.vid.services.AaiService;
36 import org.onap.vid.services.InstantiationTemplatesService;
37 import org.onap.vid.services.PombaService;
38 import org.onap.vid.services.VidService;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.http.HttpStatus;
41 import org.springframework.web.bind.annotation.*;
42 import org.springframework.web.servlet.ModelAndView;
44 import javax.servlet.http.HttpServletRequest;
45 import java.util.List;
48 public class VidController extends RestrictedBaseController {
50 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class);
52 private final VidService vidService;
53 private final AaiService aaiService;
54 private final RoleProvider roleProvider;
55 private final PombaService pombaService;
56 private final InstantiationTemplatesService instantiationTemplatesService;
59 public VidController(VidService vidService, AaiService aaiService, RoleProvider roleProvider,
60 PombaService pombaService, InstantiationTemplatesService instantiationTemplatesService) {
61 this.vidService = vidService;
62 this.aaiService = aaiService;
63 this.roleProvider = roleProvider;
64 this.pombaService = pombaService;
65 this.instantiationTemplatesService = instantiationTemplatesService;
69 * @param request the request
70 * @return the services
72 @RequestMapping(value = {"/rest/models/services"}, method = RequestMethod.GET)
73 public SecureServices getServices(HttpServletRequest request) {
74 LOG.info("Start API for browse SDC was called");
75 SecureServices secureServices = new SecureServices();
76 List<Role> roles = roleProvider.getUserRoles(request);
78 Collection<Service> servicesByDistributionStatus = aaiService.getServicesByDistributionStatus();
80 Collection<Service> servicesWithTemplatesIndication =
81 instantiationTemplatesService.setOnEachServiceIsTemplateExists(servicesByDistributionStatus);
83 secureServices.setServices(servicesWithTemplatesIndication);
84 secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles));
86 return secureServices;
91 * @param uuid the uuid
92 * @return the services
93 * @throws VidServiceUnavailableException the vid service unavailable exception
95 @RequestMapping(value = {"/rest/models/services/{uuid}"}, method = RequestMethod.GET)
96 public ServiceModel getService(@PathVariable("uuid") String uuid) throws VidServiceUnavailableException {
98 return vidService.getService(uuid);
99 } catch (AsdcCatalogException e) {
100 LOG.error("Failed to retrieve service definitions from SDC. Error: " + e.getMessage(), e);
101 throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
105 @RequestMapping(value = "/rest/models/reset", method = RequestMethod.POST)
106 @ResponseStatus(HttpStatus.ACCEPTED)
107 public void invalidateServiceModelCache() {
108 vidService.invalidateServiceCache();
112 * @return the services view
113 * @throws VidServiceUnavailableException the vid service unavailable exception
115 // FIX ME: Circular view path [serviceModels]: would dispatch back to the current handler URL [/serviceModels] again.
116 @RequestMapping(value = {"/serviceModels"}, method = RequestMethod.GET)
117 public ModelAndView getServicesView() {
118 return new ModelAndView("serviceModels");
121 @RequestMapping(value = {"/rest/models/services/verifyService"}, method = RequestMethod.POST)
122 public void verifyServiceInstance(@RequestBody PombaRequest pombaRequest) {
123 pombaService.verify(pombaRequest);