protected void run()

in src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java [49:86]


  protected void run() throws UnloggedFailure, Failure, Exception {
    if (activeOnly && inactiveOnly) {
      throw die("--active-only and --inactive-only are mutually exclusive");
    }

    Predicate<AccountState> queryPredicate;
    if (activeOnly) {
      queryPredicate = AccountPredicates.isActive();
    } else if (inactiveOnly) {
      queryPredicate = AccountPredicates.isNotActive();
    } else {
      // This is a work-around to get all the account from the index, querying
      // active and inactive users returns all the users. Another option is to
      // use the Accounts class which will list all the account ids from notedb
      // and then query the secondary index for each user but this way is less
      // efficient.
      queryPredicate = Predicate.or(AccountPredicates.isActive(), AccountPredicates.isNotActive());
    }
    for (AccountState accountState : accountQueryProvider.get().query(queryPredicate)) {
      Account account = accountState.account();
      String out =
          new StringBuilder()
              .append(account.id().toString())
              .append(" |")
              .append(accountState.userName().map(userName -> " " + userName).orElse(""))
              .append(" |")
              .append(Strings.isNullOrEmpty(account.fullName()) ? "" : " " + account.fullName())
              .append(" |")
              .append(
                  Strings.isNullOrEmpty(account.preferredEmail())
                      ? ""
                      : " " + account.preferredEmail())
              .append(" |")
              .append(account.isActive() ? " active" : " inactive")
              .toString();
      stdout.println(out);
    }
  }