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