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