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.concurrent.atomic.AtomicReference;
51 import java.util.jar.Attributes;
52 import java.util.regex.Matcher;
53 import java.util.regex.Pattern;
54 import javax.servlet.http.HttpServletRequest;
55 import javax.servlet.http.HttpServletResponse;
56 import org.onap.aaf.cadi.aaf.AAFPermission;
57 import org.onap.portalapp.annotation.ApiVersion;
58 import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser;
59 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
60 import org.onap.portalapp.portal.domain.EPUser;
61 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
62 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
63 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
64 import org.onap.portalapp.portal.service.ManifestService;
65 import org.onap.portalapp.portal.transport.Analytics;
66 import org.onap.portalapp.portal.transport.CentralUser;
67 import org.onap.portalapp.portal.transport.CentralV2Role;
68 import org.onap.portalapp.portal.transport.EpNotificationItem;
69 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
70 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
71 import org.onap.portalapp.portal.transport.OnboardingApp;
72 import org.onap.portalapp.validation.DataValidator;
73 import org.onap.portalapp.validation.SecureString;
74 import org.onap.portalsdk.core.domain.Role;
75 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
76 import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
77 import org.onap.portalsdk.core.restful.domain.EcompRole;
78 import org.onap.portalsdk.core.restful.domain.EcompUser;
79 import org.springframework.beans.BeansException;
80 import org.springframework.beans.factory.annotation.Autowired;
81 import org.springframework.context.ApplicationContext;
82 import org.springframework.context.ApplicationContextAware;
83 import org.springframework.context.annotation.Configuration;
84 import org.springframework.context.annotation.EnableAspectJAutoProxy;
85 import org.springframework.web.bind.annotation.PathVariable;
86 import org.springframework.web.bind.annotation.RequestBody;
87 import org.springframework.web.bind.annotation.RequestMapping;
88 import org.springframework.web.bind.annotation.GetMapping;
89 import org.springframework.web.bind.annotation.PostMapping;
90 import org.springframework.web.bind.annotation.PutMapping;
91 import org.springframework.web.bind.annotation.DeleteMapping;
92 import org.springframework.web.bind.annotation.RequestMethod;
93 import org.springframework.web.bind.annotation.RequestParam;
94 import org.springframework.web.bind.annotation.ResponseBody;
95 import org.springframework.web.bind.annotation.RestController;
98 @RequestMapping("/auxapi")
100 @EnableAspectJAutoProxy
102 public class AuxApiRequestMapperController implements ApplicationContextAware, BasicAuthenticationController {
104 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AuxApiRequestMapperController.class);
105 private DataValidator dataValidator = new DataValidator();
107 ApplicationContext context = null;
108 int minorVersion = 0;
111 private ManifestService manifestService;
113 @ApiOperation(value = "Gets user roles for an application which is upgraded to newer version.", response = String.class, responseContainer = "List")
114 @GetMapping(value = { "/v3/user/{loginId}" }, produces = "application/json")
115 public String getUser(HttpServletRequest request, HttpServletResponse response,
116 @PathVariable("loginId") String loginId) throws Exception {
118 SecureString secureLoginId = new SecureString(loginId);
119 if (!dataValidator.isValid(secureLoginId))
120 return "Provided data is not valid";
124 Map<String, Object> res = getMethod(request, response);
125 String answer = null;
127 answer = (String) invokeMethod(res, request, response, loginId);
128 } catch (Exception e) {
129 logger.error(EELFLoggerDelegate.errorLogger, "getUser failed", e);
134 @SuppressWarnings("unchecked")
135 @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
136 @GetMapping(value = { "/v3/roles" }, produces = "application/json")
137 public List<CentralV2Role> getRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
138 Map<String, Object> res = getMethod(request, response);
140 List<CentralV2Role> answer = null;
142 answer = (List<CentralV2Role>) invokeMethod(res, request, response);
143 } catch (Exception e) {
144 logger.error(EELFLoggerDelegate.errorLogger, "getRoles failed", e);
149 @SuppressWarnings("unchecked")
150 @ApiOperation(value = "Saves role for an application.", response = PortalRestResponse.class, responseContainer = "Json")
151 @PostMapping(value = { "/v3/role" }, produces = "application/json")
152 public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response,
153 @RequestBody Role role) throws Exception {
154 Map<String, Object> res = getMethod(request, response);
155 PortalRestResponse<String> out = null;
157 out = (PortalRestResponse<String>) invokeMethod(res, request, response, role);
158 } catch (Exception e) {
159 logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e);
160 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
165 @ApiOperation(value = "Gets v2 role information for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
166 @GetMapping(value = { "/v3/role/{role_id}" }, produces = "application/json")
167 public CentralV2Role getRoleInfo(HttpServletRequest request, HttpServletResponse response,
168 @PathVariable("role_id") Long roleId) throws Exception {
169 Map<String, Object> res = getMethod(request, response);
170 CentralV2Role role = null;
172 role = (CentralV2Role) invokeMethod(res, request, response, roleId);
173 } catch (Exception e) {
174 logger.error(EELFLoggerDelegate.errorLogger, "getRoleInfo failed", e);
180 @SuppressWarnings("unchecked")
181 @ApiOperation(value = "Gets all active Users of application", response = String.class, responseContainer = "Json")
182 @GetMapping(value = { "/v3/users" }, produces = "application/json")
183 public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response)
185 Map<String, Object> res = getMethod(request, response);
186 List<EcompUser> users = null;
188 users = (List<EcompUser>) invokeMethod(res, request, response);
189 } catch (Exception e) {
190 logger.error(EELFLoggerDelegate.errorLogger, "getUsersOfApplication failed", e);
195 @SuppressWarnings("unchecked")
196 @ApiOperation(value = "Gets all role functions for an application which is upgraded to newer version.", response = CentralV2RoleFunction.class, responseContainer = "Json")
197 @GetMapping(value = { "/v3/functions" }, produces = "application/json")
198 public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
200 Map<String, Object> res = getMethod(request, response);
201 List<CentralV2RoleFunction> roleFunctionsList = null;
203 roleFunctionsList = (List<CentralV2RoleFunction>) invokeMethod(res, request, response);
204 } catch (Exception e) {
205 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunctionsList failed", e);
207 return roleFunctionsList;
210 @ApiOperation(value = "Gets role information for an application provided by function code.", response = CentralV2RoleFunction.class, responseContainer = "Json")
211 @GetMapping(value = { "/v3/function/{code}" }, produces = "application/json")
212 public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response,
213 @PathVariable("code") String code) throws Exception {
215 SecureString secureCode = new SecureString(code);
216 if (!dataValidator.isValid(secureCode))
217 return new CentralV2RoleFunction();
220 Map<String, Object> res = getMethod(request, response);
221 CentralV2RoleFunction roleFunction = null;
223 roleFunction = (CentralV2RoleFunction) invokeMethod(res, request, response, code);
224 } catch (Exception e) {
225 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e);
230 @SuppressWarnings("unchecked")
231 @ApiOperation(value = "Saves role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
232 @PostMapping(value = { "/v3/roleFunction" }, produces = "application/json")
233 public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response,
234 @RequestBody String roleFunc) throws Exception {
236 SecureString secureRoleFunc = new SecureString(roleFunc);
237 if(!dataValidator.isValid(secureRoleFunc))
238 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
240 Optional<PortalRestResponse<String>> result = null;
241 Map<String, Object> res = getMethod(request, response);
243 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
244 if (!result.isPresent()){
245 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", new Exception("saveRoleFunction failed"));
246 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "saveRoleFunction failed", "Failed");
248 } catch (Exception e) {
249 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e);
250 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
255 @SuppressWarnings("unchecked")
256 @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
257 @DeleteMapping(value = { "/v3/roleFunction/{code}" }, produces = "application/json")
258 public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response,
259 @PathVariable("code") String code) throws Exception {
260 PortalRestResponse<String> result = null;
263 SecureString secureCode = new SecureString(code);
264 if(!dataValidator.isValid(secureCode))
265 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
268 Map<String, Object> res = getMethod(request, response);
270 result = (PortalRestResponse<String>) invokeMethod(res, request, response, code);
272 } catch (Exception e) {
273 logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction failed", e);
274 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
278 @SuppressWarnings("unchecked")
279 @ApiOperation(value = "deletes roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
280 @DeleteMapping(value = { "/v3/deleteRole/{roleId}" }, produces = "application/json")
281 public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response,
282 @PathVariable("roleId") Long roleId) throws Exception {
283 PortalRestResponse<String> result = null;
284 Map<String, Object> res = getMethod(request, response);
286 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
288 } catch (Exception e) {
289 logger.error(EELFLoggerDelegate.errorLogger, "deleteRole failed", e);
290 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
294 @SuppressWarnings("unchecked")
295 @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
296 @GetMapping(value = { "/v3/activeRoles" }, produces = "application/json")
297 public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response)
299 List<CentralV2Role> cenRole = null;
300 Map<String, Object> res = getMethod(request, response);
302 cenRole = (List<CentralV2Role>) invokeMethod(res, request, response);
303 } catch (Exception e) {
304 logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
309 @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List")
310 @GetMapping(value = { "/v4/user/{loginId}" }, produces = "application/json")
311 public String getEcompUser(HttpServletRequest request, HttpServletResponse response,
312 @PathVariable("loginId") String loginId) throws Exception {
313 Map<String, Object> res = getMethod(request, response);
316 SecureString secureLoginId = new SecureString(loginId);
318 if (!dataValidator.isValid(secureLoginId))
322 String answer = null;
324 answer = (String) invokeMethod(res, request, response, loginId);
325 } catch (Exception e) {
326 logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e);
331 @SuppressWarnings("unchecked")
332 @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List")
333 @GetMapping(value = { "/v4/roles" }, produces = "application/json")
334 public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response)
336 Map<String, Object> res = getMethod(request, response);
337 List<EcompRole> answer = null;
339 answer = (List<EcompRole>) invokeMethod(res, request, response);
340 } catch (Exception e) {
341 logger.error(EELFLoggerDelegate.errorLogger, "getEcompRolesOfApplication failed", e);
346 @ApiOperation(value = "Gets session slot-check interval, a duration in milliseconds.", response = Integer.class)
347 @GetMapping(value = {
348 "/v3/getSessionSlotCheckInterval" }, produces = "application/json")
349 public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response)
351 Map<String, Object> res = getMethod(request, response);
354 ans = (Integer) invokeMethod(res, request, response);
355 } catch (Exception e) {
356 logger.error(EELFLoggerDelegate.errorLogger, "getSessionSlotCheckInterval failed", e);
361 @ApiOperation(value = "Extends session timeout values for all on-boarded applications.", response = Boolean.class)
362 @RequestMapping(value = { "/v3/extendSessionTimeOuts" }, method = RequestMethod.POST)
363 public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response,
364 @RequestParam String sessionMap) throws Exception {
366 if (sessionMap!=null){
367 SecureString secureSessionMap = new SecureString(sessionMap);
368 if (!dataValidator.isValid(secureSessionMap)){
373 Map<String, Object> res = getMethod(request, response);
376 ans = (Boolean) invokeMethod(res, request, response, sessionMap);
377 } catch (Exception e) {
378 logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts failed", e);
383 @ApiOperation(value = "Gets javascript with functions that support gathering and reporting web analytics.", response = String.class)
384 @GetMapping(value = { "/v3/analytics" }, produces = "application/javascript")
385 public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception {
386 Map<String, Object> res = getMethod(request, response);
389 ans = (String) invokeMethod(res, request, response);
390 } catch (Exception e) {
391 logger.error(EELFLoggerDelegate.errorLogger, "getAnalyticsScript failed", e);
396 @PostMapping(value = { "/v3/storeAnalytics" }, produces = "application/json")
398 @ApiOperation(value = "Accepts data from partner applications with web analytics data.", response = PortalAPIResponse.class)
399 public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response,
400 @RequestBody Analytics analyticsMap) throws Exception {
402 if (analyticsMap!=null){
403 if (!dataValidator.isValid(analyticsMap))
404 return new PortalAPIResponse(false, "analyticsScript is not valid");
407 Map<String, Object> res = getMethod(request, response);
408 PortalAPIResponse ans = new PortalAPIResponse(true, "error");
410 ans = (PortalAPIResponse) invokeMethod(res, request, response, analyticsMap);
411 } catch (Exception e) {
412 logger.error(EELFLoggerDelegate.errorLogger, "storeAnalyticsScript failed", e);
418 @SuppressWarnings("unchecked")
419 @ApiOperation(value = "Bulk upload functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
420 @PostMapping(value = {
421 "/v3/upload/portal/functions" }, produces = "application/json")
422 public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response)
424 Optional<PortalRestResponse<String>> result = null;
425 Map<String, Object> res = getMethod(request, response);
427 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
428 if (!result.isPresent()){
429 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadFunctions", new Exception("Failed to bulkUploadFunctions"));
430 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadFunctions", "Failed");
432 } catch (Exception e) {
433 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e);
434 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
439 @SuppressWarnings("unchecked")
440 @ApiOperation(value = "Bulk upload roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
441 @PostMapping(value = { "/v3/upload/portal/roles" }, produces = "application/json")
442 public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response)
444 Optional<PortalRestResponse<String>> result;
445 Map<String, Object> res = getMethod(request, response);
447 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
448 if (!result.isPresent()){
449 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoles", new Exception("Failed to bulkUploadRoles"));
450 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoles", "Failed");
453 } catch (Exception e) {
454 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e);
455 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
459 @SuppressWarnings("unchecked")
460 @ApiOperation(value = "Bulk upload role functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
461 @PostMapping(value = {
462 "/v3/upload/portal/roleFunctions" }, produces = "application/json")
463 public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response)
465 Optional<PortalRestResponse<String>> result;
466 Map<String, Object> res = getMethod(request, response);
468 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
469 if (!result.isPresent()){
470 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoleFunctions", new Exception("Failed to bulkUploadRoleFunctions"));
471 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoleFunctions", "Failed");
474 } catch (Exception e) {
475 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoleFunctions failed", e);
476 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
480 @SuppressWarnings("unchecked")
481 @ApiOperation(value = "Bulk upload user roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
482 @PostMapping(value = {
483 "/v3/upload/portal/userRoles" }, produces = "application/json")
484 public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response)
486 Optional<PortalRestResponse<String>> result;
487 Map<String, Object> res = getMethod(request, response);
489 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
490 if (!result.isPresent()){
491 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadUserRoles", new Exception("Failed to bulkUploadUserRoles"));
492 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadUserRoles", "Failed");
495 } catch (Exception e) {
496 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUserRoles failed", e);
497 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
502 @SuppressWarnings("unchecked")
503 @ApiOperation(value = "Bulk upload users for renamed role of an application.", response = PortalRestResponse.class, responseContainer = "Json")
504 @PostMapping(value = {
505 "/v3/upload/portal/userRole/{roleId}" }, produces = "application/json")
506 public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request,
507 HttpServletResponse response, @PathVariable Long roleId) throws Exception {
508 Optional<PortalRestResponse<String>> result = null;
509 Map<String, Object> res = getMethod(request, response);
511 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
512 if (!result.isPresent()){
513 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadUsersSingleRole", new Exception("Failed to bulkUploadUsersSingleRole"));
514 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadUsersSingleRole", "Failed");
517 } catch (Exception e) {
518 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUsersSingleRole failed", e);
519 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
523 @SuppressWarnings("unchecked")
524 @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
525 @PostMapping(value = {
526 "/v3/upload/partner/functions" }, produces = "application/json")
527 public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request,
528 HttpServletResponse response) throws Exception {
529 Optional<PortalRestResponse<String>> result = null;
530 Map<String, Object> res = getMethod(request, response);
532 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
533 if (!result.isPresent()){
534 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadPartnerRoleFunctions", new Exception("Failed to bulkUploadPartnerRoleFunctions"));
535 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed");
538 } catch (Exception e) {
539 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerFunctions failed", e);
540 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
545 @SuppressWarnings("unchecked")
546 @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
547 @PostMapping(value = { "/v3/upload/partner/roles" }, produces = "application/json")
548 public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response,
549 @RequestBody List<Role> upload) throws Exception {
550 Optional<PortalRestResponse<String>> result = null;
551 Map<String, Object> res = getMethod(request, response);
553 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
554 if (!result.isPresent()){
555 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoles", new Exception("Failed to bulkUploadRoles"));
556 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoles", "Failed");
559 } catch (Exception e) {
560 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoles failed", e);
561 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
565 @SuppressWarnings("unchecked")
566 @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
567 @PostMapping(value = {
568 "/v3/upload/partner/roleFunctions" }, produces = "application/json")
569 public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request,
570 HttpServletResponse response) throws Exception {
571 Optional<PortalRestResponse<String>> result = null;
572 Map<String, Object> res = getMethod(request, response);
574 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
575 if (!result.isPresent()){
576 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadPartnerRoleFunctions", new Exception("Failed to bulkUploadPartnerRoleFunctions"));
577 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed");
580 } catch (Exception e) {
581 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoleFunctions failed", e);
582 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
586 @SuppressWarnings("unchecked")
587 @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json")
588 @GetMapping(value = { "/v3/menuFunctions" }, produces = "application/json")
589 public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception {
590 List<String> functionsList = null;
591 Map<String, Object> res = getMethod(request, response);
593 functionsList = (List<String>) invokeMethod(res, request, response);
594 } catch (Exception e) {
595 logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctions failed", e);
597 return functionsList;
600 private String getPatchNumber() {
601 String response = "0";
603 Attributes attributes = manifestService.getWebappManifest();
604 response = attributes.getValue("Build-Number");
605 } catch (Exception ex) {
606 logger.error(EELFLoggerDelegate.errorLogger, "getPatchNumber failed", ex);
611 @SuppressWarnings("rawtypes")
612 private List<Object> getObject(HttpServletRequest request, HttpServletResponse response) {
613 Map<String, Object> beans = context.getBeansWithAnnotation(ApiVersion.class);
614 @SuppressWarnings("unchecked")
615 List<Object> beansList = new ArrayList(beans.values());
620 private Map<String, Object> getMethod(HttpServletRequest request, HttpServletResponse response) {
621 Method finalmethod = null;
622 String url = request.getRequestURI();
625 Object currentObject = null;
626 Map<String, Object> res = new HashMap<String, Object>();
627 String[] uriArray = url.split("/auxapi");
628 List<Integer> minorversionList = new ArrayList<>();
629 if (uriArray.length > 1) {
630 service = uriArray[1];
632 int first = service.indexOf("/");
633 int second = service.indexOf("/", first + 1);
634 version = service.substring(first + 1, second);
635 int min = minorVersion;
636 if (request.getHeader("MinorVersion") != null) {
637 min = Integer.parseInt(request.getHeader("MinorVersion"));
639 res.put("min", version+"."+min);
640 res.put("service", service);
641 List<Object> objList = getObject(request, response);
642 String requestedApiMethodType = request.getMethod();
643 String majorVersion = latestMajorVersionOfService(objList, service, version, requestedApiMethodType);
644 int latestMinorVersion = latestMinorVersionOfService(objList, service, version, requestedApiMethodType);
645 res.put("majorVersion", majorVersion);
646 res.put("latestMinorVersion", String.valueOf(latestMinorVersion));
647 outerloop: for (Object obj : objList) {
648 final List<Method> allMethods = getAllMethodsOfClass(obj);
649 for (final Method method : allMethods) {
650 if (method.isAnnotationPresent(ApiVersion.class)) {
651 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
652 Pattern p = Pattern.compile(annotInstance.service(),
653 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
654 Matcher matcher = p.matcher(service);
655 boolean b = matcher.matches();
656 logger.debug(EELFLoggerDelegate.debugLogger, "Requested Servie is:" + service
657 + "Requested MinVersion is:" + min + "Requested MajorVersion is: " + version);
658 if (annotInstance.max().equals(version) && b && annotInstance.min() == min
659 && annotInstance.method().equals(request.getMethod())) {
660 finalmethod = method;
662 res.put("method", method);
672 private String latestMajorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
673 String requestedApiMethodType) {
674 Integer majorVersion = 0;
675 String serviceEndPoint = service;
676 int firstindex = serviceEndPoint.indexOf("/");
677 int secondindex = serviceEndPoint.indexOf("/", firstindex + 1);
678 serviceEndPoint = serviceEndPoint.substring(secondindex + 1);
680 List<Integer> latestMajorVersionList = new ArrayList<>();
681 for (Object obj : objList) {
682 final List<Method> allMethods = getAllMethodsOfClass(obj);
683 for (final Method method : allMethods) {
684 if (method.isAnnotationPresent(ApiVersion.class)) {
685 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
686 String endpoint = annotInstance.service();
687 int first = endpoint.indexOf("/");
688 int second = endpoint.indexOf("/", first + 1);
689 endpoint = endpoint.substring(second + 1);
690 Pattern p = Pattern.compile(endpoint,
691 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
692 Matcher matcher = p.matcher(serviceEndPoint);
693 boolean b = matcher.matches();
694 if (b && annotInstance.method().equals(requestedApiMethodType)) {
695 int index1 = annotInstance.service().indexOf("/");
696 int index2 = annotInstance.service().indexOf("/", index1 + 1);
697 String majorversion = annotInstance.service().substring(index1 + 2, index2);
698 latestMajorVersionList.add(Integer.parseInt(majorversion));
703 majorVersion = Collections.max(latestMajorVersionList);
704 String majorVersionWithLastestMin = "/v"+String.valueOf(majorVersion)+"/"+serviceEndPoint;
705 int latestMinorVersion = latestMinorVersionOfService(objList, majorVersionWithLastestMin, "v"+String.valueOf(majorVersion), requestedApiMethodType);
706 return majorVersion+"."+latestMinorVersion;
709 private List<Method> getAllMethodsOfClass(Object obj) {
710 List<Method> allMethods = new ArrayList<>();
711 Class<?> objClz = obj.getClass();
712 if (org.springframework.aop.support.AopUtils.isAopProxy(obj)) {
713 objClz = org.springframework.aop.support.AopUtils.getTargetClass(obj);
715 allMethods = new ArrayList<Method>(Arrays.asList(objClz.getMethods()));
716 allMethods.removeIf(s -> !(s.isAnnotationPresent(ApiVersion.class)));
720 private Integer latestMinorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
721 String requestedApiMethodType) {
722 Integer minVersion = 0;
723 String serviceEndPoint = service;
724 List<Integer> latestMinorVersionList = new ArrayList<>();
725 for (Object obj : objList) {
726 final List<Method> allMethods = getAllMethodsOfClass(obj);
727 for (final Method method : allMethods) {
728 if (method.isAnnotationPresent(ApiVersion.class)) {
729 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
730 String endpoint = annotInstance.service();
732 Pattern p = Pattern.compile(endpoint,
733 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
734 Matcher matcher = p.matcher(serviceEndPoint);
735 boolean b = matcher.matches();
736 if (annotInstance.max().equals(reuqestedVersion) && b
737 && annotInstance.method().equals(requestedApiMethodType)) {
738 int minorversion = annotInstance.min();
739 latestMinorVersionList.add(minorversion);
744 minVersion = Collections.max(latestMinorVersionList);
748 private HttpServletResponse setResponse(HttpServletResponse response, String requestedMinVersion,
749 String majorVersion, String latestMinorVersion, String service) {
750 response.setHeader("X-MinorVersion", requestedMinVersion.toUpperCase());
751 response.setHeader("X-PatchVersion", getPatchNumber());
752 response.setHeader("X-LatestVersion", "V"+majorVersion);
760 * method parameters(Maintain HttpServletRequest at 0th position
761 * and HttpServletResponse at 1th position in args array)
765 private Object invokeMethod(Map<String, Object> res, Object... args) throws Exception {
766 Method method = (Method) res.get("method");
767 Object obj = res.get("Obj");
768 Object responseObj = null;
769 String min = res.get("min").toString();
770 String majorVersion = res.get("majorVersion").toString();
771 String latestMinorVersion = res.get("latestMinorVersion").toString();
772 String service = res.get("service").toString();
773 HttpServletRequest request = (HttpServletRequest) args[0];
774 HttpServletResponse response = (HttpServletResponse) args[1];
775 setResponse(response, min, majorVersion, latestMinorVersion, service);
776 final Map<String, String> errorMap = new HashMap<>();
777 ObjectMapper mapper = new ObjectMapper();
780 if (method != null && obj != null) {
781 responseObj = method.invoke(obj, args);
783 errorMap.put("error", "Requested api is not available");
784 reason = mapper.writeValueAsString(errorMap);
785 response.getWriter().write(reason);
786 logger.debug(EELFLoggerDelegate.debugLogger, "Requested api " + request.getRequestURI()
787 + "is not available with minorVersion " + request.getHeader("MinorVersion"));
788 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
790 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
791 logger.error(EELFLoggerDelegate.errorLogger, "Method :" + method + "invocation failed", e);
797 public void setApplicationContext(ApplicationContext context) throws BeansException {
798 this.context = context;
801 @SuppressWarnings("unchecked")
802 @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class)
803 @PostMapping(value = { "/v3/userProfile" }, produces = "application/json")
804 public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
805 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
807 if (extSysUser!=null){
808 if (!dataValidator.isValid(extSysUser))
809 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
812 PortalRestResponse<String> result = null;
813 Map<String, Object> res = getMethod(request, response);
815 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
817 } catch (Exception e) {
818 logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile failed", e);
819 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
823 @SuppressWarnings("unchecked")
824 @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class)
825 @PutMapping(value = { "/v3/userProfile" }, produces = "application/json")
826 public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
827 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
829 if (extSysUser!=null){
830 if (!dataValidator.isValid(extSysUser))
831 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
834 PortalRestResponse<String> result = null;
835 Map<String, Object> res = getMethod(request, response);
837 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
839 } catch (Exception e) {
840 logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile failed", e);
841 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
845 @SuppressWarnings("unchecked")
846 @ApiOperation(value = "Processes a request to delete one or more application roles for one specified user who has roles.", response = PortalRestResponse.class)
847 @DeleteMapping(value = { "/v3/userProfile" }, produces = "application/json")
848 public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
849 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
851 if (extSysUser!=null){
852 if (!dataValidator.isValid(extSysUser))
853 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
856 PortalRestResponse<String> result = null;
857 Map<String, Object> res = getMethod(request, response);
859 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
861 } catch (Exception e) {
862 logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile failed", e);
863 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
867 @SuppressWarnings("unchecked")
868 @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class)
869 @RequestMapping(value = { "/v3/ticketevent" }, method = RequestMethod.POST)
870 public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
871 @RequestBody String ticketEventJson) throws Exception {
873 if (ticketEventJson!=null){
874 SecureString secureTicketEventJson = new SecureString(ticketEventJson);
875 if (!dataValidator.isValid(secureTicketEventJson))
876 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ticketEventJson is not valid", "Failed");
879 PortalRestResponse<String> result = null;
880 Map<String, Object> res = getMethod(request, response);
882 result = (PortalRestResponse<String>) invokeMethod(res, request, response, ticketEventJson);
884 } catch (Exception e) {
885 logger.error(EELFLoggerDelegate.errorLogger, "handleRequest failed", e);
886 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
890 @SuppressWarnings("unchecked")
891 @ApiOperation(value = "Creates a new user as a Portal administrator.", response = PortalRestResponse.class)
892 @PostMapping(value = "/v3/portalAdmin", produces = "application/json")
894 public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response,
895 @RequestBody EPUser epUser) {
898 if (!dataValidator.isValid(epUser))
899 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "EPUser is not valid", "Failed");
902 PortalRestResponse<String> result = null;
903 Map<String, Object> res = getMethod(request, response);
905 result = (PortalRestResponse<String>) invokeMethod(res, request, response, epUser);
907 } catch (Exception e) {
908 logger.error(EELFLoggerDelegate.errorLogger, "postPortalAdmin failed", e);
909 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
913 @ApiOperation(value = "Gets the specified application that is on-boarded in Portal.", response = OnboardingApp.class)
914 @GetMapping(value = { "/v3/onboardApp/{appId}" }, produces = "application/json")
916 public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
917 @PathVariable("appId") Long appId) {
918 OnboardingApp result = new OnboardingApp();
919 Map<String, Object> res = getMethod(request, response);
921 result = (OnboardingApp) invokeMethod(res, request, response, appId);
922 } catch (Exception e) {
923 logger.error(EELFLoggerDelegate.errorLogger, "getOnboardAppExternal failed", e);
928 @SuppressWarnings("unchecked")
929 @ApiOperation(value = "Adds a new application to Portal.", response = PortalRestResponse.class)
930 @PostMapping(value = { "/v3/onboardApp" }, produces = "application/json")
932 public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
933 @RequestBody OnboardingApp newOnboardApp) {
935 if (newOnboardApp!=null){
936 if (!dataValidator.isValid(newOnboardApp))
937 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
940 PortalRestResponse<String> result = new PortalRestResponse<>();
941 Map<String, Object> res = getMethod(request, response);
943 result = (PortalRestResponse<String>) invokeMethod(res, request, response, newOnboardApp);
945 } catch (Exception e) {
946 logger.error(EELFLoggerDelegate.errorLogger, "postOnboardAppExternal failed", e);
947 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
952 @SuppressWarnings("unchecked")
953 @ApiOperation(value = "Updates information about an on-boarded application in Portal.", response = PortalRestResponse.class)
954 @PutMapping(value = { "/v3/onboardApp/{appId}" }, produces = "application/json")
956 public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
957 @PathVariable("appId") Long appId, @RequestBody OnboardingApp oldOnboardApp) {
959 if (oldOnboardApp!=null){
960 if (!dataValidator.isValid(oldOnboardApp))
961 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
964 PortalRestResponse<String> result;
965 Map<String, Object> res = getMethod(request, response);
967 result = (PortalRestResponse<String>) invokeMethod(res, request, response, appId, oldOnboardApp);
969 } catch (Exception e) {
970 logger.error(EELFLoggerDelegate.errorLogger, "putOnboardAppExternal failed", e);
971 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
975 @ApiOperation(value = "Creates a Portal user notification for roles identified in the content from an external application.", response = PortalAPIResponse.class)
976 @PostMapping(value = { "/v3/publishNotification" }, produces = "application/json")
978 public PortalAPIResponse publishNotification(HttpServletRequest request,
979 @RequestBody EpNotificationItem notificationItem, HttpServletResponse response) {
981 if (notificationItem!=null){
982 if (!dataValidator.isValid(notificationItem))
983 return new PortalAPIResponse(false, "EpNotificationItem is not valid");
986 Map<String, Object> res = getMethod(request, response);
988 return (PortalAPIResponse) invokeMethod(res, request, response, notificationItem);
989 } catch (Exception e) {
990 logger.error(EELFLoggerDelegate.errorLogger, "publishNotification failed", e);
991 return new PortalAPIResponse(false, e.getMessage());
995 @SuppressWarnings("unchecked")
996 @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer = "List")
997 @GetMapping(value = { "/v3/getFavorites" }, produces = "application/json")
998 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
999 HttpServletResponse response) throws Exception {
1000 List<FavoritesFunctionalMenuItemJson> favorites = null;
1001 Map<String, Object> res = getMethod(request, response);
1003 favorites = (List<FavoritesFunctionalMenuItemJson>) invokeMethod(res, request, response);
1004 } catch (Exception e) {
1005 logger.error(EELFLoggerDelegate.errorLogger, "getFavoritesForUser failed", e);
1010 @SuppressWarnings("unchecked")
1011 @ApiOperation(value = "Gets functional menu items appropriate for the current user.", response = FunctionalMenuItem.class, responseContainer = "List")
1012 @GetMapping(value = {
1013 "/v3/functionalMenuItemsForUser" }, produces = "application/json")
1014 public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request,
1015 HttpServletResponse response) throws Exception {
1016 List<FunctionalMenuItem> fnMenuItems = null;
1017 Map<String, Object> res = getMethod(request, response);
1019 fnMenuItems = (List<FunctionalMenuItem>) invokeMethod(res, request, response);
1020 } catch (Exception e) {
1021 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser failed", e);
1027 @ApiOperation(value = "Gets MechId roles", response = String.class, responseContainer = "List")
1028 @GetMapping(value = { "/v3/systemUser" }, produces = "application/json")
1029 public List<AAFPermission> getSystemUserPerms(HttpServletRequest request, HttpServletResponse response) throws Exception {
1030 List<AAFPermission> permsList = null;
1031 Map<String, Object> res = getMethod(request, response);
1033 permsList = (List<AAFPermission>) invokeMethod(res, request, response);
1034 } catch (Exception e) {
1035 logger.error(EELFLoggerDelegate.errorLogger, "getSystemUserPerms failed", e);
1040 @ApiOperation(value = "Update role description in external auth system for an application.", response = PortalRestResponse.class, responseContainer = "Json")
1041 @PutMapping(value = { "/v3/update/app/roleDescription" }, produces = "application/json")
1042 public PortalRestResponse<String> updateAppRoleDescription(HttpServletRequest request, HttpServletResponse response) throws Exception {
1043 PortalRestResponse<String> result = null;
1044 Map<String, Object> res = getMethod(request, response);
1046 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
1048 } catch (Exception e) {
1049 logger.error(EELFLoggerDelegate.errorLogger, "updateAppRoleDescription failed", e);
1050 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");