Package com.google.gerrit.reviewdb.client

Examples of com.google.gerrit.reviewdb.client.Account


        AccountGroup group = groupCache.get(ca.getAutoVerify().getUUID());
        if (group == null) {
          throw new Failure(new NoSuchEntityException());
        }

        Account account = user.get().getAccount();
        hooks.doClaSignupHook(account, ca);

        final AccountGroupMember.Key key =
            new AccountGroupMember.Key(account.getId(), group.getId());
        AccountGroupMember m = db.accountGroupMembers().get(key);
        if (m == null) {
          m = new AccountGroupMember(key);
          db.accountGroupMembersAudit().insert(
              Collections.singleton(
                  new AccountGroupMemberAudit(m, account.getId())));
          db.accountGroupMembers().insert(Collections.singleton(m));
          accountCache.evict(m.getAccountId());
        }

        return VoidResult.INSTANCE;
View Full Code Here


  public final int parseArguments(final Parameters params)
      throws CmdLineException {
    final String token = params.getParameter(0);
    final Account.Id accountId;
    try {
      final Account a = accountResolver.find(token);
      if (a != null) {
        accountId = a.getId();
      } else {
        switch (authType) {
          case HTTP_LDAP:
          case CLIENT_SSL_CERT_LDAP:
          case LDAP:
View Full Code Here

        final GroupControl control = groupControlFactory.validateFor(groupId);
        if (groupCache.get(groupId).getType() != AccountGroup.Type.INTERNAL) {
          throw new Failure(new NameAlreadyUsedException());
        }

        final Account a = findAccount(nameOrEmail);
        if (!a.isActive()) {
          throw new Failure(new InactiveAccountException(a.getFullName()));
        }
        if (!control.canAddMember(a.getId())) {
          throw new Failure(new NoSuchEntityException());
        }

        final AccountGroupMember.Key key =
            new AccountGroupMember.Key(a.getId(), groupId);
        AccountGroupMember m = db.accountGroupMembers().get(key);
        if (m == null) {
          m = new AccountGroupMember(key);
          db.accountGroupMembersAudit().insert(
              Collections.singleton(new AccountGroupMemberAudit(m,
View Full Code Here

    }
  }

  private Account findAccount(final String nameOrEmail) throws OrmException,
      Failure {
    final Account r = accountResolver.find(nameOrEmail);
    if (r == null) {
      throw new Failure(new NoSuchAccountException(nameOrEmail));
    }
    return r;
  }
View Full Code Here

    }

    Collections.sort(members, new Comparator<AccountGroupMember>() {
      public int compare(final AccountGroupMember o1,
          final AccountGroupMember o2) {
        final Account a = aic.get(o1.getAccountId());
        final Account b = aic.get(o2.getAccountId());
        return n(a).compareTo(n(b));
      }

      private String n(final Account a) {
        String n = a.getFullName();
View Full Code Here

      // more than one match, try to return the best one
      String name = nameOrEmail.substring(0, lt - 1);
      Set<Account.Id> nameMatches = Sets.newHashSet();
      for (Account.Id id : ids) {
        Account a = byId.get(id).getAccount();
        if (name.equals(a.getFullName())) {
          nameMatches.add(id);
        }
      }
      return nameMatches.isEmpty() ? ids : nameMatches;
    }
View Full Code Here

      byName.invalidate(username);
    }
  }

  private static AccountState missing(Account.Id accountId) {
    Account account = new Account(accountId);
    Collection<AccountExternalId> ids = Collections.emptySet();
    Set<AccountGroup.UUID> anon = ImmutableSet.of(AccountGroup.ANONYMOUS_USERS);
    return new AccountState(account, anon, ids);
  }
View Full Code Here

      }
    }

    private AccountState load(final ReviewDb db, final Account.Id who)
        throws OrmException {
      final Account account = db.accounts().get(who);
      if (account == null) {
        // Account no longer exists? They are anonymous.
        //
        return missing(who);
      }
View Full Code Here

    return displayName;
  }

  private Account.Id toAccountId(final String nameOrEmail) throws OrmException,
      NoSuchAccountException {
    final Account a = accountResolver.findByNameOrEmail(nameOrEmail);
    if (a == null) {
      throw new NoSuchAccountException("\"" + nameOrEmail
          + "\" is not registered");
    }
    return a.getId();
  }
View Full Code Here

    final Set<Account.Id> reviewerIds = new HashSet<Account.Id>();
    final ChangeControl control = changeControlFactory.validateFor(changeId);

    final ReviewerResult result = new ReviewerResult();
    for (final String reviewer : reviewers) {
      final Account account = accountResolver.find(reviewer);
      if (account == null) {
        AccountGroup group = groupCache.get(new AccountGroup.NameKey(reviewer));

        if (group == null) {
          result.addError(new ReviewerResult.Error(
              ReviewerResult.Error.Type.REVIEWER_NOT_FOUND, reviewer));
          continue;
        }

        if (!isLegalReviewerGroup(group.getGroupUUID())) {
          result.addError(new ReviewerResult.Error(
              ReviewerResult.Error.Type.GROUP_NOT_ALLOWED, reviewer));
          continue;
        }

        final Set<Account> members =
            groupMembersFactory.create().listAccounts(group.getGroupUUID(),
                control.getProject().getNameKey());
        if (members == null || members.size() == 0) {
          result.addError(new ReviewerResult.Error(
              ReviewerResult.Error.Type.GROUP_EMPTY, reviewer));
          continue;
        }

        // if maxAllowed is set to 0, it is allowed to add any number of
        // reviewers
        final int maxAllowed =
            cfg.getInt("addreviewer", "maxAllowed", DEFAULT_MAX_REVIEWERS);
        if (maxAllowed > 0 && members.size() > maxAllowed) {
          result.setMemberCount(members.size());
          result.setAskForConfirmation(false);
          result.addError(new ReviewerResult.Error(
              ReviewerResult.Error.Type.GROUP_HAS_TOO_MANY_MEMBERS, reviewer));
          continue;
        }

        // if maxWithoutCheck is set to 0, we never ask for confirmation
        final int maxWithoutConfirmation =
            cfg.getInt("addreviewer", "maxWithoutConfirmation",
                DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK);
        if (!confirmed && maxWithoutConfirmation > 0
            && members.size() > maxWithoutConfirmation) {
          result.setMemberCount(members.size());
          result.setAskForConfirmation(true);
          result.addError(new ReviewerResult.Error(
              ReviewerResult.Error.Type.GROUP_HAS_TOO_MANY_MEMBERS, reviewer));
          continue;
        }

        for (final Account member : members) {
          if (member.isActive()) {
            final IdentifiedUser user =
                identifiedUserFactory.create(member.getId());
            // Does not account for draft status as a user might want to let a
            // reviewer see a draft.
            if (control.forUser(user).isRefVisible()) {
              reviewerIds.add(member.getId());
            }
          }
        }
        continue;
      }

      if (!account.isActive()) {
        result.addError(new ReviewerResult.Error(
            ReviewerResult.Error.Type.ACCOUNT_INACTIVE,
            formatUser(account, reviewer)));
        continue;
      }

      final IdentifiedUser user = identifiedUserFactory.create(account.getId());
      // Does not account for draft status as a user might want to let a
      // reviewer see a draft.
      if (!control.forUser(user).isRefVisible()) {
        result.addError(new ReviewerResult.Error(
            ReviewerResult.Error.Type.CHANGE_NOT_VISIBLE,
            formatUser(account, reviewer)));
        continue;
      }

      reviewerIds.add(account.getId());
    }

    if (reviewerIds.isEmpty()) {
      return result;
    }
View Full Code Here

TOP

Related Classes of com.google.gerrit.reviewdb.client.Account

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.