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 com.fasterxml.jackson.databind.ObjectMapper;
40 import io.swagger.annotations.ApiOperation;
41 import java.lang.reflect.InvocationTargetException;
42 import java.lang.reflect.Method;
43 import java.util.ArrayList;
44 import java.util.Arrays;
45 import java.util.Collections;
46 import java.util.HashMap;
47 import java.util.List;
49 import java.util.jar.Attributes;
50 import java.util.regex.Matcher;
51 import java.util.regex.Pattern;
52 import javax.servlet.http.HttpServletRequest;
53 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.portalapp.validation.DataValidator;
71 import org.onap.portalapp.validation.SecureString;
72 import org.onap.portalsdk.core.domain.Role;
73 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
74 import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
75 import org.onap.portalsdk.core.restful.domain.EcompRole;
76 import org.onap.portalsdk.core.restful.domain.EcompUser;
77 import org.springframework.beans.BeansException;
78 import org.springframework.beans.factory.annotation.Autowired;
79 import org.springframework.context.ApplicationContext;
80 import org.springframework.context.ApplicationContextAware;
81 import org.springframework.context.annotation.Configuration;
82 import org.springframework.context.annotation.EnableAspectJAutoProxy;
83 import org.springframework.web.bind.annotation.PathVariable;
84 import org.springframework.web.bind.annotation.RequestBody;
85 import org.springframework.web.bind.annotation.RequestMapping;
86 import org.springframework.web.bind.annotation.RequestMethod;
87 import org.springframework.web.bind.annotation.RequestParam;
88 import org.springframework.web.bind.annotation.ResponseBody;
89 import org.springframework.web.bind.annotation.RestController;
92 @RequestMapping("/auxapi")
94 @EnableAspectJAutoProxy
96 public class AuxApiRequestMapperController implements ApplicationContextAware, BasicAuthenticationController {
98 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AuxApiRequestMapperController.class);
99 private DataValidator dataValidator = new DataValidator();
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 {
112 SecureString secureLoginId = new SecureString(loginId);
113 if (!dataValidator.isValid(secureLoginId))
114 return "Provided data is not valid";
118 Map<String, Object> res = getMethod(request, response);
119 String answer = null;
121 answer = (String) invokeMethod(res, request, response, loginId);
122 } catch (Exception e) {
123 logger.error(EELFLoggerDelegate.errorLogger, "getUser failed", e);
128 @SuppressWarnings("unchecked")
129 @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
130 @RequestMapping(value = { "/v3/roles" }, method = RequestMethod.GET, produces = "application/json")
131 public List<CentralV2Role> getRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
132 Map<String, Object> res = getMethod(request, response);
134 List<CentralV2Role> answer = null;
136 answer = (List<CentralV2Role>) invokeMethod(res, request, response);
137 } catch (Exception e) {
138 logger.error(EELFLoggerDelegate.errorLogger, "getRoles failed", e);
143 @SuppressWarnings("unchecked")
144 @ApiOperation(value = "Saves role for an application.", response = PortalRestResponse.class, responseContainer = "Json")
145 @RequestMapping(value = { "/v3/role" }, method = RequestMethod.POST, produces = "application/json")
146 public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response,
147 @RequestBody Role role) throws Exception {
148 Map<String, Object> res = getMethod(request, response);
149 PortalRestResponse<String> out = null;
151 out = (PortalRestResponse<String>) invokeMethod(res, request, response, role);
152 } catch (Exception e) {
153 logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e);
154 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
159 @ApiOperation(value = "Gets v2 role information for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
160 @RequestMapping(value = { "/v3/role/{role_id}" }, method = RequestMethod.GET, produces = "application/json")
161 public CentralV2Role getRoleInfo(HttpServletRequest request, HttpServletResponse response,
162 @PathVariable("role_id") Long roleId) throws Exception {
163 Map<String, Object> res = getMethod(request, response);
164 CentralV2Role role = null;
166 role = (CentralV2Role) invokeMethod(res, request, response, roleId);
167 } catch (Exception e) {
168 logger.error(EELFLoggerDelegate.errorLogger, "getRoleInfo failed", e);
174 @SuppressWarnings("unchecked")
175 @ApiOperation(value = "Gets all active Users of application", response = String.class, responseContainer = "Json")
176 @RequestMapping(value = { "/v3/users" }, method = RequestMethod.GET, produces = "application/json")
177 public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response)
179 Map<String, Object> res = getMethod(request, response);
180 List<EcompUser> users = null;
182 users = (List<EcompUser>) invokeMethod(res, request, response);
183 } catch (Exception e) {
184 logger.error(EELFLoggerDelegate.errorLogger, "getUsersOfApplication failed", e);
189 @SuppressWarnings("unchecked")
190 @ApiOperation(value = "Gets all role functions for an application which is upgraded to newer version.", response = CentralV2RoleFunction.class, responseContainer = "Json")
191 @RequestMapping(value = { "/v3/functions" }, method = RequestMethod.GET, produces = "application/json")
192 public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
194 Map<String, Object> res = getMethod(request, response);
195 List<CentralV2RoleFunction> roleFunctionsList = null;
197 roleFunctionsList = (List<CentralV2RoleFunction>) invokeMethod(res, request, response);
198 } catch (Exception e) {
199 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunctionsList failed", e);
201 return roleFunctionsList;
204 @ApiOperation(value = "Gets role information for an application provided by function code.", response = CentralV2RoleFunction.class, responseContainer = "Json")
205 @RequestMapping(value = { "/v3/function/{code}" }, method = RequestMethod.GET, produces = "application/json")
206 public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response,
207 @PathVariable("code") String code) throws Exception {
209 SecureString secureCode = new SecureString(code);
210 if (!dataValidator.isValid(secureCode))
211 return new CentralV2RoleFunction();
214 Map<String, Object> res = getMethod(request, response);
215 CentralV2RoleFunction roleFunction = null;
217 roleFunction = (CentralV2RoleFunction) invokeMethod(res, request, response, code);
218 } catch (Exception e) {
219 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e);
224 @SuppressWarnings("unchecked")
225 @ApiOperation(value = "Saves role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
226 @RequestMapping(value = { "/v3/roleFunction" }, method = RequestMethod.POST, produces = "application/json")
227 public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response,
228 @RequestBody String roleFunc) throws Exception {
229 PortalRestResponse<String> result = null;
232 SecureString secureRoleFunc = new SecureString(roleFunc);
233 if(!dataValidator.isValid(secureRoleFunc))
234 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
237 Map<String, Object> res = getMethod(request, response);
239 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleFunc);
241 } catch (Exception e) {
242 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e);
243 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
247 @SuppressWarnings("unchecked")
248 @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
249 @RequestMapping(value = { "/v3/roleFunction/{code}" }, method = RequestMethod.DELETE, produces = "application/json")
250 public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response,
251 @PathVariable("code") String code) throws Exception {
252 PortalRestResponse<String> result = null;
255 SecureString secureCode = new SecureString(code);
256 if(!dataValidator.isValid(secureCode))
257 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
260 Map<String, Object> res = getMethod(request, response);
262 result = (PortalRestResponse<String>) invokeMethod(res, request, response, code);
264 } catch (Exception e) {
265 logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction failed", e);
266 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
270 @SuppressWarnings("unchecked")
271 @ApiOperation(value = "deletes roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
272 @RequestMapping(value = { "/v3/deleteRole/{roleId}" }, method = RequestMethod.DELETE, produces = "application/json")
273 public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response,
274 @PathVariable("roleId") Long roleId) throws Exception {
275 PortalRestResponse<String> result = null;
276 Map<String, Object> res = getMethod(request, response);
278 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
280 } catch (Exception e) {
281 logger.error(EELFLoggerDelegate.errorLogger, "deleteRole failed", e);
282 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
286 @SuppressWarnings("unchecked")
287 @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
288 @RequestMapping(value = { "/v3/activeRoles" }, method = RequestMethod.GET, produces = "application/json")
289 public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response)
291 List<CentralV2Role> cenRole = null;
292 Map<String, Object> res = getMethod(request, response);
294 cenRole = (List<CentralV2Role>) invokeMethod(res, request, response);
295 } catch (Exception e) {
296 logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
301 @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List")
302 @RequestMapping(value = { "/v4/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
303 public String getEcompUser(HttpServletRequest request, HttpServletResponse response,
304 @PathVariable("loginId") String loginId) throws Exception {
305 Map<String, Object> res = getMethod(request, response);
308 SecureString secureLoginId = new SecureString(loginId);
310 if (!dataValidator.isValid(secureLoginId))
314 String answer = null;
316 answer = (String) invokeMethod(res, request, response, loginId);
317 } catch (Exception e) {
318 logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e);
323 @SuppressWarnings("unchecked")
324 @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List")
325 @RequestMapping(value = { "/v4/roles" }, method = RequestMethod.GET, produces = "application/json")
326 public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response)
328 Map<String, Object> res = getMethod(request, response);
329 List<EcompRole> answer = null;
331 answer = (List<EcompRole>) invokeMethod(res, request, response);
332 } catch (Exception e) {
333 logger.error(EELFLoggerDelegate.errorLogger, "getEcompRolesOfApplication failed", e);
338 @ApiOperation(value = "Gets session slot-check interval, a duration in milliseconds.", response = Integer.class)
339 @RequestMapping(value = {
340 "/v3/getSessionSlotCheckInterval" }, method = RequestMethod.GET, produces = "application/json")
341 public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response)
343 Map<String, Object> res = getMethod(request, response);
346 ans = (Integer) invokeMethod(res, request, response);
347 } catch (Exception e) {
348 logger.error(EELFLoggerDelegate.errorLogger, "getSessionSlotCheckInterval failed", e);
353 @ApiOperation(value = "Extends session timeout values for all on-boarded applications.", response = Boolean.class)
354 @RequestMapping(value = { "/v3/extendSessionTimeOuts" }, method = RequestMethod.POST)
355 public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response,
356 @RequestParam String sessionMap) throws Exception {
358 if (sessionMap!=null){
359 SecureString secureSessionMap = new SecureString(sessionMap);
360 if (!dataValidator.isValid(secureSessionMap)){
365 Map<String, Object> res = getMethod(request, response);
368 ans = (Boolean) invokeMethod(res, request, response, sessionMap);
369 } catch (Exception e) {
370 logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts failed", e);
375 @ApiOperation(value = "Gets javascript with functions that support gathering and reporting web analytics.", response = String.class)
376 @RequestMapping(value = { "/v3/analytics" }, method = RequestMethod.GET, produces = "application/javascript")
377 public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception {
378 Map<String, Object> res = getMethod(request, response);
381 ans = (String) invokeMethod(res, request, response);
382 } catch (Exception e) {
383 logger.error(EELFLoggerDelegate.errorLogger, "getAnalyticsScript failed", e);
388 @RequestMapping(value = { "/v3/storeAnalytics" }, method = RequestMethod.POST, produces = "application/json")
390 @ApiOperation(value = "Accepts data from partner applications with web analytics data.", response = PortalAPIResponse.class)
391 public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response,
392 @RequestBody Analytics analyticsMap) throws Exception {
394 if (analyticsMap!=null){
395 if (!dataValidator.isValid(analyticsMap))
396 return new PortalAPIResponse(false, "analyticsScript is not valid");
399 Map<String, Object> res = getMethod(request, response);
400 PortalAPIResponse ans = new PortalAPIResponse(true, "error");
402 ans = (PortalAPIResponse) invokeMethod(res, request, response, analyticsMap);
403 } catch (Exception e) {
404 logger.error(EELFLoggerDelegate.errorLogger, "storeAnalyticsScript failed", e);
410 @SuppressWarnings("unchecked")
411 @ApiOperation(value = "Bulk upload functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
412 @RequestMapping(value = {
413 "/v3/upload/portal/functions" }, method = RequestMethod.POST, produces = "application/json")
414 public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response)
416 PortalRestResponse<String> result = null;
417 Map<String, Object> res = getMethod(request, response);
419 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
421 } catch (Exception e) {
422 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e);
423 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
428 @SuppressWarnings("unchecked")
429 @ApiOperation(value = "Bulk upload roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
430 @RequestMapping(value = { "/v3/upload/portal/roles" }, method = RequestMethod.POST, produces = "application/json")
431 public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response)
433 PortalRestResponse<String> result = null;
434 Map<String, Object> res = getMethod(request, response);
436 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
438 } catch (Exception e) {
439 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e);
440 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
444 @SuppressWarnings("unchecked")
445 @ApiOperation(value = "Bulk upload role functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
446 @RequestMapping(value = {
447 "/v3/upload/portal/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
448 public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response)
450 PortalRestResponse<String> result = null;
451 Map<String, Object> res = getMethod(request, response);
453 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
455 } catch (Exception e) {
456 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoleFunctions failed", e);
457 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
461 @SuppressWarnings("unchecked")
462 @ApiOperation(value = "Bulk upload user roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
463 @RequestMapping(value = {
464 "/v3/upload/portal/userRoles" }, method = RequestMethod.POST, produces = "application/json")
465 public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response)
467 PortalRestResponse<String> result = null;
468 Map<String, Object> res = getMethod(request, response);
470 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
472 } catch (Exception e) {
473 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUserRoles failed", e);
474 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
479 @SuppressWarnings("unchecked")
480 @ApiOperation(value = "Bulk upload users for renamed role of an application.", response = PortalRestResponse.class, responseContainer = "Json")
481 @RequestMapping(value = {
482 "/v3/upload/portal/userRole/{roleId}" }, method = RequestMethod.POST, produces = "application/json")
483 public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request,
484 HttpServletResponse response, @PathVariable Long roleId) throws Exception {
485 PortalRestResponse<String> result = null;
486 Map<String, Object> res = getMethod(request, response);
488 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
490 } catch (Exception e) {
491 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUsersSingleRole failed", e);
492 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
496 @SuppressWarnings("unchecked")
497 @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
498 @RequestMapping(value = {
499 "/v3/upload/partner/functions" }, method = RequestMethod.POST, produces = "application/json")
500 public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request,
501 HttpServletResponse response) throws Exception {
502 PortalRestResponse<String> result = null;
503 Map<String, Object> res = getMethod(request, response);
505 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
507 } catch (Exception e) {
508 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerFunctions failed", e);
509 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
514 @SuppressWarnings("unchecked")
515 @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
516 @RequestMapping(value = { "/v3/upload/partner/roles" }, method = RequestMethod.POST, produces = "application/json")
517 public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response,
518 @RequestBody List<Role> upload) throws Exception {
519 PortalRestResponse<String> result = null;
520 Map<String, Object> res = getMethod(request, response);
522 result = (PortalRestResponse<String>) invokeMethod(res, request, response, upload);
524 } catch (Exception e) {
525 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoles failed", e);
526 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
530 @SuppressWarnings("unchecked")
531 @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
532 @RequestMapping(value = {
533 "/v3/upload/partner/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
534 public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request,
535 HttpServletResponse response) throws Exception {
536 PortalRestResponse<String> result = null;
537 Map<String, Object> res = getMethod(request, response);
539 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
541 } catch (Exception e) {
542 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoleFunctions failed", e);
543 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
547 @SuppressWarnings("unchecked")
548 @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json")
549 @RequestMapping(value = { "/v3/menuFunctions" }, method = RequestMethod.GET, produces = "application/json")
550 public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception {
551 List<String> functionsList = null;
552 Map<String, Object> res = getMethod(request, response);
554 functionsList = (List<String>) invokeMethod(res, request, response);
555 } catch (Exception e) {
556 logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctions failed", e);
558 return functionsList;
561 private String getPatchNumber() {
562 String response = "0";
564 Attributes attributes = manifestService.getWebappManifest();
565 response = attributes.getValue("Build-Number");
566 } catch (Exception ex) {
567 logger.error(EELFLoggerDelegate.errorLogger, "getPatchNumber failed", ex);
572 @SuppressWarnings("rawtypes")
573 private List<Object> getObject(HttpServletRequest request, HttpServletResponse response) {
574 Map<String, Object> beans = context.getBeansWithAnnotation(ApiVersion.class);
575 @SuppressWarnings("unchecked")
576 List<Object> beansList = new ArrayList(beans.values());
581 private Map<String, Object> getMethod(HttpServletRequest request, HttpServletResponse response) {
582 Method finalmethod = null;
583 String url = request.getRequestURI();
586 Object currentObject = null;
587 Map<String, Object> res = new HashMap<String, Object>();
588 String[] uriArray = url.split("/auxapi");
589 List<Integer> minorversionList = new ArrayList<>();
590 if (uriArray.length > 1) {
591 service = uriArray[1];
593 int first = service.indexOf("/");
594 int second = service.indexOf("/", first + 1);
595 version = service.substring(first + 1, second);
596 int min = minorVersion;
597 if (request.getHeader("MinorVersion") != null) {
598 min = Integer.parseInt(request.getHeader("MinorVersion"));
600 res.put("min", version+"."+min);
601 res.put("service", service);
602 List<Object> objList = getObject(request, response);
603 String requestedApiMethodType = request.getMethod();
604 String majorVersion = latestMajorVersionOfService(objList, service, version, requestedApiMethodType);
605 int latestMinorVersion = latestMinorVersionOfService(objList, service, version, requestedApiMethodType);
606 res.put("majorVersion", majorVersion);
607 res.put("latestMinorVersion", String.valueOf(latestMinorVersion));
608 outerloop: for (Object obj : objList) {
609 final List<Method> allMethods = getAllMethodsOfClass(obj);
610 for (final Method method : allMethods) {
611 if (method.isAnnotationPresent(ApiVersion.class)) {
612 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
613 Pattern p = Pattern.compile(annotInstance.service(),
614 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
615 Matcher matcher = p.matcher(service);
616 boolean b = matcher.matches();
617 logger.debug(EELFLoggerDelegate.debugLogger, "Requested Servie is:" + service
618 + "Requested MinVersion is:" + min + "Requested MajorVersion is: " + version);
619 if (annotInstance.max().equals(version) && b && annotInstance.min() == min
620 && annotInstance.method().equals(request.getMethod())) {
621 finalmethod = method;
623 res.put("method", method);
633 private String latestMajorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
634 String requestedApiMethodType) {
635 Integer majorVersion = 0;
636 String serviceEndPoint = service;
637 int firstindex = serviceEndPoint.indexOf("/");
638 int secondindex = serviceEndPoint.indexOf("/", firstindex + 1);
639 serviceEndPoint = serviceEndPoint.substring(secondindex + 1);
641 List<Integer> latestMajorVersionList = new ArrayList<>();
642 for (Object obj : objList) {
643 final List<Method> allMethods = getAllMethodsOfClass(obj);
644 for (final Method method : allMethods) {
645 if (method.isAnnotationPresent(ApiVersion.class)) {
646 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
647 String endpoint = annotInstance.service();
648 int first = endpoint.indexOf("/");
649 int second = endpoint.indexOf("/", first + 1);
650 endpoint = endpoint.substring(second + 1);
651 Pattern p = Pattern.compile(endpoint,
652 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
653 Matcher matcher = p.matcher(serviceEndPoint);
654 boolean b = matcher.matches();
655 if (b && annotInstance.method().equals(requestedApiMethodType)) {
656 int index1 = annotInstance.service().indexOf("/");
657 int index2 = annotInstance.service().indexOf("/", index1 + 1);
658 String majorversion = annotInstance.service().substring(index1 + 2, index2);
659 latestMajorVersionList.add(Integer.parseInt(majorversion));
664 majorVersion = Collections.max(latestMajorVersionList);
665 String majorVersionWithLastestMin = "/v"+String.valueOf(majorVersion)+"/"+serviceEndPoint;
666 int latestMinorVersion = latestMinorVersionOfService(objList, majorVersionWithLastestMin, "v"+String.valueOf(majorVersion), requestedApiMethodType);
667 return majorVersion+"."+latestMinorVersion;
670 private List<Method> getAllMethodsOfClass(Object obj) {
671 List<Method> allMethods = new ArrayList<>();
672 Class<?> objClz = obj.getClass();
673 if (org.springframework.aop.support.AopUtils.isAopProxy(obj)) {
674 objClz = org.springframework.aop.support.AopUtils.getTargetClass(obj);
676 allMethods = new ArrayList<Method>(Arrays.asList(objClz.getMethods()));
677 allMethods.removeIf(s -> !(s.isAnnotationPresent(ApiVersion.class)));
681 private Integer latestMinorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
682 String requestedApiMethodType) {
683 Integer minVersion = 0;
684 String serviceEndPoint = service;
685 List<Integer> latestMinorVersionList = new ArrayList<>();
686 for (Object obj : objList) {
687 final List<Method> allMethods = getAllMethodsOfClass(obj);
688 for (final Method method : allMethods) {
689 if (method.isAnnotationPresent(ApiVersion.class)) {
690 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
691 String endpoint = annotInstance.service();
693 Pattern p = Pattern.compile(endpoint,
694 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
695 Matcher matcher = p.matcher(serviceEndPoint);
696 boolean b = matcher.matches();
697 if (annotInstance.max().equals(reuqestedVersion) && b
698 && annotInstance.method().equals(requestedApiMethodType)) {
699 int minorversion = annotInstance.min();
700 latestMinorVersionList.add(minorversion);
705 minVersion = Collections.max(latestMinorVersionList);
709 private HttpServletResponse setResponse(HttpServletResponse response, String requestedMinVersion,
710 String majorVersion, String latestMinorVersion, String service) {
711 response.setHeader("X-MinorVersion", requestedMinVersion.toUpperCase());
712 response.setHeader("X-PatchVersion", getPatchNumber());
713 response.setHeader("X-LatestVersion", "V"+majorVersion);
721 * method parameters(Maintain HttpServletRequest at 0th position
722 * and HttpServletResponse at 1th position in args array)
726 private Object invokeMethod(Map<String, Object> res, Object... args) throws Exception {
727 Method method = (Method) res.get("method");
728 Object obj = res.get("Obj");
729 Object responseObj = null;
730 String min = res.get("min").toString();
731 String majorVersion = res.get("majorVersion").toString();
732 String latestMinorVersion = res.get("latestMinorVersion").toString();
733 String service = res.get("service").toString();
734 HttpServletRequest request = (HttpServletRequest) args[0];
735 HttpServletResponse response = (HttpServletResponse) args[1];
736 setResponse(response, min, majorVersion, latestMinorVersion, service);
737 final Map<String, String> errorMap = new HashMap<>();
738 ObjectMapper mapper = new ObjectMapper();
741 if (method != null && obj != null) {
742 responseObj = method.invoke(obj, args);
744 errorMap.put("error", "Requested api is not available");
745 reason = mapper.writeValueAsString(errorMap);
746 response.getWriter().write(reason);
747 logger.debug(EELFLoggerDelegate.debugLogger, "Requested api " + request.getRequestURI()
748 + "is not available with minorVersion " + request.getHeader("MinorVersion"));
749 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
751 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
752 logger.error(EELFLoggerDelegate.errorLogger, "Method :" + method + "invocation failed", e);
758 public void setApplicationContext(ApplicationContext context) throws BeansException {
759 this.context = context;
762 @SuppressWarnings("unchecked")
763 @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class)
764 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.POST, produces = "application/json")
765 public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
766 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
768 if (extSysUser!=null){
769 if (!dataValidator.isValid(extSysUser))
770 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
773 PortalRestResponse<String> result = null;
774 Map<String, Object> res = getMethod(request, response);
776 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
778 } catch (Exception e) {
779 logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile failed", e);
780 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
784 @SuppressWarnings("unchecked")
785 @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class)
786 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.PUT, produces = "application/json")
787 public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
788 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
790 if (extSysUser!=null){
791 if (!dataValidator.isValid(extSysUser))
792 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
795 PortalRestResponse<String> result = null;
796 Map<String, Object> res = getMethod(request, response);
798 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
800 } catch (Exception e) {
801 logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile failed", e);
802 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
806 @SuppressWarnings("unchecked")
807 @ApiOperation(value = "Processes a request to delete one or more application roles for one specified user who has roles.", response = PortalRestResponse.class)
808 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.DELETE, produces = "application/json")
809 public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
810 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
812 if (extSysUser!=null){
813 if (!dataValidator.isValid(extSysUser))
814 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
817 PortalRestResponse<String> result = null;
818 Map<String, Object> res = getMethod(request, response);
820 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
822 } catch (Exception e) {
823 logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile failed", e);
824 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
828 @SuppressWarnings("unchecked")
829 @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class)
830 @RequestMapping(value = { "/v3/ticketevent" }, method = RequestMethod.POST)
831 public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
832 @RequestBody String ticketEventJson) throws Exception {
834 if (ticketEventJson!=null){
835 SecureString secureTicketEventJson = new SecureString(ticketEventJson);
836 if (!dataValidator.isValid(secureTicketEventJson))
837 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ticketEventJson is not valid", "Failed");
840 PortalRestResponse<String> result = null;
841 Map<String, Object> res = getMethod(request, response);
843 result = (PortalRestResponse<String>) invokeMethod(res, request, response, ticketEventJson);
845 } catch (Exception e) {
846 logger.error(EELFLoggerDelegate.errorLogger, "handleRequest failed", e);
847 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
851 @SuppressWarnings("unchecked")
852 @ApiOperation(value = "Creates a new user as a Portal administrator.", response = PortalRestResponse.class)
853 @RequestMapping(value = "/v3/portalAdmin", method = RequestMethod.POST, produces = "application/json")
855 public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response,
856 @RequestBody EPUser epUser) {
859 if (!dataValidator.isValid(epUser))
860 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "EPUser is not valid", "Failed");
863 PortalRestResponse<String> result = null;
864 Map<String, Object> res = getMethod(request, response);
866 result = (PortalRestResponse<String>) invokeMethod(res, request, response, epUser);
868 } catch (Exception e) {
869 logger.error(EELFLoggerDelegate.errorLogger, "postPortalAdmin failed", e);
870 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
874 @ApiOperation(value = "Gets the specified application that is on-boarded in Portal.", response = OnboardingApp.class)
875 @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.GET, produces = "application/json")
877 public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
878 @PathVariable("appId") Long appId) {
879 OnboardingApp result = new OnboardingApp();
880 Map<String, Object> res = getMethod(request, response);
882 result = (OnboardingApp) invokeMethod(res, request, response, appId);
883 } catch (Exception e) {
884 logger.error(EELFLoggerDelegate.errorLogger, "getOnboardAppExternal failed", e);
889 @SuppressWarnings("unchecked")
890 @ApiOperation(value = "Adds a new application to Portal.", response = PortalRestResponse.class)
891 @RequestMapping(value = { "/v3/onboardApp" }, method = RequestMethod.POST, produces = "application/json")
893 public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
894 @RequestBody OnboardingApp newOnboardApp) {
896 if (newOnboardApp!=null){
897 if (!dataValidator.isValid(newOnboardApp))
898 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
901 PortalRestResponse<String> result = new PortalRestResponse<>();
902 Map<String, Object> res = getMethod(request, response);
904 result = (PortalRestResponse<String>) invokeMethod(res, request, response, newOnboardApp);
906 } catch (Exception e) {
907 logger.error(EELFLoggerDelegate.errorLogger, "postOnboardAppExternal failed", e);
908 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
913 @SuppressWarnings("unchecked")
914 @ApiOperation(value = "Updates information about an on-boarded application in Portal.", response = PortalRestResponse.class)
915 @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.PUT, produces = "application/json")
917 public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
918 @PathVariable("appId") Long appId, @RequestBody OnboardingApp oldOnboardApp) {
920 if (oldOnboardApp!=null){
921 if (!dataValidator.isValid(oldOnboardApp))
922 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
925 PortalRestResponse<String> result;
926 Map<String, Object> res = getMethod(request, response);
928 result = (PortalRestResponse<String>) invokeMethod(res, request, response, appId, oldOnboardApp);
930 } catch (Exception e) {
931 logger.error(EELFLoggerDelegate.errorLogger, "putOnboardAppExternal failed", e);
932 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
936 @ApiOperation(value = "Creates a Portal user notification for roles identified in the content from an external application.", response = PortalAPIResponse.class)
937 @RequestMapping(value = { "/v3/publishNotification" }, method = RequestMethod.POST, produces = "application/json")
939 public PortalAPIResponse publishNotification(HttpServletRequest request,
940 @RequestBody EpNotificationItem notificationItem, HttpServletResponse response) {
942 if (notificationItem!=null){
943 if (!dataValidator.isValid(notificationItem))
944 return new PortalAPIResponse(false, "EpNotificationItem is not valid");
947 Map<String, Object> res = getMethod(request, response);
949 return (PortalAPIResponse) invokeMethod(res, request, response, notificationItem);
950 } catch (Exception e) {
951 logger.error(EELFLoggerDelegate.errorLogger, "publishNotification failed", e);
952 return new PortalAPIResponse(false, e.getMessage());
956 @SuppressWarnings("unchecked")
957 @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer = "List")
958 @RequestMapping(value = { "/v3/getFavorites" }, method = RequestMethod.GET, produces = "application/json")
959 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
960 HttpServletResponse response) throws Exception {
961 List<FavoritesFunctionalMenuItemJson> favorites = null;
962 Map<String, Object> res = getMethod(request, response);
964 favorites = (List<FavoritesFunctionalMenuItemJson>) invokeMethod(res, request, response);
965 } catch (Exception e) {
966 logger.error(EELFLoggerDelegate.errorLogger, "getFavoritesForUser failed", e);
971 @SuppressWarnings("unchecked")
972 @ApiOperation(value = "Gets functional menu items appropriate for the current user.", response = FunctionalMenuItem.class, responseContainer = "List")
973 @RequestMapping(value = {
974 "/v3/functionalMenuItemsForUser" }, method = RequestMethod.GET, produces = "application/json")
975 public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request,
976 HttpServletResponse response) throws Exception {
977 List<FunctionalMenuItem> fnMenuItems = null;
978 Map<String, Object> res = getMethod(request, response);
980 fnMenuItems = (List<FunctionalMenuItem>) invokeMethod(res, request, response);
981 } catch (Exception e) {
982 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser failed", e);
988 @ApiOperation(value = "Gets MechId roles", response = String.class, responseContainer = "List")
989 @RequestMapping(value = { "/v3/systemUser" }, method = RequestMethod.GET, produces = "application/json")
990 public List<AAFPermission> getSystemUserPerms(HttpServletRequest request, HttpServletResponse response) throws Exception {
991 List<AAFPermission> permsList = null;
992 Map<String, Object> res = getMethod(request, response);
994 permsList = (List<AAFPermission>) invokeMethod(res, request, response);
995 } catch (Exception e) {
996 logger.error(EELFLoggerDelegate.errorLogger, "getSystemUserPerms failed", e);
1001 @ApiOperation(value = "Update role description in external auth system for an application.", response = PortalRestResponse.class, responseContainer = "Json")
1002 @RequestMapping(value = { "/v3/update/app/roleDescription" }, method = RequestMethod.PUT, produces = "application/json")
1003 public PortalRestResponse<String> updateAppRoleDescription(HttpServletRequest request, HttpServletResponse response) throws Exception {
1004 PortalRestResponse<String> result = null;
1005 Map<String, Object> res = getMethod(request, response);
1007 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
1009 } catch (Exception e) {
1010 logger.error(EELFLoggerDelegate.errorLogger, "updateAppRoleDescription failed", e);
1011 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");