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.Optional;
50 import java.util.jar.Attributes;
51 import java.util.regex.Matcher;
52 import java.util.regex.Pattern;
53 import javax.servlet.http.HttpServletRequest;
54 import javax.servlet.http.HttpServletResponse;
55 import org.onap.aaf.cadi.aaf.AAFPermission;
56 import org.onap.portalapp.annotation.ApiVersion;
57 import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser;
58 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
59 import org.onap.portalapp.portal.domain.EPUser;
60 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
61 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
62 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
63 import org.onap.portalapp.portal.service.ManifestService;
64 import org.onap.portalapp.portal.transport.Analytics;
65 import org.onap.portalapp.portal.transport.CentralUser;
66 import org.onap.portalapp.portal.transport.CentralV2Role;
67 import org.onap.portalapp.portal.transport.EpNotificationItem;
68 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
69 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
70 import org.onap.portalapp.portal.transport.OnboardingApp;
71 import org.onap.portalapp.validation.DataValidator;
72 import org.onap.portalapp.validation.SecureString;
73 import org.onap.portalsdk.core.domain.Role;
74 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
75 import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
76 import org.onap.portalsdk.core.restful.domain.EcompRole;
77 import org.onap.portalsdk.core.restful.domain.EcompUser;
78 import org.springframework.beans.BeansException;
79 import org.springframework.beans.factory.annotation.Autowired;
80 import org.springframework.context.ApplicationContext;
81 import org.springframework.context.ApplicationContextAware;
82 import org.springframework.context.annotation.Configuration;
83 import org.springframework.context.annotation.EnableAspectJAutoProxy;
84 import org.springframework.web.bind.annotation.PathVariable;
85 import org.springframework.web.bind.annotation.RequestBody;
86 import org.springframework.web.bind.annotation.RequestMapping;
87 import org.springframework.web.bind.annotation.GetMapping;
88 import org.springframework.web.bind.annotation.PostMapping;
89 import org.springframework.web.bind.annotation.PutMapping;
90 import org.springframework.web.bind.annotation.DeleteMapping;
91 import org.springframework.web.bind.annotation.RequestMethod;
92 import org.springframework.web.bind.annotation.RequestParam;
93 import org.springframework.web.bind.annotation.ResponseBody;
94 import org.springframework.web.bind.annotation.RestController;
97 @RequestMapping("/auxapi")
99 @EnableAspectJAutoProxy
101 public class AuxApiRequestMapperController implements ApplicationContextAware, BasicAuthenticationController {
103 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AuxApiRequestMapperController.class);
104 private DataValidator dataValidator = new DataValidator();
106 ApplicationContext context = null;
107 int minorVersion = 0;
110 private ManifestService manifestService;
112 @ApiOperation(value = "Gets user roles for an application which is upgraded to newer version.", response = String.class, responseContainer = "List")
113 @GetMapping(value = { "/v3/user/{loginId}" }, produces = "application/json")
114 public String getUser(HttpServletRequest request, HttpServletResponse response,
115 @PathVariable("loginId") String loginId) throws Exception {
117 SecureString secureLoginId = new SecureString(loginId);
118 if (!dataValidator.isValid(secureLoginId))
119 return "Provided data is not valid";
123 Map<String, Object> res = getMethod(request, response);
124 String answer = null;
126 answer = (String) invokeMethod(res, request, response, loginId);
127 } catch (Exception e) {
128 logger.error(EELFLoggerDelegate.errorLogger, "getUser failed", e);
133 @SuppressWarnings("unchecked")
134 @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
135 @GetMapping(value = { "/v3/roles" }, produces = "application/json")
136 public List<CentralV2Role> getRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
137 Map<String, Object> res = getMethod(request, response);
139 List<CentralV2Role> answer = null;
141 answer = (List<CentralV2Role>) invokeMethod(res, request, response);
142 } catch (Exception e) {
143 logger.error(EELFLoggerDelegate.errorLogger, "getRoles failed", e);
148 @SuppressWarnings("unchecked")
149 @ApiOperation(value = "Saves role for an application.", response = PortalRestResponse.class, responseContainer = "Json")
150 @PostMapping(value = { "/v3/role" }, produces = "application/json")
151 public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response,
152 @RequestBody Role role) throws Exception {
153 Map<String, Object> res = getMethod(request, response);
154 PortalRestResponse<String> out = null;
156 out = (PortalRestResponse<String>) invokeMethod(res, request, response, role);
157 } catch (Exception e) {
158 logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e);
159 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
164 @ApiOperation(value = "Gets v2 role information for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
165 @GetMapping(value = { "/v3/role/{role_id}" }, produces = "application/json")
166 public CentralV2Role getRoleInfo(HttpServletRequest request, HttpServletResponse response,
167 @PathVariable("role_id") Long roleId) throws Exception {
168 Map<String, Object> res = getMethod(request, response);
169 CentralV2Role role = null;
171 role = (CentralV2Role) invokeMethod(res, request, response, roleId);
172 } catch (Exception e) {
173 logger.error(EELFLoggerDelegate.errorLogger, "getRoleInfo failed", e);
179 @SuppressWarnings("unchecked")
180 @ApiOperation(value = "Gets all active Users of application", response = String.class, responseContainer = "Json")
181 @GetMapping(value = { "/v3/users" }, produces = "application/json")
182 public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response)
184 Map<String, Object> res = getMethod(request, response);
185 List<EcompUser> users = null;
187 users = (List<EcompUser>) invokeMethod(res, request, response);
188 } catch (Exception e) {
189 logger.error(EELFLoggerDelegate.errorLogger, "getUsersOfApplication failed", e);
194 @SuppressWarnings("unchecked")
195 @ApiOperation(value = "Gets all role functions for an application which is upgraded to newer version.", response = CentralV2RoleFunction.class, responseContainer = "Json")
196 @GetMapping(value = { "/v3/functions" }, produces = "application/json")
197 public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
199 Map<String, Object> res = getMethod(request, response);
200 List<CentralV2RoleFunction> roleFunctionsList = null;
202 roleFunctionsList = (List<CentralV2RoleFunction>) invokeMethod(res, request, response);
203 } catch (Exception e) {
204 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunctionsList failed", e);
206 return roleFunctionsList;
209 @ApiOperation(value = "Gets role information for an application provided by function code.", response = CentralV2RoleFunction.class, responseContainer = "Json")
210 @GetMapping(value = { "/v3/function/{code}" }, produces = "application/json")
211 public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response,
212 @PathVariable("code") String code) throws Exception {
214 SecureString secureCode = new SecureString(code);
215 if (!dataValidator.isValid(secureCode))
216 return new CentralV2RoleFunction();
219 Map<String, Object> res = getMethod(request, response);
220 CentralV2RoleFunction roleFunction = null;
222 roleFunction = (CentralV2RoleFunction) invokeMethod(res, request, response, code);
223 } catch (Exception e) {
224 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e);
229 @SuppressWarnings("unchecked")
230 @ApiOperation(value = "Saves role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
231 @PostMapping(value = { "/v3/roleFunction" }, produces = "application/json")
232 public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response,
233 @RequestBody String roleFunc) throws Exception {
235 SecureString secureRoleFunc = new SecureString(roleFunc);
236 if(!dataValidator.isValid(secureRoleFunc))
237 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
239 Optional<PortalRestResponse<String>> result = null;
240 Map<String, Object> res = getMethod(request, response);
242 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
243 if (!result.isPresent()){
244 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", new Exception("saveRoleFunction failed"));
245 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "saveRoleFunction failed", "Failed");
247 } catch (Exception e) {
248 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e);
249 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
254 @SuppressWarnings("unchecked")
255 @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
256 @DeleteMapping(value = { "/v3/roleFunction/{code}" }, produces = "application/json")
257 public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response,
258 @PathVariable("code") String code) throws Exception {
259 PortalRestResponse<String> result = null;
262 SecureString secureCode = new SecureString(code);
263 if(!dataValidator.isValid(secureCode))
264 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
267 Map<String, Object> res = getMethod(request, response);
269 result = (PortalRestResponse<String>) invokeMethod(res, request, response, code);
271 } catch (Exception e) {
272 logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction failed", e);
273 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
277 @SuppressWarnings("unchecked")
278 @ApiOperation(value = "deletes roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
279 @DeleteMapping(value = { "/v3/deleteRole/{roleId}" }, produces = "application/json")
280 public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response,
281 @PathVariable("roleId") Long roleId) throws Exception {
282 PortalRestResponse<String> result = null;
283 Map<String, Object> res = getMethod(request, response);
285 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
287 } catch (Exception e) {
288 logger.error(EELFLoggerDelegate.errorLogger, "deleteRole failed", e);
289 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
293 @SuppressWarnings("unchecked")
294 @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
295 @GetMapping(value = { "/v3/activeRoles" }, produces = "application/json")
296 public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response)
298 List<CentralV2Role> cenRole = null;
299 Map<String, Object> res = getMethod(request, response);
301 cenRole = (List<CentralV2Role>) invokeMethod(res, request, response);
302 } catch (Exception e) {
303 logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
308 @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List")
309 @GetMapping(value = { "/v4/user/{loginId}" }, produces = "application/json")
310 public String getEcompUser(HttpServletRequest request, HttpServletResponse response,
311 @PathVariable("loginId") String loginId) throws Exception {
312 Map<String, Object> res = getMethod(request, response);
315 SecureString secureLoginId = new SecureString(loginId);
317 if (!dataValidator.isValid(secureLoginId))
321 String answer = null;
323 answer = (String) invokeMethod(res, request, response, loginId);
324 } catch (Exception e) {
325 logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e);
330 @SuppressWarnings("unchecked")
331 @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List")
332 @GetMapping(value = { "/v4/roles" }, produces = "application/json")
333 public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response)
335 Map<String, Object> res = getMethod(request, response);
336 List<EcompRole> answer = null;
338 answer = (List<EcompRole>) invokeMethod(res, request, response);
339 } catch (Exception e) {
340 logger.error(EELFLoggerDelegate.errorLogger, "getEcompRolesOfApplication failed", e);
345 @ApiOperation(value = "Gets session slot-check interval, a duration in milliseconds.", response = Integer.class)
346 @GetMapping(value = {
347 "/v3/getSessionSlotCheckInterval" }, produces = "application/json")
348 public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response)
350 Map<String, Object> res = getMethod(request, response);
353 ans = (Integer) invokeMethod(res, request, response);
354 } catch (Exception e) {
355 logger.error(EELFLoggerDelegate.errorLogger, "getSessionSlotCheckInterval failed", e);
360 @ApiOperation(value = "Extends session timeout values for all on-boarded applications.", response = Boolean.class)
361 @RequestMapping(value = { "/v3/extendSessionTimeOuts" }, method = RequestMethod.POST)
362 public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response,
363 @RequestParam String sessionMap) throws Exception {
365 if (sessionMap!=null){
366 SecureString secureSessionMap = new SecureString(sessionMap);
367 if (!dataValidator.isValid(secureSessionMap)){
372 Map<String, Object> res = getMethod(request, response);
375 ans = (Boolean) invokeMethod(res, request, response, sessionMap);
376 } catch (Exception e) {
377 logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts failed", e);
382 @ApiOperation(value = "Gets javascript with functions that support gathering and reporting web analytics.", response = String.class)
383 @GetMapping(value = { "/v3/analytics" }, produces = "application/javascript")
384 public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception {
385 Map<String, Object> res = getMethod(request, response);
388 ans = (String) invokeMethod(res, request, response);
389 } catch (Exception e) {
390 logger.error(EELFLoggerDelegate.errorLogger, "getAnalyticsScript failed", e);
395 @PostMapping(value = { "/v3/storeAnalytics" }, produces = "application/json")
397 @ApiOperation(value = "Accepts data from partner applications with web analytics data.", response = PortalAPIResponse.class)
398 public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response,
399 @RequestBody Analytics analyticsMap) throws Exception {
401 if (analyticsMap!=null){
402 if (!dataValidator.isValid(analyticsMap))
403 return new PortalAPIResponse(false, "analyticsScript is not valid");
406 Map<String, Object> res = getMethod(request, response);
407 PortalAPIResponse ans = new PortalAPIResponse(true, "error");
409 ans = (PortalAPIResponse) invokeMethod(res, request, response, analyticsMap);
410 } catch (Exception e) {
411 logger.error(EELFLoggerDelegate.errorLogger, "storeAnalyticsScript failed", e);
417 @SuppressWarnings("unchecked")
418 @ApiOperation(value = "Bulk upload functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
419 @PostMapping(value = {
420 "/v3/upload/portal/functions" }, produces = "application/json")
421 public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response)
423 Optional<PortalRestResponse<String>> result = null;
424 Map<String, Object> res = getMethod(request, response);
426 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
427 if (!result.isPresent()){
428 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadFunctions", new Exception("Failed to bulkUploadFunctions"));
429 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadFunctions", "Failed");
431 } catch (Exception e) {
432 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e);
433 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
438 @SuppressWarnings("unchecked")
439 @ApiOperation(value = "Bulk upload roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
440 @PostMapping(value = { "/v3/upload/portal/roles" }, produces = "application/json")
441 public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response)
443 Optional<PortalRestResponse<String>> result;
444 Map<String, Object> res = getMethod(request, response);
446 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
447 if (!result.isPresent()){
448 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoles", new Exception("Failed to bulkUploadRoles"));
449 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoles", "Failed");
452 } catch (Exception e) {
453 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e);
454 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
458 @SuppressWarnings("unchecked")
459 @ApiOperation(value = "Bulk upload role functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
460 @PostMapping(value = {
461 "/v3/upload/portal/roleFunctions" }, produces = "application/json")
462 public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response)
464 Optional<PortalRestResponse<String>> result;
465 Map<String, Object> res = getMethod(request, response);
467 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
468 if (!result.isPresent()){
469 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoleFunctions", new Exception("Failed to bulkUploadRoleFunctions"));
470 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoleFunctions", "Failed");
473 } catch (Exception e) {
474 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoleFunctions failed", e);
475 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
479 @SuppressWarnings("unchecked")
480 @ApiOperation(value = "Bulk upload user roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
481 @PostMapping(value = {
482 "/v3/upload/portal/userRoles" }, produces = "application/json")
483 public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response)
485 Optional<PortalRestResponse<String>> result;
486 Map<String, Object> res = getMethod(request, response);
488 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
489 if (!result.isPresent()){
490 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadUserRoles", new Exception("Failed to bulkUploadUserRoles"));
491 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadUserRoles", "Failed");
494 } catch (Exception e) {
495 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUserRoles failed", e);
496 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
501 @SuppressWarnings("unchecked")
502 @ApiOperation(value = "Bulk upload users for renamed role of an application.", response = PortalRestResponse.class, responseContainer = "Json")
503 @PostMapping(value = {
504 "/v3/upload/portal/userRole/{roleId}" }, produces = "application/json")
505 public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request,
506 HttpServletResponse response, @PathVariable Long roleId) throws Exception {
507 Optional<PortalRestResponse<String>> result = null;
508 Map<String, Object> res = getMethod(request, response);
510 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
511 if (!result.isPresent()){
512 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadUsersSingleRole", new Exception("Failed to bulkUploadUsersSingleRole"));
513 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadUsersSingleRole", "Failed");
516 } catch (Exception e) {
517 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUsersSingleRole failed", e);
518 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
522 @SuppressWarnings("unchecked")
523 @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
524 @PostMapping(value = {
525 "/v3/upload/partner/functions" }, produces = "application/json")
526 public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request,
527 HttpServletResponse response) throws Exception {
528 Optional<PortalRestResponse<String>> result = null;
529 Map<String, Object> res = getMethod(request, response);
531 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
532 if (!result.isPresent()){
533 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadPartnerRoleFunctions", new Exception("Failed to bulkUploadPartnerRoleFunctions"));
534 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed");
537 } catch (Exception e) {
538 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerFunctions failed", e);
539 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
544 @SuppressWarnings("unchecked")
545 @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
546 @PostMapping(value = { "/v3/upload/partner/roles" }, produces = "application/json")
547 public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response,
548 @RequestBody List<Role> upload) throws Exception {
549 Optional<PortalRestResponse<String>> result = null;
550 Map<String, Object> res = getMethod(request, response);
552 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
553 if (!result.isPresent()){
554 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoles", new Exception("Failed to bulkUploadRoles"));
555 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoles", "Failed");
558 } catch (Exception e) {
559 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoles failed", e);
560 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
564 @SuppressWarnings("unchecked")
565 @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
566 @PostMapping(value = {
567 "/v3/upload/partner/roleFunctions" }, produces = "application/json")
568 public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request,
569 HttpServletResponse response) throws Exception {
570 Optional<PortalRestResponse<String>> result = null;
571 Map<String, Object> res = getMethod(request, response);
573 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
574 if (!result.isPresent()){
575 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadPartnerRoleFunctions", new Exception("Failed to bulkUploadPartnerRoleFunctions"));
576 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed");
579 } catch (Exception e) {
580 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoleFunctions failed", e);
581 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
585 @SuppressWarnings("unchecked")
586 @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json")
587 @GetMapping(value = { "/v3/menuFunctions" }, produces = "application/json")
588 public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception {
589 List<String> functionsList = null;
590 Map<String, Object> res = getMethod(request, response);
592 functionsList = (List<String>) invokeMethod(res, request, response);
593 } catch (Exception e) {
594 logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctions failed", e);
596 return functionsList;
599 private String getPatchNumber() {
600 String response = "0";
602 Attributes attributes = manifestService.getWebappManifest();
603 response = attributes.getValue("Build-Number");
604 } catch (Exception ex) {
605 logger.error(EELFLoggerDelegate.errorLogger, "getPatchNumber failed", ex);
610 @SuppressWarnings("rawtypes")
611 private List<Object> getObject(HttpServletRequest request, HttpServletResponse response) {
612 Map<String, Object> beans = context.getBeansWithAnnotation(ApiVersion.class);
613 @SuppressWarnings("unchecked")
614 List<Object> beansList = new ArrayList(beans.values());
619 private Map<String, Object> getMethod(HttpServletRequest request, HttpServletResponse response) {
620 Method finalmethod = null;
621 String url = request.getRequestURI();
624 Object currentObject = null;
625 Map<String, Object> res = new HashMap<String, Object>();
626 String[] uriArray = url.split("/auxapi");
627 List<Integer> minorversionList = new ArrayList<>();
628 if (uriArray.length > 1) {
629 service = uriArray[1];
631 int first = service.indexOf("/");
632 int second = service.indexOf("/", first + 1);
633 version = service.substring(first + 1, second);
634 int min = minorVersion;
635 if (request.getHeader("MinorVersion") != null) {
636 min = Integer.parseInt(request.getHeader("MinorVersion"));
638 res.put("min", version+"."+min);
639 res.put("service", service);
640 List<Object> objList = getObject(request, response);
641 String requestedApiMethodType = request.getMethod();
642 String majorVersion = latestMajorVersionOfService(objList, service, version, requestedApiMethodType);
643 int latestMinorVersion = latestMinorVersionOfService(objList, service, version, requestedApiMethodType);
644 res.put("majorVersion", majorVersion);
645 res.put("latestMinorVersion", String.valueOf(latestMinorVersion));
646 outerloop: for (Object obj : objList) {
647 final List<Method> allMethods = getAllMethodsOfClass(obj);
648 for (final Method method : allMethods) {
649 if (method.isAnnotationPresent(ApiVersion.class)) {
650 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
651 Pattern p = Pattern.compile(annotInstance.service(),
652 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
653 Matcher matcher = p.matcher(service);
654 boolean b = matcher.matches();
655 logger.debug(EELFLoggerDelegate.debugLogger, "Requested Servie is:" + service
656 + "Requested MinVersion is:" + min + "Requested MajorVersion is: " + version);
657 if (annotInstance.max().equals(version) && b && annotInstance.min() == min
658 && annotInstance.method().equals(request.getMethod())) {
659 finalmethod = method;
661 res.put("method", method);
671 private String latestMajorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
672 String requestedApiMethodType) {
673 Integer majorVersion = 0;
674 String serviceEndPoint = service;
675 int firstindex = serviceEndPoint.indexOf("/");
676 int secondindex = serviceEndPoint.indexOf("/", firstindex + 1);
677 serviceEndPoint = serviceEndPoint.substring(secondindex + 1);
679 List<Integer> latestMajorVersionList = new ArrayList<>();
680 for (Object obj : objList) {
681 final List<Method> allMethods = getAllMethodsOfClass(obj);
682 for (final Method method : allMethods) {
683 if (method.isAnnotationPresent(ApiVersion.class)) {
684 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
685 String endpoint = annotInstance.service();
686 int first = endpoint.indexOf("/");
687 int second = endpoint.indexOf("/", first + 1);
688 endpoint = endpoint.substring(second + 1);
689 Pattern p = Pattern.compile(endpoint,
690 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
691 Matcher matcher = p.matcher(serviceEndPoint);
692 boolean b = matcher.matches();
693 if (b && annotInstance.method().equals(requestedApiMethodType)) {
694 int index1 = annotInstance.service().indexOf("/");
695 int index2 = annotInstance.service().indexOf("/", index1 + 1);
696 String majorversion = annotInstance.service().substring(index1 + 2, index2);
697 latestMajorVersionList.add(Integer.parseInt(majorversion));
702 majorVersion = Collections.max(latestMajorVersionList);
703 String majorVersionWithLastestMin = "/v"+String.valueOf(majorVersion)+"/"+serviceEndPoint;
704 int latestMinorVersion = latestMinorVersionOfService(objList, majorVersionWithLastestMin, "v"+String.valueOf(majorVersion), requestedApiMethodType);
705 return majorVersion+"."+latestMinorVersion;
708 private List<Method> getAllMethodsOfClass(Object obj) {
709 List<Method> allMethods = new ArrayList<>();
710 Class<?> objClz = obj.getClass();
711 if (org.springframework.aop.support.AopUtils.isAopProxy(obj)) {
712 objClz = org.springframework.aop.support.AopUtils.getTargetClass(obj);
714 allMethods = new ArrayList<Method>(Arrays.asList(objClz.getMethods()));
715 allMethods.removeIf(s -> !(s.isAnnotationPresent(ApiVersion.class)));
719 private Integer latestMinorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
720 String requestedApiMethodType) {
721 Integer minVersion = 0;
722 String serviceEndPoint = service;
723 List<Integer> latestMinorVersionList = new ArrayList<>();
724 for (Object obj : objList) {
725 final List<Method> allMethods = getAllMethodsOfClass(obj);
726 for (final Method method : allMethods) {
727 if (method.isAnnotationPresent(ApiVersion.class)) {
728 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
729 String endpoint = annotInstance.service();
731 Pattern p = Pattern.compile(endpoint,
732 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
733 Matcher matcher = p.matcher(serviceEndPoint);
734 boolean b = matcher.matches();
735 if (annotInstance.max().equals(reuqestedVersion) && b
736 && annotInstance.method().equals(requestedApiMethodType)) {
737 int minorversion = annotInstance.min();
738 latestMinorVersionList.add(minorversion);
743 minVersion = Collections.max(latestMinorVersionList);
747 private HttpServletResponse setResponse(HttpServletResponse response, String requestedMinVersion,
748 String majorVersion, String latestMinorVersion, String service) {
749 response.setHeader("X-MinorVersion", requestedMinVersion.toUpperCase());
750 response.setHeader("X-PatchVersion", getPatchNumber());
751 response.setHeader("X-LatestVersion", "V"+majorVersion);
759 * method parameters(Maintain HttpServletRequest at 0th position
760 * and HttpServletResponse at 1th position in args array)
764 private Object invokeMethod(Map<String, Object> res, Object... args) throws Exception {
765 Method method = (Method) res.get("method");
766 Object obj = res.get("Obj");
767 Object responseObj = null;
768 String min = res.get("min").toString();
769 String majorVersion = res.get("majorVersion").toString();
770 String latestMinorVersion = res.get("latestMinorVersion").toString();
771 String service = res.get("service").toString();
772 HttpServletRequest request = (HttpServletRequest) args[0];
773 HttpServletResponse response = (HttpServletResponse) args[1];
774 setResponse(response, min, majorVersion, latestMinorVersion, service);
775 final Map<String, String> errorMap = new HashMap<>();
776 ObjectMapper mapper = new ObjectMapper();
779 if (method != null && obj != null) {
780 responseObj = method.invoke(obj, args);
782 errorMap.put("error", "Requested api is not available");
783 reason = mapper.writeValueAsString(errorMap);
784 response.getWriter().write(reason);
785 logger.debug(EELFLoggerDelegate.debugLogger, "Requested api " + request.getRequestURI()
786 + "is not available with minorVersion " + request.getHeader("MinorVersion"));
787 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
789 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
790 logger.error(EELFLoggerDelegate.errorLogger, "Method :" + method + "invocation failed", e);
796 public void setApplicationContext(ApplicationContext context) throws BeansException {
797 this.context = context;
800 @SuppressWarnings("unchecked")
801 @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class)
802 @PostMapping(value = { "/v3/userProfile" }, produces = "application/json")
803 public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
804 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
806 if (extSysUser!=null){
807 if (!dataValidator.isValid(extSysUser))
808 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
811 PortalRestResponse<String> result = null;
812 Map<String, Object> res = getMethod(request, response);
814 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
816 } catch (Exception e) {
817 logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile failed", e);
818 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
822 @SuppressWarnings("unchecked")
823 @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class)
824 @PutMapping(value = { "/v3/userProfile" }, produces = "application/json")
825 public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
826 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
828 if (extSysUser!=null){
829 if (!dataValidator.isValid(extSysUser))
830 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
833 PortalRestResponse<String> result = null;
834 Map<String, Object> res = getMethod(request, response);
836 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
838 } catch (Exception e) {
839 logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile failed", e);
840 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
844 @SuppressWarnings("unchecked")
845 @ApiOperation(value = "Processes a request to delete one or more application roles for one specified user who has roles.", response = PortalRestResponse.class)
846 @DeleteMapping(value = { "/v3/userProfile" }, produces = "application/json")
847 public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
848 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
850 if (extSysUser!=null){
851 if (!dataValidator.isValid(extSysUser))
852 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
855 PortalRestResponse<String> result = null;
856 Map<String, Object> res = getMethod(request, response);
858 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
860 } catch (Exception e) {
861 logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile failed", e);
862 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
866 @SuppressWarnings("unchecked")
867 @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class)
868 @RequestMapping(value = { "/v3/ticketevent" }, method = RequestMethod.POST)
869 public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
870 @RequestBody String ticketEventJson) throws Exception {
872 if (ticketEventJson!=null){
873 SecureString secureTicketEventJson = new SecureString(ticketEventJson);
874 if (!dataValidator.isValid(secureTicketEventJson))
875 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ticketEventJson is not valid", "Failed");
878 PortalRestResponse<String> result = null;
879 Map<String, Object> res = getMethod(request, response);
881 result = (PortalRestResponse<String>) invokeMethod(res, request, response, ticketEventJson);
883 } catch (Exception e) {
884 logger.error(EELFLoggerDelegate.errorLogger, "handleRequest failed", e);
885 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
889 @SuppressWarnings("unchecked")
890 @ApiOperation(value = "Creates a new user as a Portal administrator.", response = PortalRestResponse.class)
891 @PostMapping(value = "/v3/portalAdmin", produces = "application/json")
893 public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response,
894 @RequestBody EPUser epUser) {
897 if (!dataValidator.isValid(epUser))
898 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "EPUser is not valid", "Failed");
901 PortalRestResponse<String> result = null;
902 Map<String, Object> res = getMethod(request, response);
904 result = (PortalRestResponse<String>) invokeMethod(res, request, response, epUser);
906 } catch (Exception e) {
907 logger.error(EELFLoggerDelegate.errorLogger, "postPortalAdmin failed", e);
908 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
912 @ApiOperation(value = "Gets the specified application that is on-boarded in Portal.", response = OnboardingApp.class)
913 @GetMapping(value = { "/v3/onboardApp/{appId}" }, produces = "application/json")
915 public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
916 @PathVariable("appId") Long appId) {
917 OnboardingApp result = new OnboardingApp();
918 Map<String, Object> res = getMethod(request, response);
920 result = (OnboardingApp) invokeMethod(res, request, response, appId);
921 } catch (Exception e) {
922 logger.error(EELFLoggerDelegate.errorLogger, "getOnboardAppExternal failed", e);
927 @SuppressWarnings("unchecked")
928 @ApiOperation(value = "Adds a new application to Portal.", response = PortalRestResponse.class)
929 @PostMapping(value = { "/v3/onboardApp" }, produces = "application/json")
931 public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
932 @RequestBody OnboardingApp newOnboardApp) {
934 if (newOnboardApp!=null){
935 if (!dataValidator.isValid(newOnboardApp))
936 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
939 PortalRestResponse<String> result = new PortalRestResponse<>();
940 Map<String, Object> res = getMethod(request, response);
942 result = (PortalRestResponse<String>) invokeMethod(res, request, response, newOnboardApp);
944 } catch (Exception e) {
945 logger.error(EELFLoggerDelegate.errorLogger, "postOnboardAppExternal failed", e);
946 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
951 @SuppressWarnings("unchecked")
952 @ApiOperation(value = "Updates information about an on-boarded application in Portal.", response = PortalRestResponse.class)
953 @PutMapping(value = { "/v3/onboardApp/{appId}" }, produces = "application/json")
955 public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
956 @PathVariable("appId") Long appId, @RequestBody OnboardingApp oldOnboardApp) {
958 if (oldOnboardApp!=null){
959 if (!dataValidator.isValid(oldOnboardApp))
960 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
963 PortalRestResponse<String> result;
964 Map<String, Object> res = getMethod(request, response);
966 result = (PortalRestResponse<String>) invokeMethod(res, request, response, appId, oldOnboardApp);
968 } catch (Exception e) {
969 logger.error(EELFLoggerDelegate.errorLogger, "putOnboardAppExternal failed", e);
970 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
974 @ApiOperation(value = "Creates a Portal user notification for roles identified in the content from an external application.", response = PortalAPIResponse.class)
975 @PostMapping(value = { "/v3/publishNotification" }, produces = "application/json")
977 public PortalAPIResponse publishNotification(HttpServletRequest request,
978 @RequestBody EpNotificationItem notificationItem, HttpServletResponse response) {
980 if (notificationItem!=null){
981 if (!dataValidator.isValid(notificationItem))
982 return new PortalAPIResponse(false, "EpNotificationItem is not valid");
985 Map<String, Object> res = getMethod(request, response);
987 return (PortalAPIResponse) invokeMethod(res, request, response, notificationItem);
988 } catch (Exception e) {
989 logger.error(EELFLoggerDelegate.errorLogger, "publishNotification failed", e);
990 return new PortalAPIResponse(false, e.getMessage());
994 @SuppressWarnings("unchecked")
995 @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer = "List")
996 @GetMapping(value = { "/v3/getFavorites" }, produces = "application/json")
997 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
998 HttpServletResponse response) throws Exception {
999 List<FavoritesFunctionalMenuItemJson> favorites = null;
1000 Map<String, Object> res = getMethod(request, response);
1002 favorites = (List<FavoritesFunctionalMenuItemJson>) invokeMethod(res, request, response);
1003 } catch (Exception e) {
1004 logger.error(EELFLoggerDelegate.errorLogger, "getFavoritesForUser failed", e);
1009 @SuppressWarnings("unchecked")
1010 @ApiOperation(value = "Gets functional menu items appropriate for the current user.", response = FunctionalMenuItem.class, responseContainer = "List")
1011 @GetMapping(value = {
1012 "/v3/functionalMenuItemsForUser" }, produces = "application/json")
1013 public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request,
1014 HttpServletResponse response) throws Exception {
1015 List<FunctionalMenuItem> fnMenuItems = null;
1016 Map<String, Object> res = getMethod(request, response);
1018 fnMenuItems = (List<FunctionalMenuItem>) invokeMethod(res, request, response);
1019 } catch (Exception e) {
1020 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser failed", e);
1026 @ApiOperation(value = "Gets MechId roles", response = String.class, responseContainer = "List")
1027 @GetMapping(value = { "/v3/systemUser" }, produces = "application/json")
1028 public List<AAFPermission> getSystemUserPerms(HttpServletRequest request, HttpServletResponse response) throws Exception {
1029 List<AAFPermission> permsList = null;
1030 Map<String, Object> res = getMethod(request, response);
1032 permsList = (List<AAFPermission>) invokeMethod(res, request, response);
1033 } catch (Exception e) {
1034 logger.error(EELFLoggerDelegate.errorLogger, "getSystemUserPerms failed", e);
1039 @ApiOperation(value = "Update role description in external auth system for an application.", response = PortalRestResponse.class, responseContainer = "Json")
1040 @PutMapping(value = { "/v3/update/app/roleDescription" }, produces = "application/json")
1041 public PortalRestResponse<String> updateAppRoleDescription(HttpServletRequest request, HttpServletResponse response) throws Exception {
1042 PortalRestResponse<String> result = null;
1043 Map<String, Object> res = getMethod(request, response);
1045 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
1047 } catch (Exception e) {
1048 logger.error(EELFLoggerDelegate.errorLogger, "updateAppRoleDescription failed", e);
1049 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");