Upgrade sonar plugin
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / controller / VidController.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * VID\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.vid.controller;\r
22 \r
23 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;\r
24 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
25 import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;\r
26 import org.openecomp.vid.asdc.AsdcCatalogException;\r
27 import org.openecomp.vid.asdc.beans.SecureServices;\r
28 import org.openecomp.vid.exceptions.VidServiceUnavailableException;\r
29 import org.openecomp.vid.model.ServiceModel;\r
30 import org.openecomp.vid.roles.Role;\r
31 import org.openecomp.vid.roles.RoleProvider;\r
32 import org.openecomp.vid.roles.RoleValidator;\r
33 import org.openecomp.vid.services.VidService;\r
34 import org.springframework.beans.factory.annotation.Autowired;\r
35 import org.springframework.web.bind.annotation.PathVariable;\r
36 import org.springframework.web.bind.annotation.RequestMapping;\r
37 import org.springframework.web.bind.annotation.RequestMethod;\r
38 import org.springframework.web.bind.annotation.RestController;\r
39 import org.springframework.web.servlet.ModelAndView;\r
40 \r
41 import javax.servlet.http.HttpServletRequest;\r
42 import java.util.List;\r
43 import java.util.Map;\r
44 \r
45 //import org.openecomp.vid.model.Service;\r
46 \r
47 @RestController\r
48 public class VidController extends RestrictedBaseController {\r
49         \r
50         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class);\r
51 \r
52         private final VidService service;\r
53 \r
54         @Autowired\r
55         public VidController(VidService vidService) throws SdcToscaParserException{\r
56 \r
57                 service = vidService;\r
58         }\r
59 //      \r
60         /**\r
61          * Gets the services.\r
62          *\r
63          * @param request the request\r
64          * @return the services\r
65          * @throws VidServiceUnavailableException the vid service unavailable exception\r
66          */\r
67         @RequestMapping(value={"/rest/models/services"}, method = RequestMethod.GET)\r
68         public SecureServices getServices(HttpServletRequest request) throws VidServiceUnavailableException {\r
69                 try {\r
70                         LOG.info("Start API for browse ASDC was called");\r
71                         SecureServices secureServices = new SecureServices();\r
72                         RoleProvider roleProvider = new RoleProvider();\r
73                         Map<String, String[]> requestParams = request.getParameterMap();\r
74                         List<Role> roles = new RoleProvider().getUserRoles(request);\r
75                         secureServices.setServices(service.getServices(requestParams));\r
76                         //Disable roles until AAF integration finishes\r
77                         //secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles));\r
78                         return secureServices;\r
79                 } catch (AsdcCatalogException e) {\r
80                         LOG.error("Failed to retrieve service definitions from SDC", e);\r
81                         throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);\r
82                 } catch (Throwable t) {\r
83                         LOG.debug("Unexpected error while retrieving service definitions from SDC: " + t.getMessage() + ":", t);\r
84                         t.printStackTrace();\r
85                         throw new VidServiceUnavailableException("Unexpected error while retrieving service definitions from SDC: " + t.getMessage(), t);\r
86                 }\r
87         }\r
88         \r
89         /**\r
90          * Gets the services.\r
91          *\r
92          * @param uuid the uuid\r
93          * @return the services\r
94          * @throws VidServiceUnavailableException the vid service unavailable exception\r
95          */\r
96         @RequestMapping(value={"/rest/models/services/{uuid}"}, method = RequestMethod.GET)\r
97         public ServiceModel getServices(@PathVariable("uuid") String uuid, HttpServletRequest request) throws VidServiceUnavailableException {\r
98                 try {\r
99 //                      RoleValidator roleValidator = new RoleValidator(new RoleProvider().getUserRoles(request));\r
100                         return service.getService(uuid);\r
101                 } catch (AsdcCatalogException e) {\r
102                         LOG.error("Failed to retrieve service definitions from SDC", e);\r
103                         throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);\r
104                 }\r
105         }\r
106 \r
107 \r
108         /**\r
109          * Gets the services view.\r
110          *\r
111          * @param request the request\r
112          * @return the services view\r
113          * @throws VidServiceUnavailableException the vid service unavailable exception\r
114          */\r
115         @RequestMapping(value={"/serviceModels"}, method=RequestMethod.GET)\r
116         public ModelAndView getServicesView(HttpServletRequest request) throws VidServiceUnavailableException {\r
117                 return new ModelAndView("serviceModels");\r
118         }\r
119 }\r