// If 'LoggedUserActionGroupList' contains an ActionGroup that doesn't exist in
  // ENGINEUserActionGroupList
  // the logged user is not 'ENGINEUser' - Update IsENGINEUser to false; Otherwise, true.
  // Raise 'LoggedIn' event after updating the flag.
  // Use only as 'Step4' of 'UpdateIsENGINEUser'
  public void CheckIsENGINEUser(Object targetObject) {
    UserPortalLoginModel loginModel = (UserPortalLoginModel) targetObject;
    loginModel.getIsENGINEUser().setEntity(null);
    boolean isENGINEUser = true;

    for (ActionGroup actionGroup : loginModel.getLoggedUserActionGroupList()) {
      if (!loginModel.getENGINEUserActionGroupList().contains(actionGroup)) {
        isENGINEUser = false;
        break;
      }
    }

    loginModel.getIsENGINEUser().setEntity(isENGINEUser);
  }
  // Get logged user's permissions and create a list of roles associated with the user (and proceed
  // to Step3).
  // Use only as 'Step2' of 'UpdateIsENGINEUser'
  public void GetUserRoles(Object targetObject) {
    UserPortalLoginModel loginModel = (UserPortalLoginModel) targetObject;
    AsyncDataProvider.GetPermissionsByAdElementId(
        new AsyncQuery(
            targetObject,
            new INewAsyncCallback() {
              @Override
              public void OnSuccess(Object target, Object returnValue) {

                java.util.ArrayList<permissions> permissions =
                    (java.util.ArrayList<permissions>) returnValue;
                java.util.ArrayList<Guid> roleIdList = new java.util.ArrayList<Guid>();
                boolean everyoneBlankPermission = false;
                for (permissions permission : permissions) {
                  if (!everyoneBlankPermission) {
                    everyoneBlankPermission =
                        permission.getad_element_id().getValue().equals(Everyone)
                            && permission.getObjectId().getValue().equals(Blank)
                            && permission.getrole_id().getValue().equals(UserTemplateBasedVM)
                            && permission.getObjectType().equals(VdcObjectType.VmTemplate);
                    if (everyoneBlankPermission) {
                      continue;
                    }
                  }
                  if (!roleIdList.contains(permission.getrole_id())) {
                    roleIdList.add(permission.getrole_id());
                  }
                }
                UserPortalLoginModel loginModel1 = (UserPortalLoginModel) target;
                loginModel1.setLoggedUserActionGroupList(new java.util.ArrayList<ActionGroup>());
                if (roleIdList.size() > 0) {
                  loginModel1.setRolesCounter(roleIdList.size());
                  loginModel1.UpdateUserActionGroups(loginModel1, roleIdList);
                } else {
                  CheckIsENGINEUser(loginModel1);
                }
              }
            }),
        loginModel.getLoggedUser().getUserId());
  }