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.aaf.cadi.aaf.AAFPermission;
55 import org.onap.portalapp.annotation.ApiVersion;
56 import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser;
57 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
58 import org.onap.portalapp.portal.domain.EPUser;
59 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
60 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
61 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
62 import org.onap.portalapp.portal.service.ManifestService;
63 import org.onap.portalapp.portal.transport.Analytics;
64 import org.onap.portalapp.portal.transport.CentralUser;
65 import org.onap.portalapp.portal.transport.CentralV2Role;
66 import org.onap.portalapp.portal.transport.EpNotificationItem;
67 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
68 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
69 import org.onap.portalapp.portal.transport.OnboardingApp;
70 import org.onap.portalsdk.core.domain.Role;
71 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
72 import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
73 import org.onap.portalsdk.core.restful.domain.EcompRole;
74 import org.onap.portalsdk.core.restful.domain.EcompUser;
75 import org.springframework.beans.BeansException;
76 import org.springframework.beans.factory.annotation.Autowired;
77 import org.springframework.context.ApplicationContext;
78 import org.springframework.context.ApplicationContextAware;
79 import org.springframework.context.annotation.EnableAspectJAutoProxy;
80 import org.springframework.web.bind.annotation.PathVariable;
81 import org.springframework.web.bind.annotation.RequestBody;
82 import org.springframework.web.bind.annotation.RequestMapping;
83 import org.springframework.web.bind.annotation.RequestMethod;
84 import org.springframework.web.bind.annotation.RequestParam;
85 import org.springframework.web.bind.annotation.ResponseBody;
86 import org.springframework.web.bind.annotation.RestController;
88 import com.fasterxml.jackson.databind.ObjectMapper;
90 import io.swagger.annotations.ApiOperation;
93 @RequestMapping("/auxapi")
94 @org.springframework.context.annotation.Configuration
95 @EnableAspectJAutoProxy
97 public class AuxApiRequestMapperController implements ApplicationContextAware, BasicAuthenticationController {
99 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AuxApiRequestMapperController.class);
101 ApplicationContext context = null;
102 int minorVersion = 0;
105 private ManifestService manifestService;
107 @ApiOperation(value = "Gets user roles for an application which is upgraded to newer version.", response = String.class, responseContainer = "List")
108 @RequestMapping(value = { "/v3/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
109 public String getUser(HttpServletRequest request, HttpServletResponse response,
110 @PathVariable("loginId") String loginId) throws Exception {
111 Map<String, Object> res = getMethod(request, response);
112 String answer = null;
114 answer = (String) invokeMethod(res, request, response, loginId);
115 } catch (Exception e) {
116 logger.error(EELFLoggerDelegate.errorLogger, "getUser failed", e);
121 @SuppressWarnings("unchecked")
122 @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
123 @RequestMapping(value = { "/v3/roles" }, method = RequestMethod.GET, produces = "application/json")
124 public List<CentralV2Role> getRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
125 Map<String, Object> res = getMethod(request, response);
127 List<CentralV2Role> answer = null;
129 answer = (List<CentralV2Role>) invokeMethod(res, request, response);
130 } catch (Exception e) {
131 logger.error(EELFLoggerDelegate.errorLogger, "getRoles failed", e);
136 @SuppressWarnings("unchecked")
137 @ApiOperation(value = "Saves role for an application.", response = PortalRestResponse.class, responseContainer = "Json")
138 @RequestMapping(value = { "/v3/role" }, method = RequestMethod.POST, produces = "application/json")
139 public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response,
140 @RequestBody Role role) throws Exception {
141 Map<String, Object> res = getMethod(request, response);
142 PortalRestResponse<String> out = null;
144 out = (PortalRestResponse<String>) invokeMethod(res, request, response, role);
145 } catch (Exception e) {
146 logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e);
147 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
152 @ApiOperation(value = "Gets v2 role information for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
153 @RequestMapping(value = { "/v3/role/{role_id}" }, method = RequestMethod.GET, produces = "application/json")
154 public CentralV2Role getRoleInfo(HttpServletRequest request, HttpServletResponse response,
155 @PathVariable("role_id") Long roleId) throws Exception {
156 Map<String, Object> res = getMethod(request, response);
157 CentralV2Role role = null;
159 role = (CentralV2Role) invokeMethod(res, request, response, roleId);
160 } catch (Exception e) {
161 logger.error(EELFLoggerDelegate.errorLogger, "getRoleInfo failed", e);
167 @SuppressWarnings("unchecked")
168 @ApiOperation(value = "Gets all active Users of application", response = String.class, responseContainer = "Json")
169 @RequestMapping(value = { "/v3/users" }, method = RequestMethod.GET, produces = "application/json")
170 public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response)
172 Map<String, Object> res = getMethod(request, response);
173 List<EcompUser> users = null;
175 users = (List<EcompUser>) invokeMethod(res, request, response);
176 } catch (Exception e) {
177 logger.error(EELFLoggerDelegate.errorLogger, "getUsersOfApplication failed", e);
182 @SuppressWarnings("unchecked")
183 @ApiOperation(value = "Gets all role functions for an application which is upgraded to newer version.", response = CentralV2RoleFunction.class, responseContainer = "Json")
184 @RequestMapping(value = { "/v3/functions" }, method = RequestMethod.GET, produces = "application/json")
185 public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
187 Map<String, Object> res = getMethod(request, response);
188 List<CentralV2RoleFunction> roleFunctionsList = null;
190 roleFunctionsList = (List<CentralV2RoleFunction>) invokeMethod(res, request, response);
191 } catch (Exception e) {
192 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunctionsList failed", e);
194 return roleFunctionsList;
197 @ApiOperation(value = "Gets role information for an application provided by function code.", response = CentralV2RoleFunction.class, responseContainer = "Json")
198 @RequestMapping(value = { "/v3/function/{code}" }, method = RequestMethod.GET, produces = "application/json")
199 public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response,
200 @PathVariable("code") String code) throws Exception {
201 Map<String, Object> res = getMethod(request, response);
202 CentralV2RoleFunction roleFunction = null;
204 roleFunction = (CentralV2RoleFunction) invokeMethod(res, request, response, code);
205 } catch (Exception e) {
206 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e);
211 @SuppressWarnings("unchecked")
212 @ApiOperation(value = "Saves role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
213 @RequestMapping(value = { "/v3/roleFunction" }, method = RequestMethod.POST, produces = "application/json")
214 public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response,
215 @RequestBody String roleFunc) throws Exception {
216 PortalRestResponse<String> result = null;
217 Map<String, Object> res = getMethod(request, response);
219 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleFunc);
221 } catch (Exception e) {
222 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e);
223 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
227 @SuppressWarnings("unchecked")
228 @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
229 @RequestMapping(value = { "/v3/roleFunction/{code}" }, method = RequestMethod.DELETE, produces = "application/json")
230 public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response,
231 @PathVariable("code") String code) throws Exception {
232 PortalRestResponse<String> result = null;
233 Map<String, Object> res = getMethod(request, response);
235 result = (PortalRestResponse<String>) invokeMethod(res, request, response, code);
237 } catch (Exception e) {
238 logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction failed", e);
239 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
243 @SuppressWarnings("unchecked")
244 @ApiOperation(value = "deletes roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
245 @RequestMapping(value = { "/v3/deleteRole/{roleId}" }, method = RequestMethod.DELETE, produces = "application/json")
246 public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response,
247 @PathVariable("roleId") Long roleId) throws Exception {
248 PortalRestResponse<String> result = null;
249 Map<String, Object> res = getMethod(request, response);
251 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
253 } catch (Exception e) {
254 logger.error(EELFLoggerDelegate.errorLogger, "deleteRole failed", e);
255 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
259 @SuppressWarnings("unchecked")
260 @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
261 @RequestMapping(value = { "/v3/activeRoles" }, method = RequestMethod.GET, produces = "application/json")
262 public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response)
264 List<CentralV2Role> cenRole = null;
265 Map<String, Object> res = getMethod(request, response);
267 cenRole = (List<CentralV2Role>) invokeMethod(res, request, response);
268 } catch (Exception e) {
269 logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
274 @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List")
275 @RequestMapping(value = { "/v4/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
276 public String getEcompUser(HttpServletRequest request, HttpServletResponse response,
277 @PathVariable("loginId") String loginId) throws Exception {
278 Map<String, Object> res = getMethod(request, response);
279 String answer = null;
281 answer = (String) invokeMethod(res, request, response, loginId);
282 } catch (Exception e) {
283 logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e);
288 @SuppressWarnings("unchecked")
289 @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List")
290 @RequestMapping(value = { "/v4/roles" }, method = RequestMethod.GET, produces = "application/json")
291 public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response)
293 Map<String, Object> res = getMethod(request, response);
294 List<EcompRole> answer = null;
296 answer = (List<EcompRole>) invokeMethod(res, request, response);
297 } catch (Exception e) {
298 logger.error(EELFLoggerDelegate.errorLogger, "getEcompRolesOfApplication failed", e);
303 @ApiOperation(value = "Gets session slot-check interval, a duration in milliseconds.", response = Integer.class)
304 @RequestMapping(value = {
305 "/v3/getSessionSlotCheckInterval" }, method = RequestMethod.GET, produces = "application/json")
306 public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response)
308 Map<String, Object> res = getMethod(request, response);
311 ans = (Integer) invokeMethod(res, request, response);
312 } catch (Exception e) {
313 logger.error(EELFLoggerDelegate.errorLogger, "getSessionSlotCheckInterval failed", e);
318 @ApiOperation(value = "Extends session timeout values for all on-boarded applications.", response = Boolean.class)
319 @RequestMapping(value = { "/v3/extendSessionTimeOuts" }, method = RequestMethod.POST)
320 public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response,
321 @RequestParam String sessionMap) throws Exception {
322 Map<String, Object> res = getMethod(request, response);
325 ans = (Boolean) invokeMethod(res, request, response, sessionMap);
326 } catch (Exception e) {
327 logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts failed", e);
332 @ApiOperation(value = "Gets javascript with functions that support gathering and reporting web analytics.", response = String.class)
333 @RequestMapping(value = { "/v3/analytics" }, method = RequestMethod.GET, produces = "application/javascript")
334 public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception {
335 Map<String, Object> res = getMethod(request, response);
338 ans = (String) invokeMethod(res, request, response);
339 } catch (Exception e) {
340 logger.error(EELFLoggerDelegate.errorLogger, "getAnalyticsScript failed", e);
345 @RequestMapping(value = { "/v3/storeAnalytics" }, method = RequestMethod.POST, produces = "application/json")
347 @ApiOperation(value = "Accepts data from partner applications with web analytics data.", response = PortalAPIResponse.class)
348 public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response,
349 @RequestBody Analytics analyticsMap) throws Exception {
350 Map<String, Object> res = getMethod(request, response);
351 PortalAPIResponse ans = new PortalAPIResponse(true, "error");
353 ans = (PortalAPIResponse) invokeMethod(res, request, response, analyticsMap);
354 } catch (Exception e) {
355 logger.error(EELFLoggerDelegate.errorLogger, "storeAnalyticsScript failed", e);
361 @SuppressWarnings("unchecked")
362 @ApiOperation(value = "Bulk upload functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
363 @RequestMapping(value = {
364 "/v3/upload/portal/functions" }, method = RequestMethod.POST, produces = "application/json")
365 public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response)
367 PortalRestResponse<String> result = null;
368 Map<String, Object> res = getMethod(request, response);
370 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
372 } catch (Exception e) {
373 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e);
374 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
379 @SuppressWarnings("unchecked")
380 @ApiOperation(value = "Bulk upload roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
381 @RequestMapping(value = { "/v3/upload/portal/roles" }, method = RequestMethod.POST, produces = "application/json")
382 public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response)
384 PortalRestResponse<String> result = null;
385 Map<String, Object> res = getMethod(request, response);
387 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
389 } catch (Exception e) {
390 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e);
391 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
395 @SuppressWarnings("unchecked")
396 @ApiOperation(value = "Bulk upload role functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
397 @RequestMapping(value = {
398 "/v3/upload/portal/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
399 public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response)
401 PortalRestResponse<String> result = null;
402 Map<String, Object> res = getMethod(request, response);
404 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
406 } catch (Exception e) {
407 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoleFunctions failed", e);
408 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
412 @SuppressWarnings("unchecked")
413 @ApiOperation(value = "Bulk upload user roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
414 @RequestMapping(value = {
415 "/v3/upload/portal/userRoles" }, method = RequestMethod.POST, produces = "application/json")
416 public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response)
418 PortalRestResponse<String> result = null;
419 Map<String, Object> res = getMethod(request, response);
421 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
423 } catch (Exception e) {
424 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUserRoles failed", e);
425 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
430 @SuppressWarnings("unchecked")
431 @ApiOperation(value = "Bulk upload users for renamed role of an application.", response = PortalRestResponse.class, responseContainer = "Json")
432 @RequestMapping(value = {
433 "/v3/upload/portal/userRole/{roleId}" }, method = RequestMethod.POST, produces = "application/json")
434 public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request,
435 HttpServletResponse response, @PathVariable Long roleId) throws Exception {
436 PortalRestResponse<String> result = null;
437 Map<String, Object> res = getMethod(request, response);
439 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
441 } catch (Exception e) {
442 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUsersSingleRole failed", e);
443 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
447 @SuppressWarnings("unchecked")
448 @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
449 @RequestMapping(value = {
450 "/v3/upload/partner/functions" }, method = RequestMethod.POST, produces = "application/json")
451 public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request,
452 HttpServletResponse response) throws Exception {
453 PortalRestResponse<String> result = null;
454 Map<String, Object> res = getMethod(request, response);
456 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
458 } catch (Exception e) {
459 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerFunctions failed", e);
460 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
465 @SuppressWarnings("unchecked")
466 @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
467 @RequestMapping(value = { "/v3/upload/partner/roles" }, method = RequestMethod.POST, produces = "application/json")
468 public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response,
469 @RequestBody List<Role> upload) throws Exception {
470 PortalRestResponse<String> result = null;
471 Map<String, Object> res = getMethod(request, response);
473 result = (PortalRestResponse<String>) invokeMethod(res, request, response, upload);
475 } catch (Exception e) {
476 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoles failed", e);
477 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
481 @SuppressWarnings("unchecked")
482 @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
483 @RequestMapping(value = {
484 "/v3/upload/partner/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
485 public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request,
486 HttpServletResponse response) throws Exception {
487 PortalRestResponse<String> result = null;
488 Map<String, Object> res = getMethod(request, response);
490 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
492 } catch (Exception e) {
493 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoleFunctions failed", e);
494 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
498 @SuppressWarnings("unchecked")
499 @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json")
500 @RequestMapping(value = { "/v3/menuFunctions" }, method = RequestMethod.GET, produces = "application/json")
501 public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception {
502 List<String> functionsList = null;
503 Map<String, Object> res = getMethod(request, response);
505 functionsList = (List<String>) invokeMethod(res, request, response);
506 } catch (Exception e) {
507 logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctions failed", e);
509 return functionsList;
512 private String getPatchNumber() {
513 String response = "0";
515 Attributes attributes = manifestService.getWebappManifest();
516 response = attributes.getValue("Build-Number");
517 } catch (Exception ex) {
518 logger.error(EELFLoggerDelegate.errorLogger, "getPatchNumber failed", ex);
523 @SuppressWarnings("rawtypes")
524 private List<Object> getObject(HttpServletRequest request, HttpServletResponse response) {
525 Map<String, Object> beans = context.getBeansWithAnnotation(ApiVersion.class);
526 @SuppressWarnings("unchecked")
527 List<Object> beansList = new ArrayList(beans.values());
532 private Map<String, Object> getMethod(HttpServletRequest request, HttpServletResponse response) {
533 Method finalmethod = null;
534 String url = request.getRequestURI();
537 Object currentObject = null;
538 Map<String, Object> res = new HashMap<String, Object>();
539 String[] uriArray = url.split("/auxapi");
540 List<Integer> minorversionList = new ArrayList<>();
541 if (uriArray.length > 1) {
542 service = uriArray[1];
544 int first = service.indexOf("/");
545 int second = service.indexOf("/", first + 1);
546 version = service.substring(first + 1, second);
547 int min = minorVersion;
548 if (request.getHeader("MinorVersion") != null) {
549 min = Integer.parseInt(request.getHeader("MinorVersion"));
551 res.put("min", version+"."+min);
552 res.put("service", service);
553 List<Object> objList = getObject(request, response);
554 String requestedApiMethodType = request.getMethod();
555 String majorVersion = latestMajorVersionOfService(objList, service, version, requestedApiMethodType);
556 int latestMinorVersion = latestMinorVersionOfService(objList, service, version, requestedApiMethodType);
557 res.put("majorVersion", majorVersion);
558 res.put("latestMinorVersion", String.valueOf(latestMinorVersion));
559 outerloop: for (Object obj : objList) {
560 final List<Method> allMethods = getAllMethodsOfClass(obj);
561 for (final Method method : allMethods) {
562 if (method.isAnnotationPresent(ApiVersion.class)) {
563 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
564 Pattern p = Pattern.compile(annotInstance.service(),
565 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
566 Matcher matcher = p.matcher(service);
567 boolean b = matcher.matches();
568 logger.debug(EELFLoggerDelegate.debugLogger, "Requested Servie is:" + service
569 + "Requested MinVersion is:" + min + "Requested MajorVersion is: " + version);
570 if (annotInstance.max().equals(version) && b && annotInstance.min() == min
571 && annotInstance.method().equals(request.getMethod())) {
572 finalmethod = method;
574 res.put("method", method);
584 private String latestMajorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
585 String requestedApiMethodType) {
586 Integer majorVersion = 0;
587 String serviceEndPoint = service;
588 int firstindex = serviceEndPoint.indexOf("/");
589 int secondindex = serviceEndPoint.indexOf("/", firstindex + 1);
590 serviceEndPoint = serviceEndPoint.substring(secondindex + 1);
592 List<Integer> latestMajorVersionList = new ArrayList<>();
593 for (Object obj : objList) {
594 final List<Method> allMethods = getAllMethodsOfClass(obj);
595 for (final Method method : allMethods) {
596 if (method.isAnnotationPresent(ApiVersion.class)) {
597 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
598 String endpoint = annotInstance.service();
599 int first = endpoint.indexOf("/");
600 int second = endpoint.indexOf("/", first + 1);
601 endpoint = endpoint.substring(second + 1);
602 Pattern p = Pattern.compile(endpoint,
603 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
604 Matcher matcher = p.matcher(serviceEndPoint);
605 boolean b = matcher.matches();
606 if (b && annotInstance.method().equals(requestedApiMethodType)) {
607 int index1 = annotInstance.service().indexOf("/");
608 int index2 = annotInstance.service().indexOf("/", index1 + 1);
609 String majorversion = annotInstance.service().substring(index1 + 2, index2);
610 latestMajorVersionList.add(Integer.parseInt(majorversion));
615 majorVersion = Collections.max(latestMajorVersionList);
616 String majorVersionWithLastestMin = "/v"+String.valueOf(majorVersion)+"/"+serviceEndPoint;
617 int latestMinorVersion = latestMinorVersionOfService(objList, majorVersionWithLastestMin, "v"+String.valueOf(majorVersion), requestedApiMethodType);
618 return majorVersion+"."+latestMinorVersion;
621 private List<Method> getAllMethodsOfClass(Object obj) {
622 List<Method> allMethods = new ArrayList<>();
623 Class<?> objClz = obj.getClass();
624 if (org.springframework.aop.support.AopUtils.isAopProxy(obj)) {
625 objClz = org.springframework.aop.support.AopUtils.getTargetClass(obj);
627 allMethods = new ArrayList<Method>(Arrays.asList(objClz.getMethods()));
628 allMethods.removeIf(s -> !(s.isAnnotationPresent(ApiVersion.class)));
632 private Integer latestMinorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
633 String requestedApiMethodType) {
634 Integer minVersion = 0;
635 String serviceEndPoint = service;
636 List<Integer> latestMinorVersionList = new ArrayList<>();
637 for (Object obj : objList) {
638 final List<Method> allMethods = getAllMethodsOfClass(obj);
639 for (final Method method : allMethods) {
640 if (method.isAnnotationPresent(ApiVersion.class)) {
641 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
642 String endpoint = annotInstance.service();
644 Pattern p = Pattern.compile(endpoint,
645 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
646 Matcher matcher = p.matcher(serviceEndPoint);
647 boolean b = matcher.matches();
648 if (annotInstance.max().equals(reuqestedVersion) && b
649 && annotInstance.method().equals(requestedApiMethodType)) {
650 int minorversion = annotInstance.min();
651 latestMinorVersionList.add(minorversion);
656 minVersion = Collections.max(latestMinorVersionList);
660 private HttpServletResponse setResponse(HttpServletResponse response, String requestedMinVersion,
661 String majorVersion, String latestMinorVersion, String service) {
662 response.setHeader("X-MinorVersion", requestedMinVersion.toUpperCase());
663 response.setHeader("X-PatchVersion", getPatchNumber());
664 response.setHeader("X-LatestVersion", "V"+majorVersion);
672 * method parameters(Maintain HttpServletRequest at 0th position
673 * and HttpServletResponse at 1th position in args array)
677 private Object invokeMethod(Map<String, Object> res, Object... args) throws Exception {
678 Method method = (Method) res.get("method");
679 Object obj = res.get("Obj");
680 Object responseObj = null;
681 String min = res.get("min").toString();
682 String majorVersion = res.get("majorVersion").toString();
683 String latestMinorVersion = res.get("latestMinorVersion").toString();
684 String service = res.get("service").toString();
685 HttpServletRequest request = (HttpServletRequest) args[0];
686 HttpServletResponse response = (HttpServletResponse) args[1];
687 setResponse(response, min, majorVersion, latestMinorVersion, service);
688 final Map<String, String> errorMap = new HashMap<>();
689 ObjectMapper mapper = new ObjectMapper();
692 if (method != null && obj != null) {
693 responseObj = method.invoke(obj, args);
695 errorMap.put("error", "Requested api is not available");
696 reason = mapper.writeValueAsString(errorMap);
697 response.getWriter().write(reason);
698 logger.debug(EELFLoggerDelegate.debugLogger, "Requested api " + request.getRequestURI()
699 + "is not available with minorVersion " + request.getHeader("MinorVersion"));
700 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
702 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
703 logger.error(EELFLoggerDelegate.errorLogger, "Method :" + method + "invocation failed", e);
709 public void setApplicationContext(ApplicationContext context) throws BeansException {
710 this.context = context;
713 @SuppressWarnings("unchecked")
714 @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class)
715 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.POST, produces = "application/json")
716 public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
717 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
718 PortalRestResponse<String> result = null;
719 Map<String, Object> res = getMethod(request, response);
721 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
723 } catch (Exception e) {
724 logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile failed", e);
725 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
729 @SuppressWarnings("unchecked")
730 @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class)
731 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.PUT, produces = "application/json")
732 public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
733 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
734 PortalRestResponse<String> result = null;
735 Map<String, Object> res = getMethod(request, response);
737 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
739 } catch (Exception e) {
740 logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile failed", e);
741 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
745 @SuppressWarnings("unchecked")
746 @ApiOperation(value = "Processes a request to delete one or more application roles for one specified user who has roles.", response = PortalRestResponse.class)
747 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.DELETE, produces = "application/json")
748 public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
749 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
750 PortalRestResponse<String> result = null;
751 Map<String, Object> res = getMethod(request, response);
753 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
755 } catch (Exception e) {
756 logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile failed", e);
757 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
761 @SuppressWarnings("unchecked")
762 @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class)
763 @RequestMapping(value = { "/v3/ticketevent" }, method = RequestMethod.POST)
764 public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
765 @RequestBody String ticketEventJson) throws Exception {
766 PortalRestResponse<String> result = null;
767 Map<String, Object> res = getMethod(request, response);
769 result = (PortalRestResponse<String>) invokeMethod(res, request, response, ticketEventJson);
771 } catch (Exception e) {
772 logger.error(EELFLoggerDelegate.errorLogger, "handleRequest failed", e);
773 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
777 @SuppressWarnings("unchecked")
778 @ApiOperation(value = "Creates a new user as a Portal administrator.", response = PortalRestResponse.class)
779 @RequestMapping(value = "/v3/portalAdmin", method = RequestMethod.POST, produces = "application/json")
781 public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response,
782 @RequestBody EPUser epUser) {
783 PortalRestResponse<String> result = null;
784 Map<String, Object> res = getMethod(request, response);
786 result = (PortalRestResponse<String>) invokeMethod(res, request, response, epUser);
788 } catch (Exception e) {
789 logger.error(EELFLoggerDelegate.errorLogger, "postPortalAdmin failed", e);
790 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
794 @ApiOperation(value = "Gets the specified application that is on-boarded in Portal.", response = OnboardingApp.class)
795 @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.GET, produces = "application/json")
797 public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
798 @PathVariable("appId") Long appId) {
799 OnboardingApp result = new OnboardingApp();
800 Map<String, Object> res = getMethod(request, response);
802 result = (OnboardingApp) invokeMethod(res, request, response, appId);
803 } catch (Exception e) {
804 logger.error(EELFLoggerDelegate.errorLogger, "getOnboardAppExternal failed", e);
809 @SuppressWarnings("unchecked")
810 @ApiOperation(value = "Adds a new application to Portal.", response = PortalRestResponse.class)
811 @RequestMapping(value = { "/v3/onboardApp" }, method = RequestMethod.POST, produces = "application/json")
813 public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
814 @RequestBody OnboardingApp newOnboardApp) {
815 PortalRestResponse<String> result = new PortalRestResponse<>();
816 Map<String, Object> res = getMethod(request, response);
818 result = (PortalRestResponse<String>) invokeMethod(res, request, response, newOnboardApp);
820 } catch (Exception e) {
821 logger.error(EELFLoggerDelegate.errorLogger, "postOnboardAppExternal failed", e);
822 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
827 @SuppressWarnings("unchecked")
828 @ApiOperation(value = "Updates information about an on-boarded application in Portal.", response = PortalRestResponse.class)
829 @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.PUT, produces = "application/json")
831 public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
832 @PathVariable("appId") Long appId, @RequestBody OnboardingApp oldOnboardApp) {
833 PortalRestResponse<String> result = new PortalRestResponse<>();
834 Map<String, Object> res = getMethod(request, response);
836 result = (PortalRestResponse<String>) invokeMethod(res, request, response, appId, oldOnboardApp);
838 } catch (Exception e) {
839 logger.error(EELFLoggerDelegate.errorLogger, "putOnboardAppExternal failed", e);
840 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
844 @ApiOperation(value = "Creates a Portal user notification for roles identified in the content from an external application.", response = PortalAPIResponse.class)
845 @RequestMapping(value = { "/v3/publishNotification" }, method = RequestMethod.POST, produces = "application/json")
847 public PortalAPIResponse publishNotification(HttpServletRequest request,
848 @RequestBody EpNotificationItem notificationItem, HttpServletResponse response) throws Exception {
849 PortalAPIResponse result = new PortalAPIResponse(true, "success");
850 Map<String, Object> res = getMethod(request, response);
852 result = (PortalAPIResponse) invokeMethod(res, request, response, notificationItem);
854 } catch (Exception e) {
855 logger.error(EELFLoggerDelegate.errorLogger, "publishNotification failed", e);
856 return new PortalAPIResponse(false, e.getMessage());
860 @SuppressWarnings("unchecked")
861 @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer = "List")
862 @RequestMapping(value = { "/v3/getFavorites" }, method = RequestMethod.GET, produces = "application/json")
863 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
864 HttpServletResponse response) throws Exception {
865 List<FavoritesFunctionalMenuItemJson> favorites = null;
866 Map<String, Object> res = getMethod(request, response);
868 favorites = (List<FavoritesFunctionalMenuItemJson>) invokeMethod(res, request, response);
869 } catch (Exception e) {
870 logger.error(EELFLoggerDelegate.errorLogger, "getFavoritesForUser failed", e);
875 @SuppressWarnings("unchecked")
876 @ApiOperation(value = "Gets functional menu items appropriate for the current user.", response = FunctionalMenuItem.class, responseContainer = "List")
877 @RequestMapping(value = {
878 "/v3/functionalMenuItemsForUser" }, method = RequestMethod.GET, produces = "application/json")
879 public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request,
880 HttpServletResponse response) throws Exception {
881 List<FunctionalMenuItem> fnMenuItems = null;
882 Map<String, Object> res = getMethod(request, response);
884 fnMenuItems = (List<FunctionalMenuItem>) invokeMethod(res, request, response);
885 } catch (Exception e) {
886 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser failed", e);
892 @ApiOperation(value = "Gets MechId roles", response = String.class, responseContainer = "List")
893 @RequestMapping(value = { "/v3/systemUser" }, method = RequestMethod.GET, produces = "application/json")
894 public List<AAFPermission> getSystemUserPerms(HttpServletRequest request, HttpServletResponse response) throws Exception {
895 List<AAFPermission> permsList = null;
896 Map<String, Object> res = getMethod(request, response);
898 permsList = (List<AAFPermission>) invokeMethod(res, request, response);
899 } catch (Exception e) {
900 logger.error(EELFLoggerDelegate.errorLogger, "getSystemUserPerms failed", e);
905 @ApiOperation(value = "Update role description in external auth system for an application.", response = PortalRestResponse.class, responseContainer = "Json")
906 @RequestMapping(value = { "/v3/update/app/roleDescription" }, method = RequestMethod.PUT, produces = "application/json")
907 public PortalRestResponse<String> updateAppRoleDescription(HttpServletRequest request, HttpServletResponse response) throws Exception {
908 PortalRestResponse<String> result = null;
909 Map<String, Object> res = getMethod(request, response);
911 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
913 } catch (Exception e) {
914 logger.error(EELFLoggerDelegate.errorLogger, "updateAppRoleDescription failed", e);
915 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");