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.RequestMethod;
88 import org.springframework.web.bind.annotation.RequestParam;
89 import org.springframework.web.bind.annotation.ResponseBody;
90 import org.springframework.web.bind.annotation.RestController;
93 @RequestMapping("/auxapi")
95 @EnableAspectJAutoProxy
97 public class AuxApiRequestMapperController implements ApplicationContextAware, BasicAuthenticationController {
99 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AuxApiRequestMapperController.class);
100 private DataValidator dataValidator = new DataValidator();
102 ApplicationContext context = null;
103 int minorVersion = 0;
106 private ManifestService manifestService;
108 @ApiOperation(value = "Gets user roles for an application which is upgraded to newer version.", response = String.class, responseContainer = "List")
109 @RequestMapping(value = { "/v3/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
110 public String getUser(HttpServletRequest request, HttpServletResponse response,
111 @PathVariable("loginId") String loginId) throws Exception {
113 SecureString secureLoginId = new SecureString(loginId);
114 if (!dataValidator.isValid(secureLoginId))
115 return "Provided data is not valid";
119 Map<String, Object> res = getMethod(request, response);
120 String answer = null;
122 answer = (String) invokeMethod(res, request, response, loginId);
123 } catch (Exception e) {
124 logger.error(EELFLoggerDelegate.errorLogger, "getUser failed", e);
129 @SuppressWarnings("unchecked")
130 @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
131 @RequestMapping(value = { "/v3/roles" }, method = RequestMethod.GET, produces = "application/json")
132 public List<CentralV2Role> getRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
133 Map<String, Object> res = getMethod(request, response);
135 List<CentralV2Role> answer = null;
137 answer = (List<CentralV2Role>) invokeMethod(res, request, response);
138 } catch (Exception e) {
139 logger.error(EELFLoggerDelegate.errorLogger, "getRoles failed", e);
144 @SuppressWarnings("unchecked")
145 @ApiOperation(value = "Saves role for an application.", response = PortalRestResponse.class, responseContainer = "Json")
146 @RequestMapping(value = { "/v3/role" }, method = RequestMethod.POST, produces = "application/json")
147 public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response,
148 @RequestBody Role role) throws Exception {
149 Map<String, Object> res = getMethod(request, response);
150 PortalRestResponse<String> out = null;
152 out = (PortalRestResponse<String>) invokeMethod(res, request, response, role);
153 } catch (Exception e) {
154 logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e);
155 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
160 @ApiOperation(value = "Gets v2 role information for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
161 @RequestMapping(value = { "/v3/role/{role_id}" }, method = RequestMethod.GET, produces = "application/json")
162 public CentralV2Role getRoleInfo(HttpServletRequest request, HttpServletResponse response,
163 @PathVariable("role_id") Long roleId) throws Exception {
164 Map<String, Object> res = getMethod(request, response);
165 CentralV2Role role = null;
167 role = (CentralV2Role) invokeMethod(res, request, response, roleId);
168 } catch (Exception e) {
169 logger.error(EELFLoggerDelegate.errorLogger, "getRoleInfo failed", e);
175 @SuppressWarnings("unchecked")
176 @ApiOperation(value = "Gets all active Users of application", response = String.class, responseContainer = "Json")
177 @RequestMapping(value = { "/v3/users" }, method = RequestMethod.GET, produces = "application/json")
178 public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response)
180 Map<String, Object> res = getMethod(request, response);
181 List<EcompUser> users = null;
183 users = (List<EcompUser>) invokeMethod(res, request, response);
184 } catch (Exception e) {
185 logger.error(EELFLoggerDelegate.errorLogger, "getUsersOfApplication failed", e);
190 @SuppressWarnings("unchecked")
191 @ApiOperation(value = "Gets all role functions for an application which is upgraded to newer version.", response = CentralV2RoleFunction.class, responseContainer = "Json")
192 @RequestMapping(value = { "/v3/functions" }, method = RequestMethod.GET, produces = "application/json")
193 public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
195 Map<String, Object> res = getMethod(request, response);
196 List<CentralV2RoleFunction> roleFunctionsList = null;
198 roleFunctionsList = (List<CentralV2RoleFunction>) invokeMethod(res, request, response);
199 } catch (Exception e) {
200 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunctionsList failed", e);
202 return roleFunctionsList;
205 @ApiOperation(value = "Gets role information for an application provided by function code.", response = CentralV2RoleFunction.class, responseContainer = "Json")
206 @RequestMapping(value = { "/v3/function/{code}" }, method = RequestMethod.GET, produces = "application/json")
207 public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response,
208 @PathVariable("code") String code) throws Exception {
210 SecureString secureCode = new SecureString(code);
211 if (!dataValidator.isValid(secureCode))
212 return new CentralV2RoleFunction();
215 Map<String, Object> res = getMethod(request, response);
216 CentralV2RoleFunction roleFunction = null;
218 roleFunction = (CentralV2RoleFunction) invokeMethod(res, request, response, code);
219 } catch (Exception e) {
220 logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e);
225 @SuppressWarnings("unchecked")
226 @ApiOperation(value = "Saves role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
227 @RequestMapping(value = { "/v3/roleFunction" }, method = RequestMethod.POST, produces = "application/json")
228 public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response,
229 @RequestBody String roleFunc) throws Exception {
231 SecureString secureRoleFunc = new SecureString(roleFunc);
232 if(!dataValidator.isValid(secureRoleFunc))
233 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
235 Optional<PortalRestResponse<String>> result = null;
236 Map<String, Object> res = getMethod(request, response);
238 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
239 if (!result.isPresent()){
240 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", new Exception("saveRoleFunction failed"));
241 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "saveRoleFunction failed", "Failed");
243 } catch (Exception e) {
244 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e);
245 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
250 @SuppressWarnings("unchecked")
251 @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
252 @RequestMapping(value = { "/v3/roleFunction/{code}" }, method = RequestMethod.DELETE, produces = "application/json")
253 public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response,
254 @PathVariable("code") String code) throws Exception {
255 PortalRestResponse<String> result = null;
258 SecureString secureCode = new SecureString(code);
259 if(!dataValidator.isValid(secureCode))
260 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
263 Map<String, Object> res = getMethod(request, response);
265 result = (PortalRestResponse<String>) invokeMethod(res, request, response, code);
267 } catch (Exception e) {
268 logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction failed", e);
269 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
273 @SuppressWarnings("unchecked")
274 @ApiOperation(value = "deletes roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
275 @RequestMapping(value = { "/v3/deleteRole/{roleId}" }, method = RequestMethod.DELETE, produces = "application/json")
276 public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response,
277 @PathVariable("roleId") Long roleId) throws Exception {
278 PortalRestResponse<String> result = null;
279 Map<String, Object> res = getMethod(request, response);
281 result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
283 } catch (Exception e) {
284 logger.error(EELFLoggerDelegate.errorLogger, "deleteRole failed", e);
285 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
289 @SuppressWarnings("unchecked")
290 @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
291 @RequestMapping(value = { "/v3/activeRoles" }, method = RequestMethod.GET, produces = "application/json")
292 public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response)
294 List<CentralV2Role> cenRole = null;
295 Map<String, Object> res = getMethod(request, response);
297 cenRole = (List<CentralV2Role>) invokeMethod(res, request, response);
298 } catch (Exception e) {
299 logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
304 @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List")
305 @RequestMapping(value = { "/v4/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
306 public String getEcompUser(HttpServletRequest request, HttpServletResponse response,
307 @PathVariable("loginId") String loginId) throws Exception {
308 Map<String, Object> res = getMethod(request, response);
311 SecureString secureLoginId = new SecureString(loginId);
313 if (!dataValidator.isValid(secureLoginId))
317 String answer = null;
319 answer = (String) invokeMethod(res, request, response, loginId);
320 } catch (Exception e) {
321 logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e);
326 @SuppressWarnings("unchecked")
327 @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List")
328 @RequestMapping(value = { "/v4/roles" }, method = RequestMethod.GET, produces = "application/json")
329 public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response)
331 Map<String, Object> res = getMethod(request, response);
332 List<EcompRole> answer = null;
334 answer = (List<EcompRole>) invokeMethod(res, request, response);
335 } catch (Exception e) {
336 logger.error(EELFLoggerDelegate.errorLogger, "getEcompRolesOfApplication failed", e);
341 @ApiOperation(value = "Gets session slot-check interval, a duration in milliseconds.", response = Integer.class)
342 @RequestMapping(value = {
343 "/v3/getSessionSlotCheckInterval" }, method = RequestMethod.GET, produces = "application/json")
344 public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response)
346 Map<String, Object> res = getMethod(request, response);
349 ans = (Integer) invokeMethod(res, request, response);
350 } catch (Exception e) {
351 logger.error(EELFLoggerDelegate.errorLogger, "getSessionSlotCheckInterval failed", e);
356 @ApiOperation(value = "Extends session timeout values for all on-boarded applications.", response = Boolean.class)
357 @RequestMapping(value = { "/v3/extendSessionTimeOuts" }, method = RequestMethod.POST)
358 public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response,
359 @RequestParam String sessionMap) throws Exception {
361 if (sessionMap!=null){
362 SecureString secureSessionMap = new SecureString(sessionMap);
363 if (!dataValidator.isValid(secureSessionMap)){
368 Map<String, Object> res = getMethod(request, response);
371 ans = (Boolean) invokeMethod(res, request, response, sessionMap);
372 } catch (Exception e) {
373 logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts failed", e);
378 @ApiOperation(value = "Gets javascript with functions that support gathering and reporting web analytics.", response = String.class)
379 @RequestMapping(value = { "/v3/analytics" }, method = RequestMethod.GET, produces = "application/javascript")
380 public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception {
381 Map<String, Object> res = getMethod(request, response);
384 ans = (String) invokeMethod(res, request, response);
385 } catch (Exception e) {
386 logger.error(EELFLoggerDelegate.errorLogger, "getAnalyticsScript failed", e);
391 @RequestMapping(value = { "/v3/storeAnalytics" }, method = RequestMethod.POST, produces = "application/json")
393 @ApiOperation(value = "Accepts data from partner applications with web analytics data.", response = PortalAPIResponse.class)
394 public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response,
395 @RequestBody Analytics analyticsMap) throws Exception {
397 if (analyticsMap!=null){
398 if (!dataValidator.isValid(analyticsMap))
399 return new PortalAPIResponse(false, "analyticsScript is not valid");
402 Map<String, Object> res = getMethod(request, response);
403 PortalAPIResponse ans = new PortalAPIResponse(true, "error");
405 ans = (PortalAPIResponse) invokeMethod(res, request, response, analyticsMap);
406 } catch (Exception e) {
407 logger.error(EELFLoggerDelegate.errorLogger, "storeAnalyticsScript failed", e);
413 @SuppressWarnings("unchecked")
414 @ApiOperation(value = "Bulk upload functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
415 @RequestMapping(value = {
416 "/v3/upload/portal/functions" }, method = RequestMethod.POST, produces = "application/json")
417 public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response)
419 Optional<PortalRestResponse<String>> result = null;
420 Map<String, Object> res = getMethod(request, response);
422 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
423 if (!result.isPresent()){
424 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadFunctions", new Exception("Failed to bulkUploadFunctions"));
425 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadFunctions", "Failed");
427 } catch (Exception e) {
428 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e);
429 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
434 @SuppressWarnings("unchecked")
435 @ApiOperation(value = "Bulk upload roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
436 @RequestMapping(value = { "/v3/upload/portal/roles" }, method = RequestMethod.POST, produces = "application/json")
437 public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response)
439 Optional<PortalRestResponse<String>> result;
440 Map<String, Object> res = getMethod(request, response);
442 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
443 if (!result.isPresent()){
444 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoles", new Exception("Failed to bulkUploadRoles"));
445 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoles", "Failed");
448 } catch (Exception e) {
449 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e);
450 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
454 @SuppressWarnings("unchecked")
455 @ApiOperation(value = "Bulk upload role functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
456 @RequestMapping(value = {
457 "/v3/upload/portal/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
458 public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response)
460 Optional<PortalRestResponse<String>> result;
461 Map<String, Object> res = getMethod(request, response);
463 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
464 if (!result.isPresent()){
465 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoleFunctions", new Exception("Failed to bulkUploadRoleFunctions"));
466 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoleFunctions", "Failed");
469 } catch (Exception e) {
470 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoleFunctions failed", e);
471 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
475 @SuppressWarnings("unchecked")
476 @ApiOperation(value = "Bulk upload user roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
477 @RequestMapping(value = {
478 "/v3/upload/portal/userRoles" }, method = RequestMethod.POST, produces = "application/json")
479 public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response)
481 Optional<PortalRestResponse<String>> result;
482 Map<String, Object> res = getMethod(request, response);
484 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
485 if (!result.isPresent()){
486 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadUserRoles", new Exception("Failed to bulkUploadUserRoles"));
487 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadUserRoles", "Failed");
490 } catch (Exception e) {
491 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUserRoles failed", e);
492 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
497 @SuppressWarnings("unchecked")
498 @ApiOperation(value = "Bulk upload users for renamed role of an application.", response = PortalRestResponse.class, responseContainer = "Json")
499 @RequestMapping(value = {
500 "/v3/upload/portal/userRole/{roleId}" }, method = RequestMethod.POST, produces = "application/json")
501 public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request,
502 HttpServletResponse response, @PathVariable Long roleId) throws Exception {
503 Optional<PortalRestResponse<String>> result = null;
504 Map<String, Object> res = getMethod(request, response);
506 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
507 if (!result.isPresent()){
508 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadUsersSingleRole", new Exception("Failed to bulkUploadUsersSingleRole"));
509 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadUsersSingleRole", "Failed");
512 } catch (Exception e) {
513 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUsersSingleRole failed", e);
514 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
518 @SuppressWarnings("unchecked")
519 @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
520 @RequestMapping(value = {
521 "/v3/upload/partner/functions" }, method = RequestMethod.POST, produces = "application/json")
522 public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request,
523 HttpServletResponse response) throws Exception {
524 Optional<PortalRestResponse<String>> result = null;
525 Map<String, Object> res = getMethod(request, response);
527 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
528 if (!result.isPresent()){
529 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadPartnerRoleFunctions", new Exception("Failed to bulkUploadPartnerRoleFunctions"));
530 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed");
533 } catch (Exception e) {
534 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerFunctions failed", e);
535 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
540 @SuppressWarnings("unchecked")
541 @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
542 @RequestMapping(value = { "/v3/upload/partner/roles" }, method = RequestMethod.POST, produces = "application/json")
543 public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response,
544 @RequestBody List<Role> upload) throws Exception {
545 Optional<PortalRestResponse<String>> result = null;
546 Map<String, Object> res = getMethod(request, response);
548 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
549 if (!result.isPresent()){
550 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoles", new Exception("Failed to bulkUploadRoles"));
551 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoles", "Failed");
554 } catch (Exception e) {
555 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoles failed", e);
556 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
560 @SuppressWarnings("unchecked")
561 @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
562 @RequestMapping(value = {
563 "/v3/upload/partner/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
564 public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request,
565 HttpServletResponse response) throws Exception {
566 Optional<PortalRestResponse<String>> result = null;
567 Map<String, Object> res = getMethod(request, response);
569 result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
570 if (!result.isPresent()){
571 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadPartnerRoleFunctions", new Exception("Failed to bulkUploadPartnerRoleFunctions"));
572 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed");
575 } catch (Exception e) {
576 logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoleFunctions failed", e);
577 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
581 @SuppressWarnings("unchecked")
582 @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json")
583 @RequestMapping(value = { "/v3/menuFunctions" }, method = RequestMethod.GET, produces = "application/json")
584 public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception {
585 List<String> functionsList = null;
586 Map<String, Object> res = getMethod(request, response);
588 functionsList = (List<String>) invokeMethod(res, request, response);
589 } catch (Exception e) {
590 logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctions failed", e);
592 return functionsList;
595 private String getPatchNumber() {
596 String response = "0";
598 Attributes attributes = manifestService.getWebappManifest();
599 response = attributes.getValue("Build-Number");
600 } catch (Exception ex) {
601 logger.error(EELFLoggerDelegate.errorLogger, "getPatchNumber failed", ex);
606 @SuppressWarnings("rawtypes")
607 private List<Object> getObject(HttpServletRequest request, HttpServletResponse response) {
608 Map<String, Object> beans = context.getBeansWithAnnotation(ApiVersion.class);
609 @SuppressWarnings("unchecked")
610 List<Object> beansList = new ArrayList(beans.values());
615 private Map<String, Object> getMethod(HttpServletRequest request, HttpServletResponse response) {
616 Method finalmethod = null;
617 String url = request.getRequestURI();
620 Object currentObject = null;
621 Map<String, Object> res = new HashMap<String, Object>();
622 String[] uriArray = url.split("/auxapi");
623 List<Integer> minorversionList = new ArrayList<>();
624 if (uriArray.length > 1) {
625 service = uriArray[1];
627 int first = service.indexOf("/");
628 int second = service.indexOf("/", first + 1);
629 version = service.substring(first + 1, second);
630 int min = minorVersion;
631 if (request.getHeader("MinorVersion") != null) {
632 min = Integer.parseInt(request.getHeader("MinorVersion"));
634 res.put("min", version+"."+min);
635 res.put("service", service);
636 List<Object> objList = getObject(request, response);
637 String requestedApiMethodType = request.getMethod();
638 String majorVersion = latestMajorVersionOfService(objList, service, version, requestedApiMethodType);
639 int latestMinorVersion = latestMinorVersionOfService(objList, service, version, requestedApiMethodType);
640 res.put("majorVersion", majorVersion);
641 res.put("latestMinorVersion", String.valueOf(latestMinorVersion));
642 outerloop: for (Object obj : objList) {
643 final List<Method> allMethods = getAllMethodsOfClass(obj);
644 for (final Method method : allMethods) {
645 if (method.isAnnotationPresent(ApiVersion.class)) {
646 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
647 Pattern p = Pattern.compile(annotInstance.service(),
648 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
649 Matcher matcher = p.matcher(service);
650 boolean b = matcher.matches();
651 logger.debug(EELFLoggerDelegate.debugLogger, "Requested Servie is:" + service
652 + "Requested MinVersion is:" + min + "Requested MajorVersion is: " + version);
653 if (annotInstance.max().equals(version) && b && annotInstance.min() == min
654 && annotInstance.method().equals(request.getMethod())) {
655 finalmethod = method;
657 res.put("method", method);
667 private String latestMajorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
668 String requestedApiMethodType) {
669 Integer majorVersion = 0;
670 String serviceEndPoint = service;
671 int firstindex = serviceEndPoint.indexOf("/");
672 int secondindex = serviceEndPoint.indexOf("/", firstindex + 1);
673 serviceEndPoint = serviceEndPoint.substring(secondindex + 1);
675 List<Integer> latestMajorVersionList = new ArrayList<>();
676 for (Object obj : objList) {
677 final List<Method> allMethods = getAllMethodsOfClass(obj);
678 for (final Method method : allMethods) {
679 if (method.isAnnotationPresent(ApiVersion.class)) {
680 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
681 String endpoint = annotInstance.service();
682 int first = endpoint.indexOf("/");
683 int second = endpoint.indexOf("/", first + 1);
684 endpoint = endpoint.substring(second + 1);
685 Pattern p = Pattern.compile(endpoint,
686 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
687 Matcher matcher = p.matcher(serviceEndPoint);
688 boolean b = matcher.matches();
689 if (b && annotInstance.method().equals(requestedApiMethodType)) {
690 int index1 = annotInstance.service().indexOf("/");
691 int index2 = annotInstance.service().indexOf("/", index1 + 1);
692 String majorversion = annotInstance.service().substring(index1 + 2, index2);
693 latestMajorVersionList.add(Integer.parseInt(majorversion));
698 majorVersion = Collections.max(latestMajorVersionList);
699 String majorVersionWithLastestMin = "/v"+String.valueOf(majorVersion)+"/"+serviceEndPoint;
700 int latestMinorVersion = latestMinorVersionOfService(objList, majorVersionWithLastestMin, "v"+String.valueOf(majorVersion), requestedApiMethodType);
701 return majorVersion+"."+latestMinorVersion;
704 private List<Method> getAllMethodsOfClass(Object obj) {
705 List<Method> allMethods = new ArrayList<>();
706 Class<?> objClz = obj.getClass();
707 if (org.springframework.aop.support.AopUtils.isAopProxy(obj)) {
708 objClz = org.springframework.aop.support.AopUtils.getTargetClass(obj);
710 allMethods = new ArrayList<Method>(Arrays.asList(objClz.getMethods()));
711 allMethods.removeIf(s -> !(s.isAnnotationPresent(ApiVersion.class)));
715 private Integer latestMinorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
716 String requestedApiMethodType) {
717 Integer minVersion = 0;
718 String serviceEndPoint = service;
719 List<Integer> latestMinorVersionList = new ArrayList<>();
720 for (Object obj : objList) {
721 final List<Method> allMethods = getAllMethodsOfClass(obj);
722 for (final Method method : allMethods) {
723 if (method.isAnnotationPresent(ApiVersion.class)) {
724 ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
725 String endpoint = annotInstance.service();
727 Pattern p = Pattern.compile(endpoint,
728 Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
729 Matcher matcher = p.matcher(serviceEndPoint);
730 boolean b = matcher.matches();
731 if (annotInstance.max().equals(reuqestedVersion) && b
732 && annotInstance.method().equals(requestedApiMethodType)) {
733 int minorversion = annotInstance.min();
734 latestMinorVersionList.add(minorversion);
739 minVersion = Collections.max(latestMinorVersionList);
743 private HttpServletResponse setResponse(HttpServletResponse response, String requestedMinVersion,
744 String majorVersion, String latestMinorVersion, String service) {
745 response.setHeader("X-MinorVersion", requestedMinVersion.toUpperCase());
746 response.setHeader("X-PatchVersion", getPatchNumber());
747 response.setHeader("X-LatestVersion", "V"+majorVersion);
755 * method parameters(Maintain HttpServletRequest at 0th position
756 * and HttpServletResponse at 1th position in args array)
760 private Object invokeMethod(Map<String, Object> res, Object... args) throws Exception {
761 Method method = (Method) res.get("method");
762 Object obj = res.get("Obj");
763 Object responseObj = null;
764 String min = res.get("min").toString();
765 String majorVersion = res.get("majorVersion").toString();
766 String latestMinorVersion = res.get("latestMinorVersion").toString();
767 String service = res.get("service").toString();
768 HttpServletRequest request = (HttpServletRequest) args[0];
769 HttpServletResponse response = (HttpServletResponse) args[1];
770 setResponse(response, min, majorVersion, latestMinorVersion, service);
771 final Map<String, String> errorMap = new HashMap<>();
772 ObjectMapper mapper = new ObjectMapper();
775 if (method != null && obj != null) {
776 responseObj = method.invoke(obj, args);
778 errorMap.put("error", "Requested api is not available");
779 reason = mapper.writeValueAsString(errorMap);
780 response.getWriter().write(reason);
781 logger.debug(EELFLoggerDelegate.debugLogger, "Requested api " + request.getRequestURI()
782 + "is not available with minorVersion " + request.getHeader("MinorVersion"));
783 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
785 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
786 logger.error(EELFLoggerDelegate.errorLogger, "Method :" + method + "invocation failed", e);
792 public void setApplicationContext(ApplicationContext context) throws BeansException {
793 this.context = context;
796 @SuppressWarnings("unchecked")
797 @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class)
798 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.POST, produces = "application/json")
799 public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
800 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
802 if (extSysUser!=null){
803 if (!dataValidator.isValid(extSysUser))
804 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
807 PortalRestResponse<String> result = null;
808 Map<String, Object> res = getMethod(request, response);
810 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
812 } catch (Exception e) {
813 logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile failed", e);
814 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
818 @SuppressWarnings("unchecked")
819 @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class)
820 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.PUT, produces = "application/json")
821 public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
822 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
824 if (extSysUser!=null){
825 if (!dataValidator.isValid(extSysUser))
826 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
829 PortalRestResponse<String> result = null;
830 Map<String, Object> res = getMethod(request, response);
832 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
834 } catch (Exception e) {
835 logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile failed", e);
836 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
840 @SuppressWarnings("unchecked")
841 @ApiOperation(value = "Processes a request to delete one or more application roles for one specified user who has roles.", response = PortalRestResponse.class)
842 @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.DELETE, produces = "application/json")
843 public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
844 @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
846 if (extSysUser!=null){
847 if (!dataValidator.isValid(extSysUser))
848 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
851 PortalRestResponse<String> result = null;
852 Map<String, Object> res = getMethod(request, response);
854 result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
856 } catch (Exception e) {
857 logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile failed", e);
858 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
862 @SuppressWarnings("unchecked")
863 @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class)
864 @RequestMapping(value = { "/v3/ticketevent" }, method = RequestMethod.POST)
865 public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
866 @RequestBody String ticketEventJson) throws Exception {
868 if (ticketEventJson!=null){
869 SecureString secureTicketEventJson = new SecureString(ticketEventJson);
870 if (!dataValidator.isValid(secureTicketEventJson))
871 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ticketEventJson is not valid", "Failed");
874 PortalRestResponse<String> result = null;
875 Map<String, Object> res = getMethod(request, response);
877 result = (PortalRestResponse<String>) invokeMethod(res, request, response, ticketEventJson);
879 } catch (Exception e) {
880 logger.error(EELFLoggerDelegate.errorLogger, "handleRequest failed", e);
881 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
885 @SuppressWarnings("unchecked")
886 @ApiOperation(value = "Creates a new user as a Portal administrator.", response = PortalRestResponse.class)
887 @RequestMapping(value = "/v3/portalAdmin", method = RequestMethod.POST, produces = "application/json")
889 public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response,
890 @RequestBody EPUser epUser) {
893 if (!dataValidator.isValid(epUser))
894 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "EPUser is not valid", "Failed");
897 PortalRestResponse<String> result = null;
898 Map<String, Object> res = getMethod(request, response);
900 result = (PortalRestResponse<String>) invokeMethod(res, request, response, epUser);
902 } catch (Exception e) {
903 logger.error(EELFLoggerDelegate.errorLogger, "postPortalAdmin failed", e);
904 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
908 @ApiOperation(value = "Gets the specified application that is on-boarded in Portal.", response = OnboardingApp.class)
909 @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.GET, produces = "application/json")
911 public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
912 @PathVariable("appId") Long appId) {
913 OnboardingApp result = new OnboardingApp();
914 Map<String, Object> res = getMethod(request, response);
916 result = (OnboardingApp) invokeMethod(res, request, response, appId);
917 } catch (Exception e) {
918 logger.error(EELFLoggerDelegate.errorLogger, "getOnboardAppExternal failed", e);
923 @SuppressWarnings("unchecked")
924 @ApiOperation(value = "Adds a new application to Portal.", response = PortalRestResponse.class)
925 @RequestMapping(value = { "/v3/onboardApp" }, method = RequestMethod.POST, produces = "application/json")
927 public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
928 @RequestBody OnboardingApp newOnboardApp) {
930 if (newOnboardApp!=null){
931 if (!dataValidator.isValid(newOnboardApp))
932 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
935 PortalRestResponse<String> result = new PortalRestResponse<>();
936 Map<String, Object> res = getMethod(request, response);
938 result = (PortalRestResponse<String>) invokeMethod(res, request, response, newOnboardApp);
940 } catch (Exception e) {
941 logger.error(EELFLoggerDelegate.errorLogger, "postOnboardAppExternal failed", e);
942 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
947 @SuppressWarnings("unchecked")
948 @ApiOperation(value = "Updates information about an on-boarded application in Portal.", response = PortalRestResponse.class)
949 @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.PUT, produces = "application/json")
951 public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
952 @PathVariable("appId") Long appId, @RequestBody OnboardingApp oldOnboardApp) {
954 if (oldOnboardApp!=null){
955 if (!dataValidator.isValid(oldOnboardApp))
956 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
959 PortalRestResponse<String> result;
960 Map<String, Object> res = getMethod(request, response);
962 result = (PortalRestResponse<String>) invokeMethod(res, request, response, appId, oldOnboardApp);
964 } catch (Exception e) {
965 logger.error(EELFLoggerDelegate.errorLogger, "putOnboardAppExternal failed", e);
966 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
970 @ApiOperation(value = "Creates a Portal user notification for roles identified in the content from an external application.", response = PortalAPIResponse.class)
971 @RequestMapping(value = { "/v3/publishNotification" }, method = RequestMethod.POST, produces = "application/json")
973 public PortalAPIResponse publishNotification(HttpServletRequest request,
974 @RequestBody EpNotificationItem notificationItem, HttpServletResponse response) {
976 if (notificationItem!=null){
977 if (!dataValidator.isValid(notificationItem))
978 return new PortalAPIResponse(false, "EpNotificationItem is not valid");
981 Map<String, Object> res = getMethod(request, response);
983 return (PortalAPIResponse) invokeMethod(res, request, response, notificationItem);
984 } catch (Exception e) {
985 logger.error(EELFLoggerDelegate.errorLogger, "publishNotification failed", e);
986 return new PortalAPIResponse(false, e.getMessage());
990 @SuppressWarnings("unchecked")
991 @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer = "List")
992 @RequestMapping(value = { "/v3/getFavorites" }, method = RequestMethod.GET, produces = "application/json")
993 public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
994 HttpServletResponse response) throws Exception {
995 List<FavoritesFunctionalMenuItemJson> favorites = null;
996 Map<String, Object> res = getMethod(request, response);
998 favorites = (List<FavoritesFunctionalMenuItemJson>) invokeMethod(res, request, response);
999 } catch (Exception e) {
1000 logger.error(EELFLoggerDelegate.errorLogger, "getFavoritesForUser failed", e);
1005 @SuppressWarnings("unchecked")
1006 @ApiOperation(value = "Gets functional menu items appropriate for the current user.", response = FunctionalMenuItem.class, responseContainer = "List")
1007 @RequestMapping(value = {
1008 "/v3/functionalMenuItemsForUser" }, method = RequestMethod.GET, produces = "application/json")
1009 public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request,
1010 HttpServletResponse response) throws Exception {
1011 List<FunctionalMenuItem> fnMenuItems = null;
1012 Map<String, Object> res = getMethod(request, response);
1014 fnMenuItems = (List<FunctionalMenuItem>) invokeMethod(res, request, response);
1015 } catch (Exception e) {
1016 logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser failed", e);
1022 @ApiOperation(value = "Gets MechId roles", response = String.class, responseContainer = "List")
1023 @RequestMapping(value = { "/v3/systemUser" }, method = RequestMethod.GET, produces = "application/json")
1024 public List<AAFPermission> getSystemUserPerms(HttpServletRequest request, HttpServletResponse response) throws Exception {
1025 List<AAFPermission> permsList = null;
1026 Map<String, Object> res = getMethod(request, response);
1028 permsList = (List<AAFPermission>) invokeMethod(res, request, response);
1029 } catch (Exception e) {
1030 logger.error(EELFLoggerDelegate.errorLogger, "getSystemUserPerms failed", e);
1035 @ApiOperation(value = "Update role description in external auth system for an application.", response = PortalRestResponse.class, responseContainer = "Json")
1036 @RequestMapping(value = { "/v3/update/app/roleDescription" }, method = RequestMethod.PUT, produces = "application/json")
1037 public PortalRestResponse<String> updateAppRoleDescription(HttpServletRequest request, HttpServletResponse response) throws Exception {
1038 PortalRestResponse<String> result = null;
1039 Map<String, Object> res = getMethod(request, response);
1041 result = (PortalRestResponse<String>) invokeMethod(res, request, response);
1043 } catch (Exception e) {
1044 logger.error(EELFLoggerDelegate.errorLogger, "updateAppRoleDescription failed", e);
1045 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");