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.RequestParam;
92 import org.springframework.web.bind.annotation.ResponseBody;
93 import org.springframework.web.bind.annotation.RestController;
96 @RequestMapping("/auxapi")
98 @EnableAspectJAutoProxy
100 public class AuxApiRequestMapperController implements ApplicationContextAware, BasicAuthenticationController {
102 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AuxApiRequestMapperController.class);
103 private DataValidator dataValidator = new DataValidator();
105 ApplicationContext context = null;
106 int minorVersion = 0;
109 private ManifestService manifestService;
111 @ApiOperation(value = "Gets user roles for an application which is upgraded to newer version.", response = String.class, responseContainer = "List")
112 @GetMapping(value = { "/v3/user/{loginId}" }, produces = "application/json")
113 public String getUser(HttpServletRequest request, HttpServletResponse response,
114 @PathVariable("loginId") String loginId) throws Exception {
116 SecureString secureLoginId = new SecureString(loginId);
117 if (!dataValidator.isValid(secureLoginId))
118 return "Provided data is not valid";
122 Map<String, Object> res = getMethod(request, response);
123 String answer = null;
125 answer = (String) invokeMethod(res, request, response, loginId);
126 } catch (Exception e) {
127 logger.error(EELFLoggerDelegate.errorLogger, "getUser failed", e);
132 @SuppressWarnings("unchecked")
133 @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
134 @GetMapping(value = { "/v3/roles" }, produces = "application/json")
135 public List<CentralV2Role> getRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
136 Map<String, Object> res = getMethod(request, response);
138 List<CentralV2Role> answer = null;
140 answer = (List<CentralV2Role>) invokeMethod(res, request, response);
141 } catch (Exception e) {
142 logger.error(EELFLoggerDelegate.errorLogger, "getRoles failed", e);
147 @SuppressWarnings("unchecked")
148 @ApiOperation(value = "Saves role for an application.", response = PortalRestResponse.class, responseContainer = "Json")
149 @PostMapping(value = { "/v3/role" }, produces = "application/json")
150 public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response,
151 @RequestBody Role role) throws Exception {
152 Map<String, Object> res = getMethod(request, response);
153 PortalRestResponse<String> out = null;
155 out = (PortalRestResponse<String>) invokeMethod(res, request, response, role);
156 } catch (Exception e) {
157 logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e);
158 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
163 @ApiOperation(value = "Gets v2 role information for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
164 @GetMapping(value = { "/v3/role/{role_id}" }, produces = "application/json")
165 public CentralV2Role getRoleInfo(HttpServletRequest request, HttpServletResponse response,
166 @PathVariable("role_id") Long roleId) throws Exception {
167 Map<String, Object> res = getMethod(request, response);
168 CentralV2Role role = null;
170 role = (CentralV2Role) invokeMethod(res, request, response, roleId);
171 } catch (Exception e) {
172 logger.error(EELFLoggerDelegate.errorLogger, "getRoleInfo failed", e);
178 @SuppressWarnings("unchecked")
179 @ApiOperation(value = "Gets all active Users of application", response = String.class, responseContainer = "Json")
180 @GetMapping(value = { "/v3/users" }, produces = "application/json")
181 public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response)
183 Map<String, Object> res = getMethod(request, response);
184 List<EcompUser> users = null;
186 users = (List<EcompUser>) invokeMethod(res, request, response);
187 } catch (Exception e) {
188 logger.error(EELFLoggerDelegate.errorLogger, "getUsersOfApplication failed", e);
193 @SuppressWarnings("unchecked")
194 @ApiOperation(value = "Gets all role functions for an application which is upgraded to newer version.", response = CentralV2RoleFunction.class, responseContainer = "Json")
195 @GetMapping(value = { "/v3/functions" }, produces = "application/json")
196 public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
198 Map<String, Object> res = getMethod(request, response);
199 List<CentralV2RoleFunction> roleFunctionsList = null;
201 roleFunctionsList = (List<CentralV2RoleFunction>) invokeMethod(res, request, response);
202 } catch (Exception e) {
203 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunctionsList failed", e);
205 return roleFunctionsList;
208 @ApiOperation(value = "Gets role information for an application provided by function code.", response = CentralV2RoleFunction.class, responseContainer = "Json")
209 @GetMapping(value = { "/v3/function/{code}" }, produces = "application/json")
210 public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response,
211 @PathVariable("code") String code) throws Exception {
213 SecureString secureCode = new SecureString(code);
214 if (!dataValidator.isValid(secureCode))
215 return new CentralV2RoleFunction();
218 Map<String, Object> res = getMethod(request, response);
219 CentralV2RoleFunction roleFunction = null;
221 roleFunction = (CentralV2RoleFunction) invokeMethod(res, request, response, code);
222 } catch (Exception e) {
223 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e);
228 @SuppressWarnings("unchecked")
229 @ApiOperation(value = "Saves role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
230 @PostMapping(value = { "/v3/roleFunction" }, produces = "application/json")
231 public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response,
232 @RequestBody String roleFunc) throws Exception {
234 SecureString secureRoleFunc = new SecureString(roleFunc);
235 if(!dataValidator.isValid(secureRoleFunc))
236 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
238 Optional<PortalRestResponse<String>> result = null;
239 Map<String, Object> res = getMethod(request, response);
241 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
242 if (!result.isPresent()){
243 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", new Exception("saveRoleFunction failed"));
244 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "saveRoleFunction failed", "Failed");
246 } catch (Exception e) {
247 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e);
248 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
253 @SuppressWarnings("unchecked")
254 @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
255 @DeleteMapping(value = { "/v3/roleFunction/{code}" }, produces = "application/json")
256 public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response,
257 @PathVariable("code") String code) throws Exception {
258 PortalRestResponse<String> result = null;
261 SecureString secureCode = new SecureString(code);
262 if(!dataValidator.isValid(secureCode))
263 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
266 Map<String, Object> res = getMethod(request, response);
268 result = (PortalRestResponse<String>) invokeMethod(res, request, response, code);
270 } catch (Exception e) {
271 logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction failed", e);
272 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
276 @SuppressWarnings("unchecked")
277 @ApiOperation(value = "deletes roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
278 @DeleteMapping(value = { "/v3/deleteRole/{roleId}" }, produces = "application/json")
279 public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response,
280 @PathVariable("roleId") Long roleId) throws Exception {
281 PortalRestResponse<String> result = null;
282 Map<String, Object> res = getMethod(request, response);
284 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
286 } catch (Exception e) {
287 logger.error(EELFLoggerDelegate.errorLogger, "deleteRole failed", e);
288 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
292 @SuppressWarnings("unchecked")
293 @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
294 @GetMapping(value = { "/v3/activeRoles" }, produces = "application/json")
295 public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response)
297 List<CentralV2Role> cenRole = null;
298 Map<String, Object> res = getMethod(request, response);
300 cenRole = (List<CentralV2Role>) invokeMethod(res, request, response);
301 } catch (Exception e) {
302 logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
307 @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List")
308 @GetMapping(value = { "/v4/user/{loginId}" }, produces = "application/json")
309 public String getEcompUser(HttpServletRequest request, HttpServletResponse response,
310 @PathVariable("loginId") String loginId) throws Exception {
311 Map<String, Object> res = getMethod(request, response);
314 SecureString secureLoginId = new SecureString(loginId);
316 if (!dataValidator.isValid(secureLoginId))
320 String answer = null;
322 answer = (String) invokeMethod(res, request, response, loginId);
323 } catch (Exception e) {
324 logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e);
329 @SuppressWarnings("unchecked")
330 @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List")
331 @GetMapping(value = { "/v4/roles" }, produces = "application/json")
332 public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response)
334 Map<String, Object> res = getMethod(request, response);
335 List<EcompRole> answer = null;
337 answer = (List<EcompRole>) invokeMethod(res, request, response);
338 } catch (Exception e) {
339 logger.error(EELFLoggerDelegate.errorLogger, "getEcompRolesOfApplication failed", e);
344 @ApiOperation(value = "Gets session slot-check interval, a duration in milliseconds.", response = Integer.class)
345 @GetMapping(value = {
346 "/v3/getSessionSlotCheckInterval" }, produces = "application/json")
347 public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response)
349 Map<String, Object> res = getMethod(request, response);
352 ans = (Integer) invokeMethod(res, request, response);
353 } catch (Exception e) {
354 logger.error(EELFLoggerDelegate.errorLogger, "getSessionSlotCheckInterval failed", e);
359 @ApiOperation(value = "Extends session timeout values for all on-boarded applications.", response = Boolean.class)
360 @PostMapping(value = { "/v3/extendSessionTimeOuts" })
361 public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response,
362 @RequestParam String sessionMap) throws Exception {
364 if (sessionMap!=null){
365 SecureString secureSessionMap = new SecureString(sessionMap);
366 if (!dataValidator.isValid(secureSessionMap)){
371 Map<String, Object> res = getMethod(request, response);
374 ans = (Boolean) invokeMethod(res, request, response, sessionMap);
375 } catch (Exception e) {
376 logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts failed", e);
381 @ApiOperation(value = "Gets javascript with functions that support gathering and reporting web analytics.", response = String.class)
382 @GetMapping(value = { "/v3/analytics" }, produces = "application/javascript")
383 public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception {
384 Map<String, Object> res = getMethod(request, response);
387 ans = (String) invokeMethod(res, request, response);
388 } catch (Exception e) {
389 logger.error(EELFLoggerDelegate.errorLogger, "getAnalyticsScript failed", e);
394 @PostMapping(value = { "/v3/storeAnalytics" }, produces = "application/json")
396 @ApiOperation(value = "Accepts data from partner applications with web analytics data.", response = PortalAPIResponse.class)
397 public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response,
398 @RequestBody Analytics analyticsMap) throws Exception {
400 if (analyticsMap!=null){
401 if (!dataValidator.isValid(analyticsMap))
402 return new PortalAPIResponse(false, "analyticsScript is not valid");
405 Map<String, Object> res = getMethod(request, response);
406 PortalAPIResponse ans = new PortalAPIResponse(true, "error");
408 ans = (PortalAPIResponse) invokeMethod(res, request, response, analyticsMap);
409 } catch (Exception e) {
410 logger.error(EELFLoggerDelegate.errorLogger, "storeAnalyticsScript failed", e);
416 @SuppressWarnings("unchecked")
417 @ApiOperation(value = "Bulk upload functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
418 @PostMapping(value = {
419 "/v3/upload/portal/functions" }, produces = "application/json")
420 public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response)
422 Optional<PortalRestResponse<String>> result = null;
423 Map<String, Object> res = getMethod(request, response);
425 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
426 if (!result.isPresent()){
427 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadFunctions", new Exception("Failed to bulkUploadFunctions"));
428 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadFunctions", "Failed");
430 } catch (Exception e) {
431 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e);
432 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
437 @SuppressWarnings("unchecked")
438 @ApiOperation(value = "Bulk upload roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
439 @PostMapping(value = { "/v3/upload/portal/roles" }, produces = "application/json")
440 public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response)
442 Optional<PortalRestResponse<String>> result;
443 Map<String, Object> res = getMethod(request, response);
445 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
446 if (!result.isPresent()){
447 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoles", new Exception("Failed to bulkUploadRoles"));
448 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoles", "Failed");
451 } catch (Exception e) {
452 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e);
453 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
457 @SuppressWarnings("unchecked")
458 @ApiOperation(value = "Bulk upload role functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
459 @PostMapping(value = {
460 "/v3/upload/portal/roleFunctions" }, produces = "application/json")
461 public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response)
463 Optional<PortalRestResponse<String>> result;
464 Map<String, Object> res = getMethod(request, response);
466 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
467 if (!result.isPresent()){
468 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoleFunctions", new Exception("Failed to bulkUploadRoleFunctions"));
469 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoleFunctions", "Failed");
472 } catch (Exception e) {
473 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoleFunctions failed", e);
474 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
478 @SuppressWarnings("unchecked")
479 @ApiOperation(value = "Bulk upload user roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
480 @PostMapping(value = {
481 "/v3/upload/portal/userRoles" }, produces = "application/json")
482 public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response)
484 Optional<PortalRestResponse<String>> result;
485 Map<String, Object> res = getMethod(request, response);
487 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
488 if (!result.isPresent()){
489 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadUserRoles", new Exception("Failed to bulkUploadUserRoles"));
490 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadUserRoles", "Failed");
493 } catch (Exception e) {
494 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUserRoles failed", e);
495 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
500 @SuppressWarnings("unchecked")
501 @ApiOperation(value = "Bulk upload users for renamed role of an application.", response = PortalRestResponse.class, responseContainer = "Json")
502 @PostMapping(value = {
503 "/v3/upload/portal/userRole/{roleId}" }, produces = "application/json")
504 public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request,
505 HttpServletResponse response, @PathVariable Long roleId) throws Exception {
506 Optional<PortalRestResponse<String>> result = null;
507 Map<String, Object> res = getMethod(request, response);
509 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
510 if (!result.isPresent()){
511 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadUsersSingleRole", new Exception("Failed to bulkUploadUsersSingleRole"));
512 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadUsersSingleRole", "Failed");
515 } catch (Exception e) {
516 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUsersSingleRole failed", e);
517 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
521 @SuppressWarnings("unchecked")
522 @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
523 @PostMapping(value = {
524 "/v3/upload/partner/functions" }, produces = "application/json")
525 public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request,
526 HttpServletResponse response) throws Exception {
527 Optional<PortalRestResponse<String>> result = null;
528 Map<String, Object> res = getMethod(request, response);
530 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
531 if (!result.isPresent()){
532 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadPartnerRoleFunctions", new Exception("Failed to bulkUploadPartnerRoleFunctions"));
533 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed");
536 } catch (Exception e) {
537 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerFunctions failed", e);
538 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
543 @SuppressWarnings("unchecked")
544 @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
545 @PostMapping(value = { "/v3/upload/partner/roles" }, produces = "application/json")
546 public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response,
547 @RequestBody List<Role> upload) throws Exception {
548 Optional<PortalRestResponse<String>> result = null;
549 Map<String, Object> res = getMethod(request, response);
551 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
552 if (!result.isPresent()){
553 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoles", new Exception("Failed to bulkUploadRoles"));
554 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoles", "Failed");
557 } catch (Exception e) {
558 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoles failed", e);
559 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
563 @SuppressWarnings("unchecked")
564 @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
565 @PostMapping(value = {
566 "/v3/upload/partner/roleFunctions" }, produces = "application/json")
567 public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request,
568 HttpServletResponse response) throws Exception {
569 Optional<PortalRestResponse<String>> result = null;
570 Map<String, Object> res = getMethod(request, response);
572 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
573 if (!result.isPresent()){
574 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadPartnerRoleFunctions", new Exception("Failed to bulkUploadPartnerRoleFunctions"));
575 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed");
578 } catch (Exception e) {
579 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoleFunctions failed", e);
580 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
584 @SuppressWarnings("unchecked")
585 @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json")
586 @GetMapping(value = { "/v3/menuFunctions" }, produces = "application/json")
587 public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception {
588 List<String> functionsList = null;
589 Map<String, Object> res = getMethod(request, response);
591 functionsList = (List<String>) invokeMethod(res, request, response);
592 } catch (Exception e) {
593 logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctions failed", e);
595 return functionsList;
598 private String getPatchNumber() {
599 String response = "0";
601 Attributes attributes = manifestService.getWebappManifest();
602 response = attributes.getValue("Build-Number");
603 } catch (Exception ex) {
604 logger.error(EELFLoggerDelegate.errorLogger, "getPatchNumber failed", ex);
609 @SuppressWarnings("rawtypes")
610 private List<Object> getObject(HttpServletRequest request, HttpServletResponse response) {
611 Map<String, Object> beans = context.getBeansWithAnnotation(ApiVersion.class);
612 @SuppressWarnings("unchecked")
613 List<Object> beansList = new ArrayList(beans.values());
618 private Map<String, Object> getMethod(HttpServletRequest request, HttpServletResponse response) {
619 Method finalmethod = null;
620 String url = request.getRequestURI();
623 Object currentObject = null;
624 Map<String, Object> res = new HashMap<String, Object>();
625 String[] uriArray = url.split("/auxapi");
626 List<Integer> minorversionList = new ArrayList<>();
627 if (uriArray.length > 1) {
628 service = uriArray[1];
630 int first = service.indexOf("/");
631 int second = service.indexOf("/", first + 1);
632 version = service.substring(first + 1, second);
633 int min = minorVersion;
634 if (request.getHeader("MinorVersion") != null) {
635 min = Integer.parseInt(request.getHeader("MinorVersion"));
637 res.put("min", version+"."+min);
638 res.put("service", service);
639 List<Object> objList = getObject(request, response);
640 String requestedApiMethodType = request.getMethod();
641 String majorVersion = latestMajorVersionOfService(objList, service, version, requestedApiMethodType);
642 int latestMinorVersion = latestMinorVersionOfService(objList, service, version, requestedApiMethodType);
643 res.put("majorVersion", majorVersion);
644 res.put("latestMinorVersion", String.valueOf(latestMinorVersion));
645 outerloop: for (Object obj : objList) {
646 final List<Method> allMethods = getAllMethodsOfClass(obj);
647 for (final Method method : allMethods) {
648 if (method.isAnnotationPresent(ApiVersion.class)) {
649 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
650 Pattern p = Pattern.compile(annotInstance.service(),
651 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
652 Matcher matcher = p.matcher(service);
653 boolean b = matcher.matches();
654 logger.debug(EELFLoggerDelegate.debugLogger, "Requested Servie is:" + service
655 + "Requested MinVersion is:" + min + "Requested MajorVersion is: " + version);
656 if (annotInstance.max().equals(version) && b && annotInstance.min() == min
657 && annotInstance.method().equals(request.getMethod())) {
658 finalmethod = method;
660 res.put("method", method);
670 private String latestMajorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
671 String requestedApiMethodType) {
672 Integer majorVersion = 0;
673 String serviceEndPoint = service;
674 int firstindex = serviceEndPoint.indexOf("/");
675 int secondindex = serviceEndPoint.indexOf("/", firstindex + 1);
676 serviceEndPoint = serviceEndPoint.substring(secondindex + 1);
678 List<Integer> latestMajorVersionList = new ArrayList<>();
679 for (Object obj : objList) {
680 final List<Method> allMethods = getAllMethodsOfClass(obj);
681 for (final Method method : allMethods) {
682 if (method.isAnnotationPresent(ApiVersion.class)) {
683 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
684 String endpoint = annotInstance.service();
685 int first = endpoint.indexOf("/");
686 int second = endpoint.indexOf("/", first + 1);
687 endpoint = endpoint.substring(second + 1);
688 Pattern p = Pattern.compile(endpoint,
689 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
690 Matcher matcher = p.matcher(serviceEndPoint);
691 boolean b = matcher.matches();
692 if (b && annotInstance.method().equals(requestedApiMethodType)) {
693 int index1 = annotInstance.service().indexOf("/");
694 int index2 = annotInstance.service().indexOf("/", index1 + 1);
695 String majorversion = annotInstance.service().substring(index1 + 2, index2);
696 latestMajorVersionList.add(Integer.parseInt(majorversion));
701 majorVersion = Collections.max(latestMajorVersionList);
702 String majorVersionWithLastestMin = "/v"+String.valueOf(majorVersion)+"/"+serviceEndPoint;
703 int latestMinorVersion = latestMinorVersionOfService(objList, majorVersionWithLastestMin, "v"+String.valueOf(majorVersion), requestedApiMethodType);
704 return majorVersion+"."+latestMinorVersion;
707 private List<Method> getAllMethodsOfClass(Object obj) {
708 List<Method> allMethods = new ArrayList<>();
709 Class<?> objClz = obj.getClass();
710 if (org.springframework.aop.support.AopUtils.isAopProxy(obj)) {
711 objClz = org.springframework.aop.support.AopUtils.getTargetClass(obj);
713 allMethods = new ArrayList<Method>(Arrays.asList(objClz.getMethods()));
714 allMethods.removeIf(s -> !(s.isAnnotationPresent(ApiVersion.class)));
718 private Integer latestMinorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
719 String requestedApiMethodType) {
720 Integer minVersion = 0;
721 String serviceEndPoint = service;
722 List<Integer> latestMinorVersionList = new ArrayList<>();
723 for (Object obj : objList) {
724 final List<Method> allMethods = getAllMethodsOfClass(obj);
725 for (final Method method : allMethods) {
726 if (method.isAnnotationPresent(ApiVersion.class)) {
727 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
728 String endpoint = annotInstance.service();
730 Pattern p = Pattern.compile(endpoint,
731 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
732 Matcher matcher = p.matcher(serviceEndPoint);
733 boolean b = matcher.matches();
734 if (annotInstance.max().equals(reuqestedVersion) && b
735 && annotInstance.method().equals(requestedApiMethodType)) {
736 int minorversion = annotInstance.min();
737 latestMinorVersionList.add(minorversion);
742 minVersion = Collections.max(latestMinorVersionList);
746 private HttpServletResponse setResponse(HttpServletResponse response, String requestedMinVersion,
747 String majorVersion, String latestMinorVersion, String service) {
748 response.setHeader("X-MinorVersion", requestedMinVersion.toUpperCase());
749 response.setHeader("X-PatchVersion", getPatchNumber());
750 response.setHeader("X-LatestVersion", "V"+majorVersion);
758 * method parameters(Maintain HttpServletRequest at 0th position
759 * and HttpServletResponse at 1th position in args array)
763 private Object invokeMethod(Map<String, Object> res, Object... args) throws Exception {
764 Method method = (Method) res.get("method");
765 Object obj = res.get("Obj");
766 Object responseObj = null;
767 String min = res.get("min").toString();
768 String majorVersion = res.get("majorVersion").toString();
769 String latestMinorVersion = res.get("latestMinorVersion").toString();
770 String service = res.get("service").toString();
771 HttpServletRequest request = (HttpServletRequest) args[0];
772 HttpServletResponse response = (HttpServletResponse) args[1];
773 setResponse(response, min, majorVersion, latestMinorVersion, service);
774 final Map<String, String> errorMap = new HashMap<>();
775 ObjectMapper mapper = new ObjectMapper();
778 if (method != null && obj != null) {
779 responseObj = method.invoke(obj, args);
781 errorMap.put("error", "Requested api is not available");
782 reason = mapper.writeValueAsString(errorMap);
783 response.getWriter().write(reason);
784 logger.debug(EELFLoggerDelegate.debugLogger, "Requested api " + request.getRequestURI()
785 + "is not available with minorVersion " + request.getHeader("MinorVersion"));
786 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
788 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
789 logger.error(EELFLoggerDelegate.errorLogger, "Method :" + method + "invocation failed", e);
795 public void setApplicationContext(ApplicationContext context) throws BeansException {
796 this.context = context;
799 @SuppressWarnings("unchecked")
800 @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class)
801 @PostMapping(value = { "/v3/userProfile" }, produces = "application/json")
802 public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
803 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
805 if (extSysUser!=null){
806 if (!dataValidator.isValid(extSysUser))
807 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
810 PortalRestResponse<String> result = null;
811 Map<String, Object> res = getMethod(request, response);
813 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
815 } catch (Exception e) {
816 logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile failed", e);
817 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
821 @SuppressWarnings("unchecked")
822 @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class)
823 @PutMapping(value = { "/v3/userProfile" }, produces = "application/json")
824 public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
825 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
827 if (extSysUser!=null){
828 if (!dataValidator.isValid(extSysUser))
829 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
832 PortalRestResponse<String> result = null;
833 Map<String, Object> res = getMethod(request, response);
835 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
837 } catch (Exception e) {
838 logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile failed", e);
839 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
843 @SuppressWarnings("unchecked")
844 @ApiOperation(value = "Processes a request to delete one or more application roles for one specified user who has roles.", response = PortalRestResponse.class)
845 @DeleteMapping(value = { "/v3/userProfile" }, produces = "application/json")
846 public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
847 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
849 if (extSysUser!=null){
850 if (!dataValidator.isValid(extSysUser))
851 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
854 PortalRestResponse<String> result = null;
855 Map<String, Object> res = getMethod(request, response);
857 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
859 } catch (Exception e) {
860 logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile failed", e);
861 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
865 @SuppressWarnings("unchecked")
866 @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class)
867 @PostMapping(value = { "/v3/ticketevent" })
868 public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
869 @RequestBody String ticketEventJson) throws Exception {
871 if (ticketEventJson!=null){
872 SecureString secureTicketEventJson = new SecureString(ticketEventJson);
873 if (!dataValidator.isValid(secureTicketEventJson))
874 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ticketEventJson is not valid", "Failed");
877 PortalRestResponse<String> result = null;
878 Map<String, Object> res = getMethod(request, response);
880 result = (PortalRestResponse<String>) invokeMethod(res, request, response, ticketEventJson);
882 } catch (Exception e) {
883 logger.error(EELFLoggerDelegate.errorLogger, "handleRequest failed", e);
884 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
888 @SuppressWarnings("unchecked")
889 @ApiOperation(value = "Creates a new user as a Portal administrator.", response = PortalRestResponse.class)
890 @PostMapping(value = "/v3/portalAdmin", produces = "application/json")
892 public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response,
893 @RequestBody EPUser epUser) {
896 if (!dataValidator.isValid(epUser))
897 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "EPUser is not valid", "Failed");
900 PortalRestResponse<String> result = null;
901 Map<String, Object> res = getMethod(request, response);
903 result = (PortalRestResponse<String>) invokeMethod(res, request, response, epUser);
905 } catch (Exception e) {
906 logger.error(EELFLoggerDelegate.errorLogger, "postPortalAdmin failed", e);
907 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
911 @ApiOperation(value = "Gets the specified application that is on-boarded in Portal.", response = OnboardingApp.class)
912 @GetMapping(value = { "/v3/onboardApp/{appId}" }, produces = "application/json")
914 public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
915 @PathVariable("appId") Long appId) {
916 OnboardingApp result = new OnboardingApp();
917 Map<String, Object> res = getMethod(request, response);
919 result = (OnboardingApp) invokeMethod(res, request, response, appId);
920 } catch (Exception e) {
921 logger.error(EELFLoggerDelegate.errorLogger, "getOnboardAppExternal failed", e);
926 @SuppressWarnings("unchecked")
927 @ApiOperation(value = "Adds a new application to Portal.", response = PortalRestResponse.class)
928 @PostMapping(value = { "/v3/onboardApp" }, produces = "application/json")
930 public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
931 @RequestBody OnboardingApp newOnboardApp) {
933 if (newOnboardApp!=null){
934 if (!dataValidator.isValid(newOnboardApp))
935 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
938 PortalRestResponse<String> result = new PortalRestResponse<>();
939 Map<String, Object> res = getMethod(request, response);
941 result = (PortalRestResponse<String>) invokeMethod(res, request, response, newOnboardApp);
943 } catch (Exception e) {
944 logger.error(EELFLoggerDelegate.errorLogger, "postOnboardAppExternal failed", e);
945 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
950 @SuppressWarnings("unchecked")
951 @ApiOperation(value = "Updates information about an on-boarded application in Portal.", response = PortalRestResponse.class)
952 @PutMapping(value = { "/v3/onboardApp/{appId}" }, produces = "application/json")
954 public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
955 @PathVariable("appId") Long appId, @RequestBody OnboardingApp oldOnboardApp) {
957 if (oldOnboardApp!=null){
958 if (!dataValidator.isValid(oldOnboardApp))
959 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
962 PortalRestResponse<String> result;
963 Map<String, Object> res = getMethod(request, response);
965 result = (PortalRestResponse<String>) invokeMethod(res, request, response, appId, oldOnboardApp);
967 } catch (Exception e) {
968 logger.error(EELFLoggerDelegate.errorLogger, "putOnboardAppExternal failed", e);
969 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
973 @ApiOperation(value = "Creates a Portal user notification for roles identified in the content from an external application.", response = PortalAPIResponse.class)
974 @PostMapping(value = { "/v3/publishNotification" }, produces = "application/json")
976 public PortalAPIResponse publishNotification(HttpServletRequest request,
977 @RequestBody EpNotificationItem notificationItem, HttpServletResponse response) {
979 if (notificationItem!=null){
980 if (!dataValidator.isValid(notificationItem))
981 return new PortalAPIResponse(false, "EpNotificationItem is not valid");
984 Map<String, Object> res = getMethod(request, response);
986 return (PortalAPIResponse) invokeMethod(res, request, response, notificationItem);
987 } catch (Exception e) {
988 logger.error(EELFLoggerDelegate.errorLogger, "publishNotification failed", e);
989 return new PortalAPIResponse(false, e.getMessage());
993 @SuppressWarnings("unchecked")
994 @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer = "List")
995 @GetMapping(value = { "/v3/getFavorites" }, produces = "application/json")
996 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
997 HttpServletResponse response) throws Exception {
998 List<FavoritesFunctionalMenuItemJson> favorites = null;
999 Map<String, Object> res = getMethod(request, response);
1001 favorites = (List<FavoritesFunctionalMenuItemJson>) invokeMethod(res, request, response);
1002 } catch (Exception e) {
1003 logger.error(EELFLoggerDelegate.errorLogger, "getFavoritesForUser failed", e);
1008 @SuppressWarnings("unchecked")
1009 @ApiOperation(value = "Gets functional menu items appropriate for the current user.", response = FunctionalMenuItem.class, responseContainer = "List")
1010 @GetMapping(value = {
1011 "/v3/functionalMenuItemsForUser" }, produces = "application/json")
1012 public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request,
1013 HttpServletResponse response) throws Exception {
1014 List<FunctionalMenuItem> fnMenuItems = null;
1015 Map<String, Object> res = getMethod(request, response);
1017 fnMenuItems = (List<FunctionalMenuItem>) invokeMethod(res, request, response);
1018 } catch (Exception e) {
1019 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser failed", e);
1025 @ApiOperation(value = "Gets MechId roles", response = String.class, responseContainer = "List")
1026 @GetMapping(value = { "/v3/systemUser" }, produces = "application/json")
1027 public List<AAFPermission> getSystemUserPerms(HttpServletRequest request, HttpServletResponse response) throws Exception {
1028 List<AAFPermission> permsList = null;
1029 Map<String, Object> res = getMethod(request, response);
1031 permsList = (List<AAFPermission>) invokeMethod(res, request, response);
1032 } catch (Exception e) {
1033 logger.error(EELFLoggerDelegate.errorLogger, "getSystemUserPerms failed", e);
1038 @ApiOperation(value = "Update role description in external auth system for an application.", response = PortalRestResponse.class, responseContainer = "Json")
1039 @PutMapping(value = { "/v3/update/app/roleDescription" }, produces = "application/json")
1040 public PortalRestResponse<String> updateAppRoleDescription(HttpServletRequest request, HttpServletResponse response) throws Exception {
1041 PortalRestResponse<String> result = null;
1042 Map<String, Object> res = getMethod(request, response);
1044 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
1046 } catch (Exception e) {
1047 logger.error(EELFLoggerDelegate.errorLogger, "updateAppRoleDescription failed", e);
1048 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");