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