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