Null check for ClientResponse in PolicyUril.java
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / controller / UserRolesController.java
index 4bb447d..b907909 100644 (file)
@@ -1,21 +1,39 @@
 /*-
- * ================================================================================
- * ECOMP Portal SDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the “License”);
+ * you may not use this software except in compliance with the License.
  * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
+ *             http://www.apache.org/licenses/LICENSE-2.0
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * ================================================================================
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
 package org.openecomp.portalapp.portal.controller;
 
@@ -153,17 +171,22 @@ public class UserRolesController extends EPRestrictedBaseController {
                }
 
                StringBuilder adminAppRoles = new StringBuilder();
-               if (result != null && result.appsRoles.size() >= 1) {
-                       adminAppRoles.append("User '" + result.orgUserId + "' has admin role to the apps = {");
-                       for (AppNameIdIsAdmin adminAppRole : result.appsRoles) {
-                               if (adminAppRole.isAdmin) {
-                                       adminAppRoles.append(adminAppRole.appName + ", ");
+               if(result != null){
+                       if ( result.appsRoles.size() >= 1) {
+                               adminAppRoles.append("User '" + result.orgUserId + "' has admin role to the apps = {");
+                               for (AppNameIdIsAdmin adminAppRole : result.appsRoles) {
+                                       if (adminAppRole.isAdmin) {
+                                               adminAppRoles.append(adminAppRole.appName + ", ");
+                                       }
                                }
+                               adminAppRoles.append("}.");
+                       } else {
+                               adminAppRoles.append("User '" + result.orgUserId + "' has no Apps with Admin Role.");
                        }
-                       adminAppRoles.append("}.");
-               } else {
-                       adminAppRoles.append("User '" + result.orgUserId + "' has no Apps with Admin Role.");
+               }else{
+                       logger.error(EELFLoggerDelegate.errorLogger, "putAppWithUserRoleStateForUser: getAppsWithAdminRoleStateForUser result is null");
                }
+               
                logger.info(EELFLoggerDelegate.errorLogger, adminAppRoles.toString());
 
                EcompPortalUtils.logAndSerializeObject(logger, "/portalApi/adminAppsRoles", "get result =", result);
@@ -189,18 +212,23 @@ public class UserRolesController extends EPRestrictedBaseController {
                // newAppsListWithAdminRoles.appsRoles
                FieldsValidator fieldsValidator = new FieldsValidator();
                StringBuilder newAppRoles = new StringBuilder();
-               if (newAppsListWithAdminRoles != null && newAppsListWithAdminRoles.appsRoles.size() >= 1) {
-                       newAppRoles.append("User '" + newAppsListWithAdminRoles.orgUserId + "' has admin role to the apps = { ");
-                       for (AppNameIdIsAdmin adminAppRole : newAppsListWithAdminRoles.appsRoles) {
-                               if (adminAppRole.isAdmin) {
-                                       newAppRoles.append(adminAppRole.appName + " ,");
+               if(newAppsListWithAdminRoles != null ){
+                       if (newAppsListWithAdminRoles.appsRoles.size() >= 1) {
+                               newAppRoles.append("User '" + newAppsListWithAdminRoles.orgUserId + "' has admin role to the apps = { ");
+                               for (AppNameIdIsAdmin adminAppRole : newAppsListWithAdminRoles.appsRoles) {
+                                       if (adminAppRole.isAdmin) {
+                                               newAppRoles.append(adminAppRole.appName + " ,");
+                                       }
                                }
+                               newAppRoles.deleteCharAt(newAppRoles.length() - 1);
+                               newAppRoles.append("}.");
+                       } else {
+                               newAppRoles.append("User '" + newAppsListWithAdminRoles.orgUserId + "' has no Apps with Admin Role.");
                        }
-                       newAppRoles.deleteCharAt(newAppRoles.length() - 1);
-                       newAppRoles.append("}.");
-               } else {
-                       newAppRoles.append("User '" + newAppsListWithAdminRoles.orgUserId + "' has no Apps with Admin Role.");
+               }else{
+                       logger.error(EELFLoggerDelegate.errorLogger, "putAppWithUserRoleStateForUser: putAppsWithAdminRoleStateForUser result is null");
                }
+               
                logger.info(EELFLoggerDelegate.errorLogger, newAppRoles.toString());
 
                EPUser user = EPUserUtils.getUserSession(request);
@@ -339,7 +367,9 @@ public class UserRolesController extends EPRestrictedBaseController {
                boolean changesApplied = false;
                if (!adminRolesService.isAccountAdmin(user)) {
                        EcompPortalUtils.setBadPermissions(user, response, "putAppWithUserRoleStateForUser");
-               } else {
+               } else if(newAppRolesForUser==null){
+                       logger.error(EELFLoggerDelegate.errorLogger, "putAppWithUserRoleStateForUser: newAppRolesForUser is null");
+               } else{
                        changesApplied = userRolesService.setAppWithUserRoleStateForUser(user, newAppRolesForUser);
                        if (changesApplied) {
                                logger.info(EELFLoggerDelegate.applicationLogger,
@@ -404,9 +434,7 @@ public class UserRolesController extends EPRestrictedBaseController {
                        List<UserApplicationRoles> appUsers = userRolesService.getUsersFromAppEndpoint(appId);
                        return appUsers;
                } catch (Exception e) {
-                       logger.error(EELFLoggerDelegate.errorLogger,
-                                       "Exception occurred while performing UserRolesController.getUsersFromAppEndpoint. Details: "
-                                                       + EcompPortalUtils.getStackTrace(e));
+                       logger.error(EELFLoggerDelegate.errorLogger,    "getUsersFromAppEndpoint failed", e);
                        return new ArrayList<UserApplicationRoles>();
                }
        }