Remove unused files with company keywords
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / controller / UserRolesController.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 package org.openecomp.portalapp.portal.controller;
21
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.Comparator;
26 import java.util.List;
27
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30
31 import org.apache.cxf.transport.http.HTTPException;
32 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
33 import org.openecomp.portalapp.portal.domain.EPRole;
34 import org.openecomp.portalapp.portal.domain.EPUser;
35 import org.openecomp.portalapp.portal.domain.EPUserAppCatalogRoles;
36 import org.openecomp.portalapp.portal.domain.EcompAuditLog;
37 import org.openecomp.portalapp.portal.domain.ExternalSystemAccess;
38 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
39 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
40 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
41 import org.openecomp.portalapp.portal.logging.aop.EPEELFLoggerAdvice;
42 import org.openecomp.portalapp.portal.logging.logic.EPLogUtil;
43 import org.openecomp.portalapp.portal.service.AdminRolesService;
44 import org.openecomp.portalapp.portal.service.ApplicationsRestClientService;
45 import org.openecomp.portalapp.portal.service.SearchService;
46 import org.openecomp.portalapp.portal.service.UserRolesService;
47 import org.openecomp.portalapp.portal.transport.AppNameIdIsAdmin;
48 import org.openecomp.portalapp.portal.transport.AppWithRolesForUser;
49 import org.openecomp.portalapp.portal.transport.AppsListWithAdminRole;
50 import org.openecomp.portalapp.portal.transport.FieldsValidator;
51 import org.openecomp.portalapp.portal.transport.RoleInAppForUser;
52 import org.openecomp.portalapp.portal.transport.UserApplicationRoles;
53 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
54 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
55 import org.openecomp.portalapp.portal.utils.PortalConstants;
56 import org.openecomp.portalapp.util.EPUserUtils;
57 import org.openecomp.portalsdk.core.domain.AuditLog;
58 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
59 import org.openecomp.portalsdk.core.restful.domain.EcompRole;
60 import org.openecomp.portalsdk.core.service.AuditService;
61 import org.openecomp.portalsdk.core.util.SystemProperties;
62 import org.slf4j.MDC;
63 import org.springframework.beans.factory.annotation.Autowired;
64 import org.springframework.context.annotation.EnableAspectJAutoProxy;
65 import org.springframework.web.bind.annotation.PathVariable;
66 import org.springframework.web.bind.annotation.RequestBody;
67 import org.springframework.web.bind.annotation.RequestMapping;
68 import org.springframework.web.bind.annotation.RequestMethod;
69 import org.springframework.web.bind.annotation.RequestParam;
70 import org.springframework.web.bind.annotation.RestController;
71
72 @RestController
73 @org.springframework.context.annotation.Configuration
74 @EnableAspectJAutoProxy
75 @EPAuditLog
76 public class UserRolesController extends EPRestrictedBaseController {
77
78         private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserRolesController.class);
79
80         @Autowired
81         private SearchService searchService;
82         @Autowired
83         private AdminRolesService adminRolesService;
84         private @Autowired UserRolesService userRolesService;
85         @Autowired
86         private ApplicationsRestClientService applicationsRestClientService;
87         @Autowired
88         private AuditService auditService;
89
90         private static final String FAILURE = "failure";
91
92         /**
93          * RESTful service method to fetch users in the WebPhone external service
94          * 
95          * @param request
96          *            HttpServletRequest
97          * @param searchString
98          *            search string
99          * @param response
100          *            HttpServletResponse
101          * @return array of found users as json
102          */
103         @RequestMapping(value = { "/portalApi/queryUsers" }, method = RequestMethod.GET, produces = "application/json")
104         public String getPhoneBookSearchResult(HttpServletRequest request, @RequestParam("search") String searchString,
105                         HttpServletResponse response) {
106                 EPUser user = EPUserUtils.getUserSession(request);
107                 String searchResult = null;
108                 if (!adminRolesService.isSuperAdmin(user) && !adminRolesService.isAccountAdmin(user)) {
109                         EcompPortalUtils.setBadPermissions(user, response, "getPhoneBookSearchResult");
110                 } else {
111                         searchString = searchString.trim();
112                         if (searchString.length() > 2) {
113                                 searchResult = searchService.searchUsersInPhoneBook(searchString);
114                         } else {
115                                 logger.info(EELFLoggerDelegate.errorLogger,
116                                                 "getPhoneBookSearchResult - too short search string: " + searchString);
117                         }
118                 }
119                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/queryUsers", "result =", searchResult);
120
121                 return searchResult;
122         }
123
124         /**
125          * RESTful service method to fetch applications where user is admin
126          * 
127          * @param request
128          *            HttpServletRequest
129          * @param orgUserId
130          *            search string
131          * @param response
132          *            HttpServletResponse
133          * @return for GET: array of all applications with boolean
134          *         isAdmin=true/false for each application
135          */
136         @RequestMapping(value = { "/portalApi/adminAppsRoles" }, method = {
137                         RequestMethod.GET }, produces = "application/json")
138         public AppsListWithAdminRole getAppsWithAdminRoleStateForUser(HttpServletRequest request,
139                         @RequestParam("user") String orgUserId, HttpServletResponse response) {
140
141                 EPUser user = EPUserUtils.getUserSession(request);
142                 AppsListWithAdminRole result = null;
143                 if (!adminRolesService.isSuperAdmin(user)) {
144                         EcompPortalUtils.setBadPermissions(user, response, "getAppsWithAdminRoleStateForUser");
145                 } else {
146                         if (EcompPortalUtils.legitimateUserId(orgUserId)) {
147                                 result = adminRolesService.getAppsWithAdminRoleStateForUser(orgUserId);
148                         } else {
149                                 logger.info(EELFLoggerDelegate.errorLogger,
150                                                 "getAppsWithAdminRoleStateForUser - parms error, no Organization User ID");
151                                 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
152                         }
153                 }
154
155                 StringBuilder adminAppRoles = new StringBuilder();
156                 if (result != null && result.appsRoles.size() >= 1) {
157                         adminAppRoles.append("User '" + result.orgUserId + "' has admin role to the apps = {");
158                         for (AppNameIdIsAdmin adminAppRole : result.appsRoles) {
159                                 if (adminAppRole.isAdmin) {
160                                         adminAppRoles.append(adminAppRole.appName + ", ");
161                                 }
162                         }
163                         adminAppRoles.append("}.");
164                 } else {
165                         adminAppRoles.append("User '" + result.orgUserId + "' has no Apps with Admin Role.");
166                 }
167                 logger.info(EELFLoggerDelegate.errorLogger, adminAppRoles.toString());
168
169                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/adminAppsRoles", "get result =", result);
170
171                 return result;
172         }
173
174         /**
175          * 
176          * @param request
177          *            HttpServletRequest
178          * @param newAppsListWithAdminRoles
179          *            new apps
180          * @param response
181          *            HttpServletResponse
182          * @return FieldsValidator
183          */
184         @RequestMapping(value = { "/portalApi/adminAppsRoles" }, method = {
185                         RequestMethod.PUT }, produces = "application/json")
186         public FieldsValidator putAppsWithAdminRoleStateForUser(HttpServletRequest request,
187                         @RequestBody AppsListWithAdminRole newAppsListWithAdminRoles, HttpServletResponse response) {
188
189                 // newAppsListWithAdminRoles.appsRoles
190                 FieldsValidator fieldsValidator = new FieldsValidator();
191                 StringBuilder newAppRoles = new StringBuilder();
192                 if (newAppsListWithAdminRoles != null && newAppsListWithAdminRoles.appsRoles.size() >= 1) {
193                         newAppRoles.append("User '" + newAppsListWithAdminRoles.orgUserId + "' has admin role to the apps = { ");
194                         for (AppNameIdIsAdmin adminAppRole : newAppsListWithAdminRoles.appsRoles) {
195                                 if (adminAppRole.isAdmin) {
196                                         newAppRoles.append(adminAppRole.appName + " ,");
197                                 }
198                         }
199                         newAppRoles.deleteCharAt(newAppRoles.length() - 1);
200                         newAppRoles.append("}.");
201                 } else {
202                         newAppRoles.append("User '" + newAppsListWithAdminRoles.orgUserId + "' has no Apps with Admin Role.");
203                 }
204                 logger.info(EELFLoggerDelegate.errorLogger, newAppRoles.toString());
205
206                 EPUser user = EPUserUtils.getUserSession(request);
207                 boolean changesApplied = false;
208
209                 if (!adminRolesService.isSuperAdmin(user)) {
210                         EcompPortalUtils.setBadPermissions(user, response, "putAppsWithAdminRoleStateForUser");
211                 } else {
212                         changesApplied = adminRolesService.setAppsWithAdminRoleStateForUser(newAppsListWithAdminRoles);
213                         AuditLog auditLog = new AuditLog();
214                         auditLog.setUserId(user.getId());
215                         auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN);
216                         auditLog.setAffectedRecordId(newAppsListWithAdminRoles.orgUserId);
217                         auditLog.setComments(EcompPortalUtils.truncateString(newAppRoles.toString(), PortalConstants.AUDIT_LOG_COMMENT_SIZE));
218                         auditService.logActivity(auditLog, null);
219
220                         MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
221                         MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
222                         EcompPortalUtils.calculateDateTimeDifferenceForLog(
223                                         MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
224                                         MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
225                         logger.info(EELFLoggerDelegate.auditLogger,
226                                         EPLogUtil.formatAuditLogMessage("UserRolesController.putAppsWithAdminRoleStateForUser",
227                                                         EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN, user.getOrgUserId(),
228                                                         newAppsListWithAdminRoles.orgUserId, newAppRoles.toString()));
229                         MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
230                         MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
231                         MDC.remove(SystemProperties.MDC_TIMER);
232                 }
233                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/adminAppsRoles", "put result =", changesApplied);
234
235                 return fieldsValidator;
236         }
237
238         /**
239          * It returns a list of user app roles for single app
240          * 
241          * @param request
242          *            HttpServletRequest
243          * @param response
244          *            HttpServletResponse
245          * @param orgUserId
246          *            user ID
247          * @param appid
248          *            application ID
249          * @param extRequestValue
250          *            set to false if request is from users page otherwise true
251          * @return List<RoleInAppForUser>
252          */
253         @RequestMapping(value = { "/portalApi/userAppRoles" }, method = {
254                         RequestMethod.GET }, produces = "application/json")
255         public List<RoleInAppForUser> getAppRolesForUser(HttpServletRequest request, @RequestParam("user") String orgUserId,
256                         @RequestParam("app") Long appid, @RequestParam("externalRequest") Boolean extRequestValue,
257                         HttpServletResponse response) {
258                 EPUser user = EPUserUtils.getUserSession(request);
259                 List<RoleInAppForUser> result = null;
260                 String feErrorString = "";
261                 if (!adminRolesService.isAccountAdmin(user)) {
262                         EcompPortalUtils.setBadPermissions(user, response, "getAppRolesForUser");
263                         feErrorString = EcompPortalUtils.getFEErrorString(true, response.getStatus());
264                 } else {
265                         if (EcompPortalUtils.legitimateUserId(orgUserId)) {
266                                 result = userRolesService.getAppRolesForUser(appid, orgUserId, extRequestValue);
267                                 int responseCode = EcompPortalUtils.getExternalAppResponseCode();
268                                 if (responseCode != 0 && responseCode != 200) {
269                                         // external error
270                                         response.setStatus(responseCode);
271                                         feErrorString = EcompPortalUtils.getFEErrorString(false, responseCode);
272                                 } else if (result == null) {
273                                         // If the result is null, there was an internal ecomp error
274                                         // in the service call.
275                                         response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
276                                         feErrorString = EcompPortalUtils.getFEErrorString(true,
277                                                         HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
278                                 }
279                         } else {
280                                 logger.info(EELFLoggerDelegate.errorLogger, "getAppRolesForUser - no Organization User ID");
281                                 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
282                                 feErrorString = EcompPortalUtils.getFEErrorString(true, HttpServletResponse.SC_BAD_REQUEST);
283                         }
284                 }
285
286                 StringBuilder sbUserApps = new StringBuilder();
287                 if (result != null && result.size() >= 1) {
288                         sbUserApps.append("User '" + orgUserId + "' has Roles={");
289                         for (RoleInAppForUser appRole : result) {
290                                 if (appRole.isApplied) {
291                                         sbUserApps.append(appRole.roleName + ", ");
292                                 }
293                         }
294                         sbUserApps.append("} assigned to the appId '" + appid + "'.");
295                 } else {
296                         // Not sure creating an empty object will make any difference
297                         // but would like to give it a shot for defect #DE221057
298                         if (result == null) {
299                                 result = new ArrayList<RoleInAppForUser>();
300                         }
301                         sbUserApps.append("User '" + orgUserId + "' and appid " + appid + " has no roles");
302                 }
303                 logger.info(EELFLoggerDelegate.errorLogger, sbUserApps.toString());
304
305                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppRoles", "get result =", result);
306                 if (feErrorString != "") {
307                         logger.debug(EELFLoggerDelegate.debugLogger, "LR: FEErrorString to header: " + feErrorString);
308
309                         response.addHeader("FEErrorString", feErrorString);
310                         response.addHeader("Access-Control-Expose-Headers", "FEErrorString");
311                 }
312                 return result;
313         }
314
315         @RequestMapping(value = { "/portalApi/userAppRoles" }, method = {
316                         RequestMethod.PUT }, produces = "application/json")
317         public FieldsValidator putAppWithUserRoleStateForUser(HttpServletRequest request,
318                         @RequestBody AppWithRolesForUser newAppRolesForUser, HttpServletResponse response) {
319                 FieldsValidator fieldsValidator = new FieldsValidator();
320                 StringBuilder sbUserApps = new StringBuilder();
321                 if (newAppRolesForUser != null) {
322                         sbUserApps.append("User '" + newAppRolesForUser.orgUserId);
323                         if (newAppRolesForUser.appRoles != null && newAppRolesForUser.appRoles.size() >= 1) {
324                                 sbUserApps.append("' has roles = { ");
325                                 for (RoleInAppForUser appRole : newAppRolesForUser.appRoles) {
326                                         if (appRole.isApplied) {
327                                                 sbUserApps.append(appRole.roleName + " ,");
328                                         }
329                                 }
330                                 sbUserApps.deleteCharAt(sbUserApps.length() - 1);
331                                 sbUserApps.append("} assigned for the app " + newAppRolesForUser.appId);
332                         } else {
333                                 sbUserApps.append("' has no roles assigned for app " + newAppRolesForUser.appId);
334                         }
335                 }
336                 logger.info(EELFLoggerDelegate.applicationLogger, "putAppWithUserRoleStateForUser: {}", sbUserApps.toString());
337
338                 EPUser user = EPUserUtils.getUserSession(request);
339                 boolean changesApplied = false;
340                 if (!adminRolesService.isAccountAdmin(user)) {
341                         EcompPortalUtils.setBadPermissions(user, response, "putAppWithUserRoleStateForUser");
342                 } else {
343                         changesApplied = userRolesService.setAppWithUserRoleStateForUser(user, newAppRolesForUser);
344                         if (changesApplied) {
345                                 logger.info(EELFLoggerDelegate.applicationLogger,
346                                                 "putAppWithUserRoleStateForUser: succeeded for app {}, user {}", newAppRolesForUser.appId,
347                                                 newAppRolesForUser.orgUserId);
348
349                                 MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
350                                 AuditLog auditLog = new AuditLog();
351                                 auditLog.setUserId(user.getId());
352                                 auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_UPDATE_USER);
353                                 auditLog.setAffectedRecordId(newAppRolesForUser.orgUserId);
354                                 auditLog.setComments(EcompPortalUtils.truncateString(sbUserApps.toString(), PortalConstants.AUDIT_LOG_COMMENT_SIZE));
355                                 auditService.logActivity(auditLog, null);
356                                 
357                                 MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
358                                 EcompPortalUtils.calculateDateTimeDifferenceForLog(
359                                                 MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
360                                                 MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
361                                 logger.info(EELFLoggerDelegate.auditLogger,
362                                                 EPLogUtil.formatAuditLogMessage("UserRolesController.putAppWithUserRoleStateForUser",
363                                                                 EcompAuditLog.CD_ACTIVITY_UPDATE_USER, user.getOrgUserId(),
364                                                                 newAppRolesForUser.orgUserId, sbUserApps.toString()));
365                                 MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
366                                 MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
367                                 MDC.remove(SystemProperties.MDC_TIMER);
368                         } else {
369                                 logger.error(EELFLoggerDelegate.errorLogger,
370                                                 "putAppWithUserRoleStateForUser: failed for app {}, user {}", newAppRolesForUser.appId,
371                                                 newAppRolesForUser.orgUserId);
372                         }
373                 }
374
375                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userAppRoles", "put result =", changesApplied);
376                 return fieldsValidator;
377         }
378
379         @RequestMapping(value = { "/portalApi/updateRemoteUserProfile" }, method = {
380                         RequestMethod.GET }, produces = "application/json")
381         public PortalRestResponse<String> updateRemoteUserProfile(HttpServletRequest request,
382                         HttpServletResponse response) {
383
384                 String updateRemoteUserFlag = FAILURE;
385                 try {
386                         // saveNewUser = userService.saveNewUser(newUser);
387                         String orgUserId = request.getParameter("loginId");
388                         Long appId = Long.parseLong(request.getParameter("appId"));
389                         userRolesService.updateRemoteUserProfile(orgUserId, appId);
390
391                 } catch (Exception e) {
392                         return new PortalRestResponse<String>(PortalRestStatusEnum.OK, updateRemoteUserFlag, e.getMessage());
393                 }
394                 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, updateRemoteUserFlag, "");
395
396         }
397
398         @RequestMapping(value = { "/portalApi/app/{appId}/users" }, method = {
399                         RequestMethod.GET }, produces = "application/json")
400         public List<UserApplicationRoles> getUsersFromAppEndpoint(HttpServletRequest request,
401                         @PathVariable("appId") Long appId) throws HTTPException {
402                 try {
403                         logger.debug(EELFLoggerDelegate.debugLogger, "/portalApi/app/{}/users was invoked", appId);
404                         List<UserApplicationRoles> appUsers = userRolesService.getUsersFromAppEndpoint(appId);
405                         return appUsers;
406                 } catch (Exception e) {
407                         logger.error(EELFLoggerDelegate.errorLogger,
408                                         "Exception occurred while performing UserRolesController.getUsersFromAppEndpoint. Details: "
409                                                         + EcompPortalUtils.getStackTrace(e));
410                         return new ArrayList<UserApplicationRoles>();
411                 }
412         }
413
414         @RequestMapping(value = { "/portalApi/app/{appId}/roles" }, method = {
415                         RequestMethod.GET }, produces = "application/json")
416         public List<EcompRole> testGetRoles(HttpServletRequest request, @PathVariable("appId") Long appId)
417                         throws HTTPException {
418                 EcompRole[] appRoles = applicationsRestClientService.get(EcompRole[].class, appId, "/roles");
419                 List<EcompRole> rolesList = Arrays.asList(appRoles);
420                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/app/{appId}/roles", "response for appId=" + appId,
421                                 rolesList);
422
423                 return rolesList;
424         }
425
426         @RequestMapping(value = { "/portalApi/admin/import/app/{appId}/roles" }, method = {
427                         RequestMethod.GET }, produces = "application/json")
428         public List<EPRole> importRolesFromRemoteApplication(HttpServletRequest request, @PathVariable("appId") Long appId)
429                         throws HTTPException {
430                 List<EPRole> rolesList = userRolesService.importRolesFromRemoteApplication(appId);
431                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/admin/import/app/{appId}/roles",
432                                 "response for appId=" + appId, rolesList);
433
434                 return rolesList;
435         }
436
437         @RequestMapping(value = { "/portalApi/app/{appId}/user/{orgUserId}/roles" }, method = {
438                         RequestMethod.GET }, produces = "application/json")
439         public EcompRole testGetRoles(HttpServletRequest request, @PathVariable("appId") Long appId,
440                         @PathVariable("orgUserId") String orgUserId) throws Exception {
441                 if (!EcompPortalUtils.legitimateUserId(orgUserId)) {
442                         String msg = "Error /user/<user>/roles not legitimate orgUserId = " + orgUserId;
443                         logger.error(EELFLoggerDelegate.errorLogger, msg);
444                         throw new Exception(msg);
445                 }
446                 EcompRole[] roles = applicationsRestClientService.get(EcompRole[].class, appId,
447                                 String.format("/user/%s/roles", orgUserId));
448                 if (roles.length != 1) {
449                         String msg = "Error /user/<user>/roles returned array. expected size 1 recieved size = " + roles.length;
450                         logger.error(EELFLoggerDelegate.errorLogger, msg);
451                         throw new Exception(msg);
452                 }
453
454                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/app/{appId}/user/{orgUserId}/roles",
455                                 "response for appId='" + appId + "' and orgUserId='" + orgUserId + "'", roles[0]);
456                 return roles[0];
457         }
458
459         @RequestMapping(value = { "/portalApi/saveUserAppRoles" }, method = {
460                         RequestMethod.PUT }, produces = "application/json")
461         public FieldsValidator putAppWithUserRoleRequest(HttpServletRequest request,
462                         @RequestBody AppWithRolesForUser newAppRolesForUser, HttpServletResponse response) {
463                 FieldsValidator fieldsValidator = null;
464                 try {
465
466                         EPUser user = EPUserUtils.getUserSession(request);
467                         fieldsValidator = userRolesService.putUserAppRolesRequest(newAppRolesForUser, user);
468                         response.setStatus(fieldsValidator.httpStatusCode.intValue());
469
470                 } catch (Exception e) {
471                         logger.error(EELFLoggerDelegate.errorLogger, "putAppWithUserRoleRequest failed", e);
472
473                 }
474                 // return fieldsValidator;
475                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/saveUserAppRoles", "PUT result =",
476                                 response.getStatus());
477                 return fieldsValidator;
478         }
479
480         @RequestMapping(value = { "/portalApi/appCatalogRoles" }, method = {
481                         RequestMethod.GET }, produces = "application/json")
482         public List<EPUserAppCatalogRoles> getUserAppCatalogRoles(HttpServletRequest request,
483                         @RequestParam("appName") String appName) {
484                 EPUser user = EPUserUtils.getUserSession(request);
485                 List<EPUserAppCatalogRoles> userAppRoleList = null;
486                 try {
487                         userAppRoleList = userRolesService.getUserAppCatalogRoles(user, appName);
488                 } catch (Exception e) {
489                         logger.error(EELFLoggerDelegate.errorLogger, "putUserWidgetsSortPref failed", e);
490
491                 }
492                 Collections.sort(userAppRoleList, getUserAppCatalogRolesComparator);
493                 EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/userApplicationRoles", "result =", userAppRoleList);
494
495                 return userAppRoleList;
496
497         }
498
499         private Comparator<EPUserAppCatalogRoles> getUserAppCatalogRolesComparator = new Comparator<EPUserAppCatalogRoles>() {
500                 public int compare(EPUserAppCatalogRoles o1, EPUserAppCatalogRoles o2) {
501                         return o1.getRolename().compareTo(o2.getRolename());
502                 }
503         };
504
505         @RequestMapping(value = "/portalApi/externalRequestAccessSystem", method = RequestMethod.GET, produces = "application/json")
506         public ExternalSystemAccess readExternalRequestAccess(HttpServletRequest request) {
507                 ExternalSystemAccess result = null;
508                 try {
509                         result = userRolesService.getExternalRequestAccess();
510                         EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/externalRequestAccessSystem", "GET result =",
511                                         result);
512                 } catch (Exception e) {
513                         logger.error(EELFLoggerDelegate.errorLogger, "readExternalRequestAccess failed: " + e.getMessage());
514                 }
515                 return result;
516         }
517
518 }