2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software 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.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
37 package org.onap.portalapp.portal.controller;
39 import java.lang.reflect.InvocationTargetException;
40 import java.lang.reflect.Method;
41 import java.util.ArrayList;
42 import java.util.Arrays;
43 import java.util.Collections;
44 import java.util.HashMap;
45 import java.util.List;
47 import java.util.jar.Attributes;
48 import java.util.regex.Matcher;
49 import java.util.regex.Pattern;
51 import javax.servlet.http.HttpServletRequest;
52 import javax.servlet.http.HttpServletResponse;
54 import org.onap.portalapp.annotation.ApiVersion;
55 import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser;
56 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
57 import org.onap.portalapp.portal.domain.EPUser;
58 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
59 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
60 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
61 import org.onap.portalapp.portal.service.ManifestService;
62 import org.onap.portalapp.portal.transport.Analytics;
63 import org.onap.portalapp.portal.transport.CentralUser;
64 import org.onap.portalapp.portal.transport.CentralV2Role;
65 import org.onap.portalapp.portal.transport.EpNotificationItem;
66 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
67 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
68 import org.onap.portalapp.portal.transport.OnboardingApp;
69 import org.onap.portalsdk.core.domain.Role;
70 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
71 import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
72 import org.onap.portalsdk.core.restful.domain.EcompRole;
73 import org.onap.portalsdk.core.restful.domain.EcompUser;
74 import org.springframework.beans.BeansException;
75 import org.springframework.beans.factory.annotation.Autowired;
76 import org.springframework.context.ApplicationContext;
77 import org.springframework.context.ApplicationContextAware;
78 import org.springframework.context.annotation.EnableAspectJAutoProxy;
79 import org.springframework.web.bind.annotation.PathVariable;
80 import org.springframework.web.bind.annotation.RequestBody;
81 import org.springframework.web.bind.annotation.RequestMapping;
82 import org.springframework.web.bind.annotation.RequestMethod;
83 import org.springframework.web.bind.annotation.RequestParam;
84 import org.springframework.web.bind.annotation.ResponseBody;
85 import org.springframework.web.bind.annotation.RestController;
87 import com.fasterxml.jackson.databind.ObjectMapper;
89 import io.swagger.annotations.ApiOperation;
92 @RequestMapping("/auxapi")
93 @org.springframework.context.annotation.Configuration
94 @EnableAspectJAutoProxy
96 public class AuxApiRequestMapperController implements ApplicationContextAware, BasicAuthenticationController {
98 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AuxApiRequestMapperController.class);
100 ApplicationContext context = null;
101 int minorVersion = 0;
104 private ManifestService manifestService;
106 @ApiOperation(value = "Gets user roles for an application which is upgraded to newer version.", response = String.class, responseContainer = "List")
107 @RequestMapping(value = { "/v3/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
108 public String getUser(HttpServletRequest request, HttpServletResponse response,
109 @PathVariable("loginId") String loginId) throws Exception {
110 Map<String, Object> res = getMethod(request, response);
111 String answer = null;
113 answer = (String) invokeMethod(res, request, response, loginId);
114 } catch (Exception e) {
115 logger.error(EELFLoggerDelegate.errorLogger, "getUser failed", e);
120 @SuppressWarnings("unchecked")
121 @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
122 @RequestMapping(value = { "/v3/roles" }, method = RequestMethod.GET, produces = "application/json")
123 public List<CentralV2Role> getRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
124 Map<String, Object> res = getMethod(request, response);
126 List<CentralV2Role> answer = null;
128 answer = (List<CentralV2Role>) invokeMethod(res, request, response);
129 } catch (Exception e) {
130 logger.error(EELFLoggerDelegate.errorLogger, "getRoles failed", e);
135 @SuppressWarnings("unchecked")
136 @ApiOperation(value = "Saves role for an application.", response = PortalRestResponse.class, responseContainer = "Json")
137 @RequestMapping(value = { "/v3/role" }, method = RequestMethod.POST, produces = "application/json")
138 public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response,
139 @RequestBody Role role) throws Exception {
140 Map<String, Object> res = getMethod(request, response);
141 PortalRestResponse<String> out = null;
143 out = (PortalRestResponse<String>) invokeMethod(res, request, response, role);
144 } catch (Exception e) {
145 logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e);
146 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
151 @ApiOperation(value = "Gets v2 role information for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
152 @RequestMapping(value = { "/v3/role/{role_id}" }, method = RequestMethod.GET, produces = "application/json")
153 public CentralV2Role getRoleInfo(HttpServletRequest request, HttpServletResponse response,
154 @PathVariable("role_id") Long roleId) throws Exception {
155 Map<String, Object> res = getMethod(request, response);
156 CentralV2Role role = null;
158 role = (CentralV2Role) invokeMethod(res, request, response, roleId);
159 } catch (Exception e) {
160 logger.error(EELFLoggerDelegate.errorLogger, "getRoleInfo failed", e);
166 @SuppressWarnings("unchecked")
167 @ApiOperation(value = "Gets all active Users of application", response = String.class, responseContainer = "Json")
168 @RequestMapping(value = { "/v3/users" }, method = RequestMethod.GET, produces = "application/json")
169 public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response)
171 Map<String, Object> res = getMethod(request, response);
172 List<EcompUser> users = null;
174 users = (List<EcompUser>) invokeMethod(res, request, response);
175 } catch (Exception e) {
176 logger.error(EELFLoggerDelegate.errorLogger, "getUsersOfApplication failed", e);
181 @SuppressWarnings("unchecked")
182 @ApiOperation(value = "Gets all role functions for an application which is upgraded to newer version.", response = CentralV2RoleFunction.class, responseContainer = "Json")
183 @RequestMapping(value = { "/v3/functions" }, method = RequestMethod.GET, produces = "application/json")
184 public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
186 Map<String, Object> res = getMethod(request, response);
187 List<CentralV2RoleFunction> roleFunctionsList = null;
189 roleFunctionsList = (List<CentralV2RoleFunction>) invokeMethod(res, request, response);
190 } catch (Exception e) {
191 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunctionsList failed", e);
193 return roleFunctionsList;
196 @ApiOperation(value = "Gets role information for an application provided by function code.", response = CentralV2RoleFunction.class, responseContainer = "Json")
197 @RequestMapping(value = { "/v3/function/{code}" }, method = RequestMethod.GET, produces = "application/json")
198 public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response,
199 @PathVariable("code") String code) throws Exception {
200 Map<String, Object> res = getMethod(request, response);
201 CentralV2RoleFunction roleFunction = null;
203 roleFunction = (CentralV2RoleFunction) invokeMethod(res, request, response, code);
204 } catch (Exception e) {
205 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e);
210 @SuppressWarnings("unchecked")
211 @ApiOperation(value = "Saves role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
212 @RequestMapping(value = { "/v3/roleFunction" }, method = RequestMethod.POST, produces = "application/json")
213 public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response,
214 @RequestBody String roleFunc) throws Exception {
215 PortalRestResponse<String> result = null;
216 Map<String, Object> res = getMethod(request, response);
218 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleFunc);
220 } catch (Exception e) {
221 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e);
222 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
226 @SuppressWarnings("unchecked")
227 @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
228 @RequestMapping(value = { "/v3/roleFunction/{code}" }, method = RequestMethod.DELETE, produces = "application/json")
229 public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response,
230 @PathVariable("code") String code) throws Exception {
231 PortalRestResponse<String> result = null;
232 Map<String, Object> res = getMethod(request, response);
234 result = (PortalRestResponse<String>) invokeMethod(res, request, response, code);
236 } catch (Exception e) {
237 logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction failed", e);
238 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
242 @SuppressWarnings("unchecked")
243 @ApiOperation(value = "deletes roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
244 @RequestMapping(value = { "/v3/deleteRole/{roleId}" }, method = RequestMethod.DELETE, produces = "application/json")
245 public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response,
246 @PathVariable("roleId") Long roleId) throws Exception {
247 PortalRestResponse<String> result = null;
248 Map<String, Object> res = getMethod(request, response);
250 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
252 } catch (Exception e) {
253 logger.error(EELFLoggerDelegate.errorLogger, "deleteRole failed", e);
254 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
258 @SuppressWarnings("unchecked")
259 @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
260 @RequestMapping(value = { "/v3/activeRoles" }, method = RequestMethod.GET, produces = "application/json")
261 public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response)
263 List<CentralV2Role> cenRole = null;
264 Map<String, Object> res = getMethod(request, response);
266 cenRole = (List<CentralV2Role>) invokeMethod(res, request, response);
267 } catch (Exception e) {
268 logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
273 @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List")
274 @RequestMapping(value = { "/v4/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
275 public String getEcompUser(HttpServletRequest request, HttpServletResponse response,
276 @PathVariable("loginId") String loginId) throws Exception {
277 Map<String, Object> res = getMethod(request, response);
278 String answer = null;
280 answer = (String) invokeMethod(res, request, response, loginId);
281 } catch (Exception e) {
282 logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e);
287 @SuppressWarnings("unchecked")
288 @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List")
289 @RequestMapping(value = { "/v4/roles" }, method = RequestMethod.GET, produces = "application/json")
290 public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response)
292 Map<String, Object> res = getMethod(request, response);
293 List<EcompRole> answer = null;
295 answer = (List<EcompRole>) invokeMethod(res, request, response);
296 } catch (Exception e) {
297 logger.error(EELFLoggerDelegate.errorLogger, "getEcompRolesOfApplication failed", e);
302 @ApiOperation(value = "Gets session slot-check interval, a duration in milliseconds.", response = Integer.class)
303 @RequestMapping(value = {
304 "/v3/getSessionSlotCheckInterval" }, method = RequestMethod.GET, produces = "application/json")
305 public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response)
307 Map<String, Object> res = getMethod(request, response);
310 ans = (Integer) invokeMethod(res, request, response);
311 } catch (Exception e) {
312 logger.error(EELFLoggerDelegate.errorLogger, "getSessionSlotCheckInterval failed", e);
317 @ApiOperation(value = "Extends session timeout values for all on-boarded applications.", response = Boolean.class)
318 @RequestMapping(value = { "/v3/extendSessionTimeOuts" }, method = RequestMethod.POST)
319 public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response,
320 @RequestParam String sessionMap) throws Exception {
321 Map<String, Object> res = getMethod(request, response);
324 ans = (Boolean) invokeMethod(res, request, response, sessionMap);
325 } catch (Exception e) {
326 logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts failed", e);
331 @ApiOperation(value = "Gets javascript with functions that support gathering and reporting web analytics.", response = String.class)
332 @RequestMapping(value = { "/v3/analytics" }, method = RequestMethod.GET, produces = "application/javascript")
333 public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception {
334 Map<String, Object> res = getMethod(request, response);
337 ans = (String) invokeMethod(res, request, response);
338 } catch (Exception e) {
339 logger.error(EELFLoggerDelegate.errorLogger, "getAnalyticsScript failed", e);
344 @RequestMapping(value = { "/v3/storeAnalytics" }, method = RequestMethod.POST, produces = "application/json")
346 @ApiOperation(value = "Accepts data from partner applications with web analytics data.", response = PortalAPIResponse.class)
347 public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response,
348 @RequestBody Analytics analyticsMap) throws Exception {
349 Map<String, Object> res = getMethod(request, response);
350 PortalAPIResponse ans = new PortalAPIResponse(true, "error");
352 ans = (PortalAPIResponse) invokeMethod(res, request, response, analyticsMap);
353 } catch (Exception e) {
354 logger.error(EELFLoggerDelegate.errorLogger, "storeAnalyticsScript failed", e);
360 @SuppressWarnings("unchecked")
361 @ApiOperation(value = "Bulk upload functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
362 @RequestMapping(value = {
363 "/v3/upload/portal/functions" }, method = RequestMethod.POST, produces = "application/json")
364 public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response)
366 PortalRestResponse<String> result = null;
367 Map<String, Object> res = getMethod(request, response);
369 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
371 } catch (Exception e) {
372 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e);
373 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
378 @SuppressWarnings("unchecked")
379 @ApiOperation(value = "Bulk upload roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
380 @RequestMapping(value = { "/v3/upload/portal/roles" }, method = RequestMethod.POST, produces = "application/json")
381 public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response)
383 PortalRestResponse<String> result = null;
384 Map<String, Object> res = getMethod(request, response);
386 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
388 } catch (Exception e) {
389 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e);
390 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
394 @SuppressWarnings("unchecked")
395 @ApiOperation(value = "Bulk upload role functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
396 @RequestMapping(value = {
397 "/v3/upload/portal/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
398 public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response)
400 PortalRestResponse<String> result = null;
401 Map<String, Object> res = getMethod(request, response);
403 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
405 } catch (Exception e) {
406 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoleFunctions failed", e);
407 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
411 @SuppressWarnings("unchecked")
412 @ApiOperation(value = "Bulk upload user roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
413 @RequestMapping(value = {
414 "/v3/upload/portal/userRoles" }, method = RequestMethod.POST, produces = "application/json")
415 public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response)
417 PortalRestResponse<String> result = null;
418 Map<String, Object> res = getMethod(request, response);
420 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
422 } catch (Exception e) {
423 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUserRoles failed", e);
424 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
429 @SuppressWarnings("unchecked")
430 @ApiOperation(value = "Bulk upload users for renamed role of an application.", response = PortalRestResponse.class, responseContainer = "Json")
431 @RequestMapping(value = {
432 "/v3/upload/portal/userRole/{roleId}" }, method = RequestMethod.POST, produces = "application/json")
433 public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request,
434 HttpServletResponse response, @PathVariable Long roleId) throws Exception {
435 PortalRestResponse<String> result = null;
436 Map<String, Object> res = getMethod(request, response);
438 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
440 } catch (Exception e) {
441 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUsersSingleRole failed", e);
442 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
446 @SuppressWarnings("unchecked")
447 @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
448 @RequestMapping(value = {
449 "/v3/upload/partner/functions" }, method = RequestMethod.POST, produces = "application/json")
450 public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request,
451 HttpServletResponse response) throws Exception {
452 PortalRestResponse<String> result = null;
453 Map<String, Object> res = getMethod(request, response);
455 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
457 } catch (Exception e) {
458 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerFunctions failed", e);
459 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
464 @SuppressWarnings("unchecked")
465 @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
466 @RequestMapping(value = { "/v3/upload/partner/roles" }, method = RequestMethod.POST, produces = "application/json")
467 public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response,
468 @RequestBody List<Role> upload) throws Exception {
469 PortalRestResponse<String> result = null;
470 Map<String, Object> res = getMethod(request, response);
472 result = (PortalRestResponse<String>) invokeMethod(res, request, response, upload);
474 } catch (Exception e) {
475 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoles failed", e);
476 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
480 @SuppressWarnings("unchecked")
481 @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
482 @RequestMapping(value = {
483 "/v3/upload/partner/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
484 public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request,
485 HttpServletResponse response) throws Exception {
486 PortalRestResponse<String> result = null;
487 Map<String, Object> res = getMethod(request, response);
489 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
491 } catch (Exception e) {
492 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoleFunctions failed", e);
493 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
497 @SuppressWarnings("unchecked")
498 @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json")
499 @RequestMapping(value = { "/v3/menuFunctions" }, method = RequestMethod.GET, produces = "application/json")
500 public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception {
501 List<String> functionsList = null;
502 Map<String, Object> res = getMethod(request, response);
504 functionsList = (List<String>) invokeMethod(res, request, response);
505 } catch (Exception e) {
506 logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctions failed", e);
508 return functionsList;
511 private String getPatchNumber() {
512 String response = "0";
514 Attributes attributes = manifestService.getWebappManifest();
515 response = attributes.getValue("Build-Number");
516 } catch (Exception ex) {
517 logger.error(EELFLoggerDelegate.errorLogger, "getPatchNumber failed", ex);
522 @SuppressWarnings("rawtypes")
523 private List<Object> getObject(HttpServletRequest request, HttpServletResponse response) {
524 Map<String, Object> beans = context.getBeansWithAnnotation(ApiVersion.class);
525 @SuppressWarnings("unchecked")
526 List<Object> beansList = new ArrayList(beans.values());
531 private Map<String, Object> getMethod(HttpServletRequest request, HttpServletResponse response) {
532 Method finalmethod = null;
533 String url = request.getRequestURI();
536 Object currentObject = null;
537 Map<String, Object> res = new HashMap<String, Object>();
538 String[] uriArray = url.split("/auxapi");
539 List<Integer> minorversionList = new ArrayList<>();
540 if (uriArray.length > 1) {
541 service = uriArray[1];
543 int first = service.indexOf("/");
544 int second = service.indexOf("/", first + 1);
545 version = service.substring(first + 1, second);
546 int min = minorVersion;
547 if (request.getHeader("MinorVersion") != null) {
548 min = Integer.parseInt(request.getHeader("MinorVersion"));
550 res.put("min", version+"."+min);
551 res.put("service", service);
552 List<Object> objList = getObject(request, response);
553 String requestedApiMethodType = request.getMethod();
554 String majorVersion = latestMajorVersionOfService(objList, service, version, requestedApiMethodType);
555 int latestMinorVersion = latestMinorVersionOfService(objList, service, version, requestedApiMethodType);
556 res.put("majorVersion", majorVersion);
557 res.put("latestMinorVersion", String.valueOf(latestMinorVersion));
558 outerloop: for (Object obj : objList) {
559 final List<Method> allMethods = getAllMethodsOfClass(obj);
560 for (final Method method : allMethods) {
561 if (method.isAnnotationPresent(ApiVersion.class)) {
562 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
563 Pattern p = Pattern.compile(annotInstance.service(),
564 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
565 Matcher matcher = p.matcher(service);
566 boolean b = matcher.matches();
567 logger.debug(EELFLoggerDelegate.debugLogger, "Requested Servie is:" + service
568 + "Requested MinVersion is:" + min + "Requested MajorVersion is: " + version);
569 if (annotInstance.max().equals(version) && b && annotInstance.min() == min
570 && annotInstance.method().equals(request.getMethod())) {
571 finalmethod = method;
573 res.put("method", method);
583 private String latestMajorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
584 String requestedApiMethodType) {
585 Integer majorVersion = 0;
586 String serviceEndPoint = service;
587 int firstindex = serviceEndPoint.indexOf("/");
588 int secondindex = serviceEndPoint.indexOf("/", firstindex + 1);
589 serviceEndPoint = serviceEndPoint.substring(secondindex + 1);
591 List<Integer> latestMajorVersionList = new ArrayList<>();
592 for (Object obj : objList) {
593 final List<Method> allMethods = getAllMethodsOfClass(obj);
594 for (final Method method : allMethods) {
595 if (method.isAnnotationPresent(ApiVersion.class)) {
596 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
597 String endpoint = annotInstance.service();
598 int first = endpoint.indexOf("/");
599 int second = endpoint.indexOf("/", first + 1);
600 endpoint = endpoint.substring(second + 1);
601 Pattern p = Pattern.compile(endpoint,
602 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
603 Matcher matcher = p.matcher(serviceEndPoint);
604 boolean b = matcher.matches();
605 if (b && annotInstance.method().equals(requestedApiMethodType)) {
606 int index1 = annotInstance.service().indexOf("/");
607 int index2 = annotInstance.service().indexOf("/", index1 + 1);
608 String majorversion = annotInstance.service().substring(index1 + 2, index2);
609 latestMajorVersionList.add(Integer.parseInt(majorversion));
614 majorVersion = Collections.max(latestMajorVersionList);
615 String majorVersionWithLastestMin = "/v"+String.valueOf(majorVersion)+"/"+serviceEndPoint;
616 int latestMinorVersion = latestMinorVersionOfService(objList, majorVersionWithLastestMin, "v"+String.valueOf(majorVersion), requestedApiMethodType);
617 return majorVersion+"."+latestMinorVersion;
620 private List<Method> getAllMethodsOfClass(Object obj) {
621 List<Method> allMethods = new ArrayList<>();
622 Class<?> objClz = obj.getClass();
623 if (org.springframework.aop.support.AopUtils.isAopProxy(obj)) {
624 objClz = org.springframework.aop.support.AopUtils.getTargetClass(obj);
626 allMethods = new ArrayList<Method>(Arrays.asList(objClz.getMethods()));
627 allMethods.removeIf(s -> !(s.isAnnotationPresent(ApiVersion.class)));
631 private Integer latestMinorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
632 String requestedApiMethodType) {
633 Integer minVersion = 0;
634 String serviceEndPoint = service;
635 List<Integer> latestMinorVersionList = new ArrayList<>();
636 for (Object obj : objList) {
637 final List<Method> allMethods = getAllMethodsOfClass(obj);
638 for (final Method method : allMethods) {
639 if (method.isAnnotationPresent(ApiVersion.class)) {
640 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
641 String endpoint = annotInstance.service();
643 Pattern p = Pattern.compile(endpoint,
644 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
645 Matcher matcher = p.matcher(serviceEndPoint);
646 boolean b = matcher.matches();
647 if (annotInstance.max().equals(reuqestedVersion) && b
648 && annotInstance.method().equals(requestedApiMethodType)) {
649 int minorversion = annotInstance.min();
650 latestMinorVersionList.add(minorversion);
655 minVersion = Collections.max(latestMinorVersionList);
659 private HttpServletResponse setResponse(HttpServletResponse response, String requestedMinVersion,
660 String majorVersion, String latestMinorVersion, String service) {
661 response.setHeader("X-MinorVersion", requestedMinVersion.toUpperCase());
662 response.setHeader("X-PatchVersion", getPatchNumber());
663 response.setHeader("X-LatestVersion", "V"+majorVersion);
671 * method parameters(Maintain HttpServletRequest at 0th position
672 * and HttpServletResponse at 1th position in args array)
676 private Object invokeMethod(Map<String, Object> res, Object... args) throws Exception {
677 Method method = (Method) res.get("method");
678 Object obj = res.get("Obj");
679 Object responseObj = null;
680 String min = res.get("min").toString();
681 String majorVersion = res.get("majorVersion").toString();
682 String latestMinorVersion = res.get("latestMinorVersion").toString();
683 String service = res.get("service").toString();
684 HttpServletRequest request = (HttpServletRequest) args[0];
685 HttpServletResponse response = (HttpServletResponse) args[1];
686 setResponse(response, min, majorVersion, latestMinorVersion, service);
687 final Map<String, String> errorMap = new HashMap<>();
688 ObjectMapper mapper = new ObjectMapper();
691 if (method != null && obj != null) {
692 responseObj = method.invoke(obj, args);
694 errorMap.put("error", "Requested api is not available");
695 reason = mapper.writeValueAsString(errorMap);
696 response.getWriter().write(reason);
697 logger.debug(EELFLoggerDelegate.debugLogger, "Requested api " + request.getRequestURI()
698 + "is not available with minorVersion " + request.getHeader("MinorVersion"));
699 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
701 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
702 logger.error(EELFLoggerDelegate.errorLogger, "Method :" + method + "invocation failed", e);
708 public void setApplicationContext(ApplicationContext context) throws BeansException {
709 this.context = context;
712 @SuppressWarnings("unchecked")
713 @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class)
714 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.POST, produces = "application/json")
715 public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
716 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
717 PortalRestResponse<String> result = null;
718 Map<String, Object> res = getMethod(request, response);
720 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
722 } catch (Exception e) {
723 logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile failed", e);
724 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
728 @SuppressWarnings("unchecked")
729 @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class)
730 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.PUT, produces = "application/json")
731 public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
732 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
733 PortalRestResponse<String> result = null;
734 Map<String, Object> res = getMethod(request, response);
736 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
738 } catch (Exception e) {
739 logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile failed", e);
740 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
744 @SuppressWarnings("unchecked")
745 @ApiOperation(value = "Processes a request to delete one or more application roles for one specified user who has roles.", response = PortalRestResponse.class)
746 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.DELETE, produces = "application/json")
747 public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
748 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
749 PortalRestResponse<String> result = null;
750 Map<String, Object> res = getMethod(request, response);
752 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
754 } catch (Exception e) {
755 logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile failed", e);
756 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
760 @SuppressWarnings("unchecked")
761 @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class)
762 @RequestMapping(value = { "/v3/ticketevent" }, method = RequestMethod.POST)
763 public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
764 @RequestBody String ticketEventJson) throws Exception {
765 PortalRestResponse<String> result = null;
766 Map<String, Object> res = getMethod(request, response);
768 result = (PortalRestResponse<String>) invokeMethod(res, request, response, ticketEventJson);
770 } catch (Exception e) {
771 logger.error(EELFLoggerDelegate.errorLogger, "handleRequest failed", e);
772 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
776 @SuppressWarnings("unchecked")
777 @ApiOperation(value = "Creates a new user as a Portal administrator.", response = PortalRestResponse.class)
778 @RequestMapping(value = "/v3/portalAdmin", method = RequestMethod.POST, produces = "application/json")
780 public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response,
781 @RequestBody EPUser epUser) {
782 PortalRestResponse<String> result = null;
783 Map<String, Object> res = getMethod(request, response);
785 result = (PortalRestResponse<String>) invokeMethod(res, request, response, epUser);
787 } catch (Exception e) {
788 logger.error(EELFLoggerDelegate.errorLogger, "postPortalAdmin failed", e);
789 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
793 @ApiOperation(value = "Gets the specified application that is on-boarded in Portal.", response = OnboardingApp.class)
794 @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.GET, produces = "application/json")
796 public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
797 @PathVariable("appId") Long appId) {
798 OnboardingApp result = new OnboardingApp();
799 Map<String, Object> res = getMethod(request, response);
801 result = (OnboardingApp) invokeMethod(res, request, response, appId);
802 } catch (Exception e) {
803 logger.error(EELFLoggerDelegate.errorLogger, "getOnboardAppExternal failed", e);
808 @SuppressWarnings("unchecked")
809 @ApiOperation(value = "Adds a new application to Portal.", response = PortalRestResponse.class)
810 @RequestMapping(value = { "/v3/onboardApp" }, method = RequestMethod.POST, produces = "application/json")
812 public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
813 @RequestBody OnboardingApp newOnboardApp) {
814 PortalRestResponse<String> result = new PortalRestResponse<>();
815 Map<String, Object> res = getMethod(request, response);
817 result = (PortalRestResponse<String>) invokeMethod(res, request, response, newOnboardApp);
819 } catch (Exception e) {
820 logger.error(EELFLoggerDelegate.errorLogger, "postOnboardAppExternal failed", e);
821 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
826 @SuppressWarnings("unchecked")
827 @ApiOperation(value = "Updates information about an on-boarded application in Portal.", response = PortalRestResponse.class)
828 @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.PUT, produces = "application/json")
830 public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
831 @PathVariable("appId") Long appId, @RequestBody OnboardingApp oldOnboardApp) {
832 PortalRestResponse<String> result = new PortalRestResponse<>();
833 Map<String, Object> res = getMethod(request, response);
835 result = (PortalRestResponse<String>) invokeMethod(res, request, response, appId, oldOnboardApp);
837 } catch (Exception e) {
838 logger.error(EELFLoggerDelegate.errorLogger, "putOnboardAppExternal failed", e);
839 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
843 @ApiOperation(value = "Creates a Portal user notification for roles identified in the content from an external application.", response = PortalAPIResponse.class)
844 @RequestMapping(value = { "/v3/publishNotification" }, method = RequestMethod.POST, produces = "application/json")
846 public PortalAPIResponse publishNotification(HttpServletRequest request,
847 @RequestBody EpNotificationItem notificationItem, HttpServletResponse response) throws Exception {
848 PortalAPIResponse result = new PortalAPIResponse(true, "success");
849 Map<String, Object> res = getMethod(request, response);
851 result = (PortalAPIResponse) invokeMethod(res, request, response, notificationItem);
853 } catch (Exception e) {
854 logger.error(EELFLoggerDelegate.errorLogger, "publishNotification failed", e);
855 return new PortalAPIResponse(false, e.getMessage());
859 @SuppressWarnings("unchecked")
860 @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer = "List")
861 @RequestMapping(value = { "/v3/getFavorites" }, method = RequestMethod.GET, produces = "application/json")
862 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
863 HttpServletResponse response) throws Exception {
864 List<FavoritesFunctionalMenuItemJson> favorites = null;
865 Map<String, Object> res = getMethod(request, response);
867 favorites = (List<FavoritesFunctionalMenuItemJson>) invokeMethod(res, request, response);
868 } catch (Exception e) {
869 logger.error(EELFLoggerDelegate.errorLogger, "getFavoritesForUser failed", e);
874 @SuppressWarnings("unchecked")
875 @ApiOperation(value = "Gets functional menu items appropriate for the current user.", response = FunctionalMenuItem.class, responseContainer = "List")
876 @RequestMapping(value = {
877 "/v3/functionalMenuItemsForUser" }, method = RequestMethod.GET, produces = "application/json")
878 public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request,
879 HttpServletResponse response) throws Exception {
880 List<FunctionalMenuItem> fnMenuItems = null;
881 Map<String, Object> res = getMethod(request, response);
883 fnMenuItems = (List<FunctionalMenuItem>) invokeMethod(res, request, response);
884 } catch (Exception e) {
885 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser failed", e);