XSS Vulnerability fix in ExternalAccessRolesControllerDashboardController
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / controller / AuxApiRequestMapperController.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  */
37 package org.onap.portalapp.portal.controller;
38
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;
48 import java.util.Map;
49 import java.util.Optional;
50 import java.util.concurrent.atomic.AtomicReference;
51 import java.util.jar.Attributes;
52 import java.util.regex.Matcher;
53 import java.util.regex.Pattern;
54 import javax.servlet.http.HttpServletRequest;
55 import javax.servlet.http.HttpServletResponse;
56 import org.onap.aaf.cadi.aaf.AAFPermission;
57 import org.onap.portalapp.annotation.ApiVersion;
58 import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser;
59 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
60 import org.onap.portalapp.portal.domain.EPUser;
61 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
62 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
63 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
64 import org.onap.portalapp.portal.service.ManifestService;
65 import org.onap.portalapp.portal.transport.Analytics;
66 import org.onap.portalapp.portal.transport.CentralUser;
67 import org.onap.portalapp.portal.transport.CentralV2Role;
68 import org.onap.portalapp.portal.transport.EpNotificationItem;
69 import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
70 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
71 import org.onap.portalapp.portal.transport.OnboardingApp;
72 import org.onap.portalapp.validation.DataValidator;
73 import org.onap.portalapp.validation.SecureString;
74 import org.onap.portalsdk.core.domain.Role;
75 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
76 import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
77 import org.onap.portalsdk.core.restful.domain.EcompRole;
78 import org.onap.portalsdk.core.restful.domain.EcompUser;
79 import org.springframework.beans.BeansException;
80 import org.springframework.beans.factory.annotation.Autowired;
81 import org.springframework.context.ApplicationContext;
82 import org.springframework.context.ApplicationContextAware;
83 import org.springframework.context.annotation.Configuration;
84 import org.springframework.context.annotation.EnableAspectJAutoProxy;
85 import org.springframework.web.bind.annotation.PathVariable;
86 import org.springframework.web.bind.annotation.RequestBody;
87 import org.springframework.web.bind.annotation.RequestMapping;
88 import org.springframework.web.bind.annotation.RequestMethod;
89 import org.springframework.web.bind.annotation.RequestParam;
90 import org.springframework.web.bind.annotation.ResponseBody;
91 import org.springframework.web.bind.annotation.RestController;
92
93 @RestController
94 @RequestMapping("/auxapi")
95 @Configuration
96 @EnableAspectJAutoProxy
97 @EPAuditLog
98 public class AuxApiRequestMapperController implements ApplicationContextAware, BasicAuthenticationController {
99
100         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AuxApiRequestMapperController.class);
101         private DataValidator dataValidator = new DataValidator();
102
103         ApplicationContext context = null;
104         int minorVersion = 0;
105
106         @Autowired
107         private ManifestService manifestService;
108
109         @ApiOperation(value = "Gets user roles for an application which is upgraded to newer version.", response = String.class, responseContainer = "List")
110         @RequestMapping(value = { "/v3/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
111         public String getUser(HttpServletRequest request, HttpServletResponse response,
112                         @PathVariable("loginId") String loginId) throws Exception {
113                 if (loginId!=null){
114                         SecureString secureLoginId = new SecureString(loginId);
115                         if (!dataValidator.isValid(secureLoginId))
116                                 return "Provided data is not valid";
117                 }
118
119
120                 Map<String, Object> res = getMethod(request, response);
121                 String answer = null;
122                 try {
123                         answer = (String) invokeMethod(res, request, response, loginId);
124                 } catch (Exception e) {
125                         logger.error(EELFLoggerDelegate.errorLogger, "getUser failed", e);
126                 }
127                 return answer;
128         }
129
130         @SuppressWarnings("unchecked")
131         @ApiOperation(value = "Gets roles for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
132         @RequestMapping(value = { "/v3/roles" }, method = RequestMethod.GET, produces = "application/json")
133         public List<CentralV2Role> getRoles(HttpServletRequest request, HttpServletResponse response) throws Exception {
134                 Map<String, Object> res = getMethod(request, response);
135                 request.getMethod();
136                 List<CentralV2Role> answer = null;
137                 try {
138                         answer = (List<CentralV2Role>) invokeMethod(res, request, response);
139                 } catch (Exception e) {
140                         logger.error(EELFLoggerDelegate.errorLogger, "getRoles failed", e);
141                 }
142                 return answer;
143         }
144
145         @SuppressWarnings("unchecked")
146         @ApiOperation(value = "Saves role for an application.", response = PortalRestResponse.class, responseContainer = "Json")
147         @RequestMapping(value = { "/v3/role" }, method = RequestMethod.POST, produces = "application/json")
148         public PortalRestResponse<String> saveRole(HttpServletRequest request, HttpServletResponse response,
149                         @RequestBody Role role) throws Exception {
150                 Map<String, Object> res = getMethod(request, response);
151                 PortalRestResponse<String> out = null;
152                 try {
153                         out = (PortalRestResponse<String>) invokeMethod(res, request, response, role);
154                 } catch (Exception e) {
155                         logger.error(EELFLoggerDelegate.errorLogger, "saveRole failed", e);
156                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
157                 }
158                 return out;
159         }
160
161         @ApiOperation(value = "Gets v2 role information for an application which is upgraded to newer version.", response = CentralV2Role.class, responseContainer = "Json")
162         @RequestMapping(value = { "/v3/role/{role_id}" }, method = RequestMethod.GET, produces = "application/json")
163         public CentralV2Role getRoleInfo(HttpServletRequest request, HttpServletResponse response,
164                         @PathVariable("role_id") Long roleId) throws Exception {
165                 Map<String, Object> res = getMethod(request, response);
166                 CentralV2Role role = null;
167                 try {
168                         role = (CentralV2Role) invokeMethod(res, request, response, roleId);
169                 } catch (Exception e) {
170                         logger.error(EELFLoggerDelegate.errorLogger, "getRoleInfo failed", e);
171                 }
172                 return role;
173
174         }
175
176         @SuppressWarnings("unchecked")
177         @ApiOperation(value = "Gets all active Users of application", response = String.class, responseContainer = "Json")
178         @RequestMapping(value = { "/v3/users" }, method = RequestMethod.GET, produces = "application/json")
179         public List<EcompUser> getUsersOfApplication(HttpServletRequest request, HttpServletResponse response)
180                         throws Exception {
181                 Map<String, Object> res = getMethod(request, response);
182                 List<EcompUser> users = null;
183                 try {
184                         users = (List<EcompUser>) invokeMethod(res, request, response);
185                 } catch (Exception e) {
186                         logger.error(EELFLoggerDelegate.errorLogger, "getUsersOfApplication failed", e);
187                 }
188                 return users;
189         }
190
191         @SuppressWarnings("unchecked")
192         @ApiOperation(value = "Gets all role functions for an application which is upgraded to newer version.", response = CentralV2RoleFunction.class, responseContainer = "Json")
193         @RequestMapping(value = { "/v3/functions" }, method = RequestMethod.GET, produces = "application/json")
194         public List<CentralV2RoleFunction> getRoleFunctionsList(HttpServletRequest request, HttpServletResponse response)
195                         throws Exception {
196                 Map<String, Object> res = getMethod(request, response);
197                 List<CentralV2RoleFunction> roleFunctionsList = null;
198                 try {
199                         roleFunctionsList = (List<CentralV2RoleFunction>) invokeMethod(res, request, response);
200                 } catch (Exception e) {
201                         logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunctionsList failed", e);
202                 }
203                 return roleFunctionsList;
204         }
205
206         @ApiOperation(value = "Gets role information for an application provided by function code.", response = CentralV2RoleFunction.class, responseContainer = "Json")
207         @RequestMapping(value = { "/v3/function/{code}" }, method = RequestMethod.GET, produces = "application/json")
208         public CentralV2RoleFunction getRoleFunction(HttpServletRequest request, HttpServletResponse response,
209                         @PathVariable("code") String code) throws Exception {
210                 if (code!=null){
211                         SecureString secureCode = new SecureString(code);
212                         if (!dataValidator.isValid(secureCode))
213                                 return new CentralV2RoleFunction();
214                 }
215
216                 Map<String, Object> res = getMethod(request, response);
217                 CentralV2RoleFunction roleFunction = null;
218                 try {
219                         roleFunction = (CentralV2RoleFunction) invokeMethod(res, request, response, code);
220                 } catch (Exception e) {
221                         logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e);
222                 }
223                 return roleFunction;
224         }
225
226         @SuppressWarnings("unchecked")
227         @ApiOperation(value = "Saves role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
228         @RequestMapping(value = { "/v3/roleFunction" }, method = RequestMethod.POST, produces = "application/json")
229         public PortalRestResponse<String> saveRoleFunction(HttpServletRequest request, HttpServletResponse response,
230                         @RequestBody String roleFunc) throws Exception {
231                 if (roleFunc!=null){
232                         SecureString secureRoleFunc = new SecureString(roleFunc);
233                         if(!dataValidator.isValid(secureRoleFunc))
234                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
235                 }
236                 Optional<PortalRestResponse<String>> result = null;
237                 Map<String, Object> res = getMethod(request, response);
238                 try {
239                         result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
240                         if (!result.isPresent()){
241                                 logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", new Exception("saveRoleFunction failed"));
242                                 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "saveRoleFunction failed", "Failed");
243                         }
244                 } catch (Exception e) {
245                         logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction failed", e);
246                         return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
247                 }
248                 return result.get();
249         }
250
251         @SuppressWarnings("unchecked")
252         @ApiOperation(value = "Deletes role function for an application.", response = PortalRestResponse.class, responseContainer = "Json")
253         @RequestMapping(value = { "/v3/roleFunction/{code}" }, method = RequestMethod.DELETE, produces = "application/json")
254         public PortalRestResponse<String> deleteRoleFunction(HttpServletRequest request, HttpServletResponse response,
255                         @PathVariable("code") String code) throws Exception {
256                 PortalRestResponse<String> result = null;
257
258                 if (code!=null){
259                         SecureString secureCode = new SecureString(code);
260                         if(!dataValidator.isValid(secureCode))
261                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "Provided data is not valid", "Failed");
262                 }
263
264                 Map<String, Object> res = getMethod(request, response);
265                 try {
266                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, code);
267                         return result;
268                 } catch (Exception e) {
269                         logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction failed", e);
270                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
271                 }
272         }
273
274         @SuppressWarnings("unchecked")
275         @ApiOperation(value = "deletes  roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
276         @RequestMapping(value = { "/v3/deleteRole/{roleId}" }, method = RequestMethod.DELETE, produces = "application/json")
277         public PortalRestResponse<String> deleteRole(HttpServletRequest request, HttpServletResponse response,
278                         @PathVariable("roleId") Long roleId) throws Exception {
279                 PortalRestResponse<String> result = null;
280                 Map<String, Object> res = getMethod(request, response);
281                 try {
282                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, roleId);
283                         return result;
284                 } catch (Exception e) {
285                         logger.error(EELFLoggerDelegate.errorLogger, "deleteRole failed", e);
286                         return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
287                 }
288         }
289
290         @SuppressWarnings("unchecked")
291         @ApiOperation(value = "Gets active roles for an application.", response = CentralV2Role.class, responseContainer = "Json")
292         @RequestMapping(value = { "/v3/activeRoles" }, method = RequestMethod.GET, produces = "application/json")
293         public List<CentralV2Role> getActiveRoles(HttpServletRequest request, HttpServletResponse response)
294                         throws Exception {
295                 List<CentralV2Role> cenRole = null;
296                 Map<String, Object> res = getMethod(request, response);
297                 try {
298                         cenRole = (List<CentralV2Role>) invokeMethod(res, request, response);
299                 } catch (Exception e) {
300                         logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
301                 }
302                 return cenRole;
303         }
304
305         @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List")
306         @RequestMapping(value = { "/v4/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
307         public String getEcompUser(HttpServletRequest request, HttpServletResponse response,
308                         @PathVariable("loginId") String loginId) throws Exception {
309                 Map<String, Object> res = getMethod(request, response);
310
311                 if (loginId!=null){
312                         SecureString secureLoginId = new SecureString(loginId);
313
314                         if (!dataValidator.isValid(secureLoginId))
315                                 return null;
316                 }
317
318                 String answer = null;
319                 try {
320                         answer = (String) invokeMethod(res, request, response, loginId);
321                 } catch (Exception e) {
322                         logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e);
323                 }
324                 return answer;
325         }
326
327         @SuppressWarnings("unchecked")
328         @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List")
329         @RequestMapping(value = { "/v4/roles" }, method = RequestMethod.GET, produces = "application/json")
330         public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response)
331                         throws Exception {
332                 Map<String, Object> res = getMethod(request, response);
333                 List<EcompRole> answer = null;
334                 try {
335                         answer = (List<EcompRole>) invokeMethod(res, request, response);
336                 } catch (Exception e) {
337                         logger.error(EELFLoggerDelegate.errorLogger, "getEcompRolesOfApplication failed", e);
338                 }
339                 return answer;
340         }
341
342         @ApiOperation(value = "Gets session slot-check interval, a duration in milliseconds.", response = Integer.class)
343         @RequestMapping(value = {
344                         "/v3/getSessionSlotCheckInterval" }, method = RequestMethod.GET, produces = "application/json")
345         public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response)
346                         throws Exception {
347                 Map<String, Object> res = getMethod(request, response);
348                 Integer ans = null;
349                 try {
350                         ans = (Integer) invokeMethod(res, request, response);
351                 } catch (Exception e) {
352                         logger.error(EELFLoggerDelegate.errorLogger, "getSessionSlotCheckInterval failed", e);
353                 }
354                 return ans;
355         }
356
357         @ApiOperation(value = "Extends session timeout values for all on-boarded applications.", response = Boolean.class)
358         @RequestMapping(value = { "/v3/extendSessionTimeOuts" }, method = RequestMethod.POST)
359         public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response,
360                         @RequestParam String sessionMap) throws Exception {
361
362                 if (sessionMap!=null){
363                         SecureString secureSessionMap = new SecureString(sessionMap);
364                         if (!dataValidator.isValid(secureSessionMap)){
365                                 return null;
366                         }
367                 }
368
369                 Map<String, Object> res = getMethod(request, response);
370                 Boolean ans = null;
371                 try {
372                         ans = (Boolean) invokeMethod(res, request, response, sessionMap);
373                 } catch (Exception e) {
374                         logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts failed", e);
375                 }
376                 return ans;
377         }
378
379         @ApiOperation(value = "Gets javascript with functions that support gathering and reporting web analytics.", response = String.class)
380         @RequestMapping(value = { "/v3/analytics" }, method = RequestMethod.GET, produces = "application/javascript")
381         public String getAnalyticsScript(HttpServletRequest request, HttpServletResponse response) throws Exception {
382                 Map<String, Object> res = getMethod(request, response);
383                 String ans = null;
384                 try {
385                         ans = (String) invokeMethod(res, request, response);
386                 } catch (Exception e) {
387                         logger.error(EELFLoggerDelegate.errorLogger, "getAnalyticsScript failed", e);
388                 }
389                 return ans;
390         }
391
392         @RequestMapping(value = { "/v3/storeAnalytics" }, method = RequestMethod.POST, produces = "application/json")
393         @ResponseBody
394         @ApiOperation(value = "Accepts data from partner applications with web analytics data.", response = PortalAPIResponse.class)
395         public PortalAPIResponse storeAnalyticsScript(HttpServletRequest request, HttpServletResponse response,
396                         @RequestBody Analytics analyticsMap) throws Exception {
397
398                 if (analyticsMap!=null){
399                         if (!dataValidator.isValid(analyticsMap))
400                                 return new PortalAPIResponse(false, "analyticsScript is not valid");
401                 }
402
403                 Map<String, Object> res = getMethod(request, response);
404                 PortalAPIResponse ans = new PortalAPIResponse(true, "error");
405                 try {
406                         ans = (PortalAPIResponse) invokeMethod(res, request, response, analyticsMap);
407                 } catch (Exception e) {
408                         logger.error(EELFLoggerDelegate.errorLogger, "storeAnalyticsScript failed", e);
409                 }
410                 return ans;
411
412         }
413
414         @SuppressWarnings("unchecked")
415         @ApiOperation(value = "Bulk upload functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
416         @RequestMapping(value = {
417                         "/v3/upload/portal/functions" }, method = RequestMethod.POST, produces = "application/json")
418         public PortalRestResponse<String> bulkUploadFunctions(HttpServletRequest request, HttpServletResponse response)
419                         throws Exception {
420                 Optional<PortalRestResponse<String>> result = null;
421                 Map<String, Object> res = getMethod(request, response);
422                 try {
423                         result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
424                         if (!result.isPresent()){
425                                 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadFunctions", new Exception("Failed to bulkUploadFunctions"));
426                                 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadFunctions", "Failed");
427                         }
428                 } catch (Exception e) {
429                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e);
430                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
431                 }
432                 return result.get();
433         }
434
435         @SuppressWarnings("unchecked")
436         @ApiOperation(value = "Bulk upload roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
437         @RequestMapping(value = { "/v3/upload/portal/roles" }, method = RequestMethod.POST, produces = "application/json")
438         public PortalRestResponse<String> bulkUploadRoles(HttpServletRequest request, HttpServletResponse response)
439                         throws Exception {
440                 Optional<PortalRestResponse<String>> result;
441                 Map<String, Object> res = getMethod(request, response);
442                 try {
443                         result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
444                         if (!result.isPresent()){
445                                 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoles", new Exception("Failed to bulkUploadRoles"));
446                                 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoles", "Failed");
447                         }
448                         return result.get();
449                 } catch (Exception e) {
450                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoles failed", e);
451                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
452                 }
453         }
454
455         @SuppressWarnings("unchecked")
456         @ApiOperation(value = "Bulk upload role functions for an application.", response = PortalRestResponse.class, responseContainer = "Json")
457         @RequestMapping(value = {
458                         "/v3/upload/portal/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
459         public PortalRestResponse<String> bulkUploadRoleFunctions(HttpServletRequest request, HttpServletResponse response)
460                         throws Exception {
461                 Optional<PortalRestResponse<String>> result;
462                 Map<String, Object> res = getMethod(request, response);
463                 try {
464                         result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
465                         if (!result.isPresent()){
466                                 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoleFunctions", new Exception("Failed to bulkUploadRoleFunctions"));
467                                 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoleFunctions", "Failed");
468                         }
469                         return result.get();
470                 } catch (Exception e) {
471                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRoleFunctions failed", e);
472                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
473                 }
474         }
475
476         @SuppressWarnings("unchecked")
477         @ApiOperation(value = "Bulk upload user roles for an application.", response = PortalRestResponse.class, responseContainer = "Json")
478         @RequestMapping(value = {
479                         "/v3/upload/portal/userRoles" }, method = RequestMethod.POST, produces = "application/json")
480         public PortalRestResponse<String> bulkUploadUserRoles(HttpServletRequest request, HttpServletResponse response)
481                         throws Exception {
482                 Optional<PortalRestResponse<String>> result;
483                 Map<String, Object> res = getMethod(request, response);
484                 try {
485                         result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
486                         if (!result.isPresent()){
487                                 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadUserRoles", new Exception("Failed to bulkUploadUserRoles"));
488                                 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadUserRoles", "Failed");
489                         }
490                         return result.get();
491                 } catch (Exception e) {
492                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUserRoles failed", e);
493                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
494                 }
495
496         }
497
498         @SuppressWarnings("unchecked")
499         @ApiOperation(value = "Bulk upload users for renamed role of an application.", response = PortalRestResponse.class, responseContainer = "Json")
500         @RequestMapping(value = {
501                         "/v3/upload/portal/userRole/{roleId}" }, method = RequestMethod.POST, produces = "application/json")
502         public PortalRestResponse<String> bulkUploadUsersSingleRole(HttpServletRequest request,
503                         HttpServletResponse response, @PathVariable Long roleId) throws Exception {
504                 Optional<PortalRestResponse<String>> result = null;
505                 Map<String, Object> res = getMethod(request, response);
506                 try {
507                         result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
508                         if (!result.isPresent()){
509                                 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadUsersSingleRole", new Exception("Failed to bulkUploadUsersSingleRole"));
510                                 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadUsersSingleRole", "Failed");
511                         }
512                         return result.get();
513                 } catch (Exception e) {
514                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadUsersSingleRole failed", e);
515                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
516                 }
517         }
518
519         @SuppressWarnings("unchecked")
520         @ApiOperation(value = "Bulk upload functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
521         @RequestMapping(value = {
522                         "/v3/upload/partner/functions" }, method = RequestMethod.POST, produces = "application/json")
523         public PortalRestResponse<String> bulkUploadPartnerFunctions(HttpServletRequest request,
524                         HttpServletResponse response) throws Exception {
525                 Optional<PortalRestResponse<String>> result = null;
526                 Map<String, Object> res = getMethod(request, response);
527                 try {
528                         result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
529                         if (!result.isPresent()){
530                                 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadPartnerRoleFunctions", new Exception("Failed to bulkUploadPartnerRoleFunctions"));
531                                 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed");
532                         }
533                         return result.get();
534                 } catch (Exception e) {
535                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerFunctions failed", e);
536                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
537                 }
538         }
539
540         // not using
541         @SuppressWarnings("unchecked")
542         @ApiOperation(value = "Bulk upload roles for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
543         @RequestMapping(value = { "/v3/upload/partner/roles" }, method = RequestMethod.POST, produces = "application/json")
544         public PortalRestResponse<String> bulkUploadPartnerRoles(HttpServletRequest request, HttpServletResponse response,
545                         @RequestBody List<Role> upload) throws Exception {
546                 Optional<PortalRestResponse<String>> result = null;
547                 Map<String, Object> res = getMethod(request, response);
548                 try {
549                         result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
550                         if (!result.isPresent()){
551                                 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadRoles", new Exception("Failed to bulkUploadRoles"));
552                                 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadRoles", "Failed");
553                         }
554                         return result.get();
555                 } catch (Exception e) {
556                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoles failed", e);
557                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
558                 }
559         }
560
561         @SuppressWarnings("unchecked")
562         @ApiOperation(value = "Bulk upload role functions for an partner application.", response = PortalRestResponse.class, responseContainer = "Json")
563         @RequestMapping(value = {
564                         "/v3/upload/partner/roleFunctions" }, method = RequestMethod.POST, produces = "application/json")
565         public PortalRestResponse<String> bulkUploadPartnerRoleFunctions(HttpServletRequest request,
566                         HttpServletResponse response) throws Exception {
567                 Optional<PortalRestResponse<String>> result = null;
568                 Map<String, Object> res = getMethod(request, response);
569                 try {
570                         result = Optional.ofNullable((PortalRestResponse<String>) invokeMethod(res, request, response));
571                         if (!result.isPresent()){
572                                 logger.error(EELFLoggerDelegate.errorLogger, "Failed to bulkUploadPartnerRoleFunctions", new Exception("Failed to bulkUploadPartnerRoleFunctions"));
573                                 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "Failed to bulkUploadPartnerRoleFunctions", "Failed");
574                         }
575                         return result.get();
576                 } catch (Exception e) {
577                         logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadPartnerRoleFunctions failed", e);
578                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
579                 }
580         }
581
582         @SuppressWarnings("unchecked")
583         @ApiOperation(value = "Gets all functions along with global functions", response = List.class, responseContainer = "Json")
584         @RequestMapping(value = { "/v3/menuFunctions" }, method = RequestMethod.GET, produces = "application/json")
585         public List<String> getMenuFunctions(HttpServletRequest request, HttpServletResponse response) throws Exception {
586                 List<String> functionsList = null;
587                 Map<String, Object> res = getMethod(request, response);
588                 try {
589                         functionsList = (List<String>) invokeMethod(res, request, response);
590                 } catch (Exception e) {
591                         logger.error(EELFLoggerDelegate.errorLogger, "getMenuFunctions failed", e);
592                 }
593                 return functionsList;
594         }
595
596         private String getPatchNumber() {
597                 String response = "0";
598                 try {
599                         Attributes attributes = manifestService.getWebappManifest();
600                         response = attributes.getValue("Build-Number");
601                 } catch (Exception ex) {
602                         logger.error(EELFLoggerDelegate.errorLogger, "getPatchNumber failed", ex);
603                 }
604                 return response;
605         }
606
607         @SuppressWarnings("rawtypes")
608         private List<Object> getObject(HttpServletRequest request, HttpServletResponse response) {
609                 Map<String, Object> beans = context.getBeansWithAnnotation(ApiVersion.class);
610                 @SuppressWarnings("unchecked")
611                 List<Object> beansList = new ArrayList(beans.values());
612                 return beansList;
613
614         }
615
616         private Map<String, Object> getMethod(HttpServletRequest request, HttpServletResponse response) {
617                 Method finalmethod = null;
618                 String url = request.getRequestURI();
619                 String version = "";
620                 String service = "";
621                 Object currentObject = null;
622                 Map<String, Object> res = new HashMap<String, Object>();
623                 String[] uriArray = url.split("/auxapi");
624                 List<Integer> minorversionList = new ArrayList<>();
625                 if (uriArray.length > 1) {
626                         service = uriArray[1];
627                 }
628                 int first = service.indexOf("/");
629                 int second = service.indexOf("/", first + 1);
630                 version = service.substring(first + 1, second);
631                 int min = minorVersion;
632                 if (request.getHeader("MinorVersion") != null) {
633                         min = Integer.parseInt(request.getHeader("MinorVersion"));
634                 }
635                 res.put("min", version+"."+min);
636                 res.put("service", service);
637                 List<Object> objList = getObject(request, response);
638                 String requestedApiMethodType = request.getMethod();
639                 String majorVersion = latestMajorVersionOfService(objList, service, version, requestedApiMethodType);
640                 int latestMinorVersion = latestMinorVersionOfService(objList, service, version, requestedApiMethodType);
641                 res.put("majorVersion", majorVersion);
642                 res.put("latestMinorVersion", String.valueOf(latestMinorVersion));
643                 outerloop: for (Object obj : objList) {
644                         final List<Method> allMethods = getAllMethodsOfClass(obj);
645                         for (final Method method : allMethods) {
646                                 if (method.isAnnotationPresent(ApiVersion.class)) {
647                                         ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
648                                         Pattern p = Pattern.compile(annotInstance.service(),
649                                                         Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
650                                         Matcher matcher = p.matcher(service);
651                                         boolean b = matcher.matches();
652                                         logger.debug(EELFLoggerDelegate.debugLogger, "Requested Servie is:" + service
653                                                         + "Requested MinVersion is:" + min + "Requested MajorVersion is: " + version);
654                                         if (annotInstance.max().equals(version) && b && annotInstance.min() == min
655                                                         && annotInstance.method().equals(request.getMethod())) {
656                                                 finalmethod = method;
657                                                 currentObject = obj;
658                                                 res.put("method", method);
659                                                 res.put("Obj", obj);
660                                                 break outerloop;
661                                         }
662                                 }
663                         }
664                 }
665                 return res;
666         }
667
668         private String latestMajorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
669                         String requestedApiMethodType) {
670                 Integer majorVersion = 0;
671                 String serviceEndPoint = service;
672                 int firstindex = serviceEndPoint.indexOf("/");
673                 int secondindex = serviceEndPoint.indexOf("/", firstindex + 1);
674                 serviceEndPoint = serviceEndPoint.substring(secondindex + 1);
675
676                 List<Integer> latestMajorVersionList = new ArrayList<>();
677                 for (Object obj : objList) {
678                         final List<Method> allMethods = getAllMethodsOfClass(obj);
679                         for (final Method method : allMethods) {
680                                 if (method.isAnnotationPresent(ApiVersion.class)) {
681                                         ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
682                                         String endpoint = annotInstance.service();
683                                         int first = endpoint.indexOf("/");
684                                         int second = endpoint.indexOf("/", first + 1);
685                                         endpoint = endpoint.substring(second + 1);
686                                         Pattern p = Pattern.compile(endpoint,
687                                                         Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
688                                         Matcher matcher = p.matcher(serviceEndPoint);
689                                         boolean b = matcher.matches();
690                                         if (b && annotInstance.method().equals(requestedApiMethodType)) {
691                                                 int index1 = annotInstance.service().indexOf("/");
692                                                 int index2 = annotInstance.service().indexOf("/", index1 + 1);
693                                                 String majorversion = annotInstance.service().substring(index1 + 2, index2);
694                                                 latestMajorVersionList.add(Integer.parseInt(majorversion));
695                                         }
696                                 }
697                         }
698                 }
699                 majorVersion = Collections.max(latestMajorVersionList);
700                 String majorVersionWithLastestMin = "/v"+String.valueOf(majorVersion)+"/"+serviceEndPoint;
701                 int latestMinorVersion = latestMinorVersionOfService(objList, majorVersionWithLastestMin, "v"+String.valueOf(majorVersion), requestedApiMethodType);
702                 return majorVersion+"."+latestMinorVersion;
703         }
704
705         private List<Method> getAllMethodsOfClass(Object obj) {
706                 List<Method> allMethods = new ArrayList<>();
707                 Class<?> objClz = obj.getClass();
708                 if (org.springframework.aop.support.AopUtils.isAopProxy(obj)) {
709                         objClz = org.springframework.aop.support.AopUtils.getTargetClass(obj);
710                 }
711                 allMethods = new ArrayList<Method>(Arrays.asList(objClz.getMethods()));
712                 allMethods.removeIf(s -> !(s.isAnnotationPresent(ApiVersion.class)));
713                 return allMethods;
714         }
715
716         private Integer latestMinorVersionOfService(List<Object> objList, String service, String reuqestedVersion,
717                         String requestedApiMethodType) {
718                 Integer minVersion = 0;
719                 String serviceEndPoint = service;
720                 List<Integer> latestMinorVersionList = new ArrayList<>();
721                 for (Object obj : objList) {
722                         final List<Method> allMethods = getAllMethodsOfClass(obj);
723                         for (final Method method : allMethods) {
724                                 if (method.isAnnotationPresent(ApiVersion.class)) {
725                                         ApiVersion annotInstance = method.getAnnotation(ApiVersion.class);
726                                         String endpoint = annotInstance.service();
727
728                                         Pattern p = Pattern.compile(endpoint,
729                                                         Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
730                                         Matcher matcher = p.matcher(serviceEndPoint);
731                                         boolean b = matcher.matches();
732                                         if (annotInstance.max().equals(reuqestedVersion) && b
733                                                         && annotInstance.method().equals(requestedApiMethodType)) {
734                                                 int minorversion = annotInstance.min();
735                                                 latestMinorVersionList.add(minorversion);
736                                         }
737                                 }
738                         }
739                 }
740                 minVersion = Collections.max(latestMinorVersionList);
741                 return minVersion;
742         }
743
744         private HttpServletResponse setResponse(HttpServletResponse response, String requestedMinVersion,
745                         String majorVersion, String latestMinorVersion, String service) {
746                 response.setHeader("X-MinorVersion", requestedMinVersion.toUpperCase());
747                 response.setHeader("X-PatchVersion", getPatchNumber());
748                 response.setHeader("X-LatestVersion", "V"+majorVersion);
749                 return response;
750         }
751
752         /**
753          * 
754          * @param res
755          * @param args
756          *            method parameters(Maintain HttpServletRequest at 0th position
757          *            and HttpServletResponse at 1th position in args array)
758          * @return
759          * @throws Exception
760          */
761         private Object invokeMethod(Map<String, Object> res, Object... args) throws Exception {
762                 Method method = (Method) res.get("method");
763                 Object obj = res.get("Obj");
764                 Object responseObj = null;
765                 String min = res.get("min").toString();
766                 String majorVersion = res.get("majorVersion").toString();
767                 String latestMinorVersion = res.get("latestMinorVersion").toString();
768                 String service = res.get("service").toString();
769                 HttpServletRequest request = (HttpServletRequest) args[0];
770                 HttpServletResponse response = (HttpServletResponse) args[1];
771                 setResponse(response, min, majorVersion, latestMinorVersion, service);
772                 final Map<String, String> errorMap = new HashMap<>();
773                 ObjectMapper mapper = new ObjectMapper();
774                 String reason = "";
775                 try {
776                         if (method != null && obj != null) {
777                                 responseObj = method.invoke(obj, args);
778                         } else {
779                                 errorMap.put("error", "Requested api is not available");
780                                 reason = mapper.writeValueAsString(errorMap);
781                                 response.getWriter().write(reason);
782                                 logger.debug(EELFLoggerDelegate.debugLogger, "Requested api " + request.getRequestURI()
783                                                 + "is not available with minorVersion " + request.getHeader("MinorVersion"));
784                                 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
785                         }
786                 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
787                         logger.error(EELFLoggerDelegate.errorLogger, "Method :" + method + "invocation failed", e);
788                 }
789                 return responseObj;
790         }
791
792         @Override
793         public void setApplicationContext(ApplicationContext context) throws BeansException {
794                 this.context = context;
795         }
796
797         @SuppressWarnings("unchecked")
798         @ApiOperation(value = "Creates an application user with the specified roles.", response = PortalRestResponse.class)
799         @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.POST, produces = "application/json")
800         public PortalRestResponse<String> postUserProfile(HttpServletRequest request,
801                         @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
802
803                 if (extSysUser!=null){
804                         if (!dataValidator.isValid(extSysUser))
805                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
806                 }
807
808                 PortalRestResponse<String> result = null;
809                 Map<String, Object> res = getMethod(request, response);
810                 try {
811                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
812                         return result;
813                 } catch (Exception e) {
814                         logger.error(EELFLoggerDelegate.errorLogger, "postUserProfile failed", e);
815                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
816                 }
817         }
818
819         @SuppressWarnings("unchecked")
820         @ApiOperation(value = "Updates an application user to have only the specified roles.", response = PortalRestResponse.class)
821         @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.PUT, produces = "application/json")
822         public PortalRestResponse<String> putUserProfile(HttpServletRequest request,
823                         @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
824
825                 if (extSysUser!=null){
826                         if (!dataValidator.isValid(extSysUser))
827                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
828                 }
829
830                 PortalRestResponse<String> result = null;
831                 Map<String, Object> res = getMethod(request, response);
832                 try {
833                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
834                         return result;
835                 } catch (Exception e) {
836                         logger.error(EELFLoggerDelegate.errorLogger, "putUserProfile failed", e);
837                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
838                 }
839         }
840
841         @SuppressWarnings("unchecked")
842         @ApiOperation(value = "Processes a request to delete one or more application roles for one      specified user who has roles.", response = PortalRestResponse.class)
843         @RequestMapping(value = { "/v3/userProfile" }, method = RequestMethod.DELETE, produces = "application/json")
844         public PortalRestResponse<String> deleteUserProfile(HttpServletRequest request,
845                         @RequestBody ExternalSystemUser extSysUser, HttpServletResponse response) {
846
847                 if (extSysUser!=null){
848                         if (!dataValidator.isValid(extSysUser))
849                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ExternalSystemUser is not valid", "Failed");
850                 }
851
852                 PortalRestResponse<String> result = null;
853                 Map<String, Object> res = getMethod(request, response);
854                 try {
855                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, extSysUser);
856                         return result;
857                 } catch (Exception e) {
858                         logger.error(EELFLoggerDelegate.errorLogger, "deleteUserProfile failed", e);
859                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
860                 }
861         }
862
863         @SuppressWarnings("unchecked")
864         @ApiOperation(value = "Accepts messages from external ticketing systems and creates notifications for Portal users.", response = PortalRestResponse.class)
865         @RequestMapping(value = { "/v3/ticketevent" }, method = RequestMethod.POST)
866         public PortalRestResponse<String> handleRequest(HttpServletRequest request, HttpServletResponse response,
867                         @RequestBody String ticketEventJson) throws Exception {
868
869                 if (ticketEventJson!=null){
870                         SecureString secureTicketEventJson = new SecureString(ticketEventJson);
871                         if (!dataValidator.isValid(secureTicketEventJson))
872                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "ticketEventJson is not valid", "Failed");
873                 }
874
875                 PortalRestResponse<String> result = null;
876                 Map<String, Object> res = getMethod(request, response);
877                 try {
878                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, ticketEventJson);
879                         return result;
880                 } catch (Exception e) {
881                         logger.error(EELFLoggerDelegate.errorLogger, "handleRequest failed", e);
882                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
883                 }
884         }
885
886         @SuppressWarnings("unchecked")
887         @ApiOperation(value = "Creates a new user as a Portal administrator.", response = PortalRestResponse.class)
888         @RequestMapping(value = "/v3/portalAdmin", method = RequestMethod.POST, produces = "application/json")
889         @ResponseBody
890         public PortalRestResponse<String> postPortalAdmin(HttpServletRequest request, HttpServletResponse response,
891                         @RequestBody EPUser epUser) {
892
893                 if (epUser!=null){
894                         if (!dataValidator.isValid(epUser))
895                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "EPUser is not valid", "Failed");
896                 }
897
898                 PortalRestResponse<String> result = null;
899                 Map<String, Object> res = getMethod(request, response);
900                 try {
901                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, epUser);
902                         return result;
903                 } catch (Exception e) {
904                         logger.error(EELFLoggerDelegate.errorLogger, "postPortalAdmin failed", e);
905                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
906                 }
907         }
908
909         @ApiOperation(value = "Gets the specified application that is on-boarded in Portal.", response = OnboardingApp.class)
910         @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.GET, produces = "application/json")
911         @ResponseBody
912         public OnboardingApp getOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
913                         @PathVariable("appId") Long appId) {
914                 OnboardingApp result = new OnboardingApp();
915                 Map<String, Object> res = getMethod(request, response);
916                 try {
917                         result = (OnboardingApp) invokeMethod(res, request, response, appId);
918                 } catch (Exception e) {
919                         logger.error(EELFLoggerDelegate.errorLogger, "getOnboardAppExternal failed", e);
920                 }
921                 return result;
922         }
923
924         @SuppressWarnings("unchecked")
925         @ApiOperation(value = "Adds a new application to Portal.", response = PortalRestResponse.class)
926         @RequestMapping(value = { "/v3/onboardApp" }, method = RequestMethod.POST, produces = "application/json")
927         @ResponseBody
928         public PortalRestResponse<String> postOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
929                         @RequestBody OnboardingApp newOnboardApp) {
930
931                 if (newOnboardApp!=null){
932                         if (!dataValidator.isValid(newOnboardApp))
933                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
934                 }
935
936                 PortalRestResponse<String> result = new PortalRestResponse<>();
937                 Map<String, Object> res = getMethod(request, response);
938                 try {
939                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, newOnboardApp);
940                         return result;
941                 } catch (Exception e) {
942                         logger.error(EELFLoggerDelegate.errorLogger, "postOnboardAppExternal failed", e);
943                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
944                 }
945
946         }
947
948         @SuppressWarnings("unchecked")
949         @ApiOperation(value = "Updates information about an on-boarded application in Portal.", response = PortalRestResponse.class)
950         @RequestMapping(value = { "/v3/onboardApp/{appId}" }, method = RequestMethod.PUT, produces = "application/json")
951         @ResponseBody
952         public PortalRestResponse<String> putOnboardAppExternal(HttpServletRequest request, HttpServletResponse response,
953                         @PathVariable("appId") Long appId, @RequestBody OnboardingApp oldOnboardApp) {
954
955                 if (oldOnboardApp!=null){
956                         if (!dataValidator.isValid(oldOnboardApp))
957                                 return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "OnboardingApp is not valid", "Failed");
958                 }
959
960                 PortalRestResponse<String> result;
961                 Map<String, Object> res = getMethod(request, response);
962                 try {
963                         result = (PortalRestResponse<String>) invokeMethod(res, request, response, appId, oldOnboardApp);
964                         return result;
965                 } catch (Exception e) {
966                         logger.error(EELFLoggerDelegate.errorLogger, "putOnboardAppExternal failed", e);
967                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
968                 }
969         }
970
971         @ApiOperation(value = "Creates a Portal user notification for roles identified in the content from an external application.", response = PortalAPIResponse.class)
972         @RequestMapping(value = { "/v3/publishNotification" }, method = RequestMethod.POST, produces = "application/json")
973         @ResponseBody
974         public PortalAPIResponse publishNotification(HttpServletRequest request,
975                         @RequestBody EpNotificationItem notificationItem, HttpServletResponse response) {
976
977                 if (notificationItem!=null){
978                         if (!dataValidator.isValid(notificationItem))
979                                 return new PortalAPIResponse(false, "EpNotificationItem is not valid");
980                 }
981
982                 Map<String, Object> res = getMethod(request, response);
983                 try {
984                         return (PortalAPIResponse) invokeMethod(res, request, response, notificationItem);
985                 } catch (Exception e) {
986                         logger.error(EELFLoggerDelegate.errorLogger, "publishNotification failed", e);
987                         return new PortalAPIResponse(false, e.getMessage());
988                 }
989         }
990
991         @SuppressWarnings("unchecked")
992         @ApiOperation(value = "Gets favorite items within the functional menu for the current user.", response = FavoritesFunctionalMenuItemJson.class, responseContainer = "List")
993         @RequestMapping(value = { "/v3/getFavorites" }, method = RequestMethod.GET, produces = "application/json")
994         public List<FavoritesFunctionalMenuItemJson> getFavoritesForUser(HttpServletRequest request,
995                         HttpServletResponse response) throws Exception {
996                 List<FavoritesFunctionalMenuItemJson> favorites = null;
997                 Map<String, Object> res = getMethod(request, response);
998                 try {
999                         favorites = (List<FavoritesFunctionalMenuItemJson>) invokeMethod(res, request, response);
1000                 } catch (Exception e) {
1001                         logger.error(EELFLoggerDelegate.errorLogger, "getFavoritesForUser failed", e);
1002                 }
1003                 return favorites;
1004         }
1005
1006         @SuppressWarnings("unchecked")
1007         @ApiOperation(value = "Gets functional menu items appropriate for the current user.", response = FunctionalMenuItem.class, responseContainer = "List")
1008         @RequestMapping(value = {
1009                         "/v3/functionalMenuItemsForUser" }, method = RequestMethod.GET, produces = "application/json")
1010         public List<FunctionalMenuItem> getFunctionalMenuItemsForUser(HttpServletRequest request,
1011                         HttpServletResponse response) throws Exception {
1012                 List<FunctionalMenuItem> fnMenuItems = null;
1013                 Map<String, Object> res = getMethod(request, response);
1014                 try {
1015                         fnMenuItems = (List<FunctionalMenuItem>) invokeMethod(res, request, response);
1016                 } catch (Exception e) {
1017                         logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenuItemsForUser failed", e);
1018                 }
1019                 return fnMenuItems;
1020         }
1021
1022         
1023         @ApiOperation(value = "Gets MechId roles", response = String.class, responseContainer = "List")
1024         @RequestMapping(value = { "/v3/systemUser" }, method = RequestMethod.GET, produces = "application/json")
1025         public List<AAFPermission> getSystemUserPerms(HttpServletRequest request, HttpServletResponse response) throws Exception {
1026                 List<AAFPermission> permsList = null;
1027                 Map<String, Object> res = getMethod(request, response);
1028                 try {
1029                         permsList = (List<AAFPermission>) invokeMethod(res, request, response);
1030                 } catch (Exception e) {
1031                         logger.error(EELFLoggerDelegate.errorLogger, "getSystemUserPerms failed", e);
1032                 }
1033                 return permsList;
1034         }
1035         
1036         @ApiOperation(value = "Update role description in external auth system for an application.", response = PortalRestResponse.class, responseContainer = "Json")
1037         @RequestMapping(value = { "/v3/update/app/roleDescription" }, method = RequestMethod.PUT, produces = "application/json")
1038         public  PortalRestResponse<String> updateAppRoleDescription(HttpServletRequest request, HttpServletResponse response) throws Exception {
1039                 PortalRestResponse<String> result = null;
1040                 Map<String, Object> res = getMethod(request, response);
1041                 try {
1042                         result = (PortalRestResponse<String>) invokeMethod(res, request, response);
1043                         return result;
1044                 } catch (Exception e) {
1045                         logger.error(EELFLoggerDelegate.errorLogger, "updateAppRoleDescription failed", e);
1046                         return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, e.getMessage(), "Failed");
1047                 }
1048         }
1049 }