Issue-ID: PORTAL-913 optimization in git clone using --depth
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / service / UserRolesCommonServiceImpl.java
index bfc232a..4924e65 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START==========================================
  * ONAP Portal
  * ===================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
  *
  * Unless otherwise specified, all software contained herein is licensed
@@ -200,7 +200,12 @@ public class UserRolesCommonServiceImpl  {
                                        client = new EPUser();
                                        client.setOrgUserId(userId);
                                        client.setSystemUser(true);
-                                       client.setFirstName(userId.substring(0,userId.indexOf("@")));
+                                       if (userId.indexOf("@") != -1) {
+                                               client.setFirstName(userId.substring(0,userId.indexOf("@")));
+                                       }
+                                       else {
+                                               client.setFirstName(userId);
+                                       }
                                }
                                if (client == null) {
                                        String msg = "createLocalUserIfNecessary: cannot create user " + userId
@@ -1084,7 +1089,7 @@ public class UserRolesCommonServiceImpl  {
                                        
                                applyChangesToUserAppRolesForMyLoginsRequest(user, appId);
 
-                               boolean systemUser = newAppRolesForUser.isSystemUser();
+                               Boolean systemUser = (newAppRolesForUser.getIsSystemUser() != null ? newAppRolesForUser.getIsSystemUser() : false);
 
                                if ((app.getCentralAuth() || app.getId().equals(PortalConstants.PORTAL_APP_ID)) && systemUser) {
 
@@ -1192,7 +1197,7 @@ public class UserRolesCommonServiceImpl  {
         * @param roleInAppUser Contains list of active roles 
         */
        @SuppressWarnings("unchecked")
-       private void updateUserRolesInExternalSystem(EPApp app, String orgUserId, List<RoleInAppForUser> roleInAppUser, boolean isPortalRequest,boolean isSystemUser,Set<EcompRole> deletedRolesByApprover,boolean isLoggedInUserRoleAdminofApp) throws Exception
+       private void updateUserRolesInExternalSystem(EPApp app, String orgUserId, List<RoleInAppForUser> roleInAppUser, boolean isPortalRequest,boolean nonHumanUserId,Set<EcompRole> deletedRolesByApprover,boolean isLoggedInUserRoleAdminofApp) throws Exception
        {
                try {
                        // check if user exists
@@ -1200,15 +1205,23 @@ public class UserRolesCommonServiceImpl  {
                        userParams.put("orgUserIdValue", orgUserId);
                        List<EPUser> userInfo = checkIfUserExists(userParams);
                        if (userInfo.isEmpty()) {
-                               createLocalUserIfNecessary(orgUserId, isSystemUser);
+                               createLocalUserIfNecessary(orgUserId, nonHumanUserId);
                        }
                        String name = "";
                        if (EPCommonSystemProperties
-                                       .containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN) && !isSystemUser) {
-                               name = orgUserId
-                                               + SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN);
+                                       .containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN) && !nonHumanUserId) {
+                               if(orgUserId.indexOf("@") ==-1) {
+                                       name = orgUserId + SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN);
+                               }else {
+                                       name = orgUserId;
+                               }
                        } else {
                                name = orgUserId;
+                               if(nonHumanUserId && orgUserId!=null) {
+                       if(orgUserId.indexOf("@") ==-1) {
+                               name = orgUserId + SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN);
+                       }                       
+               }
                        }
                        ObjectMapper mapper = new ObjectMapper();
                        HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth();
@@ -2303,10 +2316,15 @@ public class UserRolesCommonServiceImpl  {
                EPApp app = appsService.getApp(appId);
                //If local or centralized application
                if (appId == PortalConstants.PORTAL_APP_ID || app.getCentralAuth()) {
+                       Map<String, Object> params = new HashMap<>();
+                       params.put("id", app.getId());
+                       params.put("active", true);
                        @SuppressWarnings("unchecked")
-                       List<EPUser> userList = (List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsers", null, null);
+                       //List<EPUser> userList = (List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsers", null, null);
+                       //List<Object[]> userList = (List<Object[]>) dataAccessService.executeNamedQuery("getActiveUsersForApp", params, null);
+                       List<EPUser> userList = (List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsersForApp", params, null);
                        for (EPUser user : userList) {
-                               UserApplicationRoles userWithAppRoles = convertToUserApplicationRoles(appId, user, app);
+                               UserApplicationRoles userWithAppRoles = convertToUserApplicationRoles(user, app.getId());
                                if (userWithAppRoles.getRoles() != null && userWithAppRoles.getRoles().size() > 0)
                                        userApplicationRoles.add(userWithAppRoles);
                        }
@@ -2334,6 +2352,29 @@ public class UserRolesCommonServiceImpl  {
                return userApplicationRoles;
        }
        
+       /**
+        * 
+        * @param user
+        * @param app_id
+        * @return
+        */
+       private UserApplicationRoles convertToUserApplicationRoles(EPUser user, Long appId) {
+               UserApplicationRoles userWithRemoteAppRoles = new UserApplicationRoles();
+               userWithRemoteAppRoles.setAppId(appId);
+               userWithRemoteAppRoles.setOrgUserId(user.getOrgUserId());
+               userWithRemoteAppRoles.setFirstName(user.getFirstName());
+               userWithRemoteAppRoles.setLastName(user.getLastName());
+               List<RemoteRole> roleList = new ArrayList<RemoteRole>();
+               for(EPUserApp userApp :user.getEPUserApps()) {
+                       RemoteRole remoteRole = new RemoteRole();
+                       remoteRole.setName(userApp.getRole().getName());
+                       remoteRole.setId(userApp.getRole().getId());
+                       roleList.add(remoteRole);
+               }
+               userWithRemoteAppRoles.setRoles(roleList);
+               return userWithRemoteAppRoles;
+       }
+       
        /**
         * 
         * @param appId