use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class Schema_146 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
try (Repository repo = repoManager.openRepository(allUsersName);
RevWalk rw = new RevWalk(repo);
ObjectInserter oi = repo.newObjectInserter()) {
ObjectId emptyTree = emptyTree(oi);
for (Account account : db.accounts().all()) {
String refName = RefNames.refsUsers(account.getId());
Ref ref = repo.exactRef(refName);
if (ref != null) {
rewriteUserBranch(repo, rw, oi, emptyTree, ref, account);
} else {
AccountsUpdate.createUserBranch(repo, oi, serverIdent, serverIdent, account);
}
}
} catch (IOException e) {
throw new OrmException("Failed to rewrite user branches.", e);
}
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class FromAddressGeneratorProviderTest method makeUser.
private AccountState makeUser(final String name, final String email) {
final Account.Id userId = new Account.Id(42);
final Account account = new Account(userId, TimeUtil.nowTs());
account.setFullName(name);
account.setPreferredEmail(email);
return new AccountState(account, Collections.emptySet(), Collections.emptySet(), new HashMap<>());
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class LsUserRefs method run.
@Override
protected void run() throws Failure {
Account userAccount;
try {
userAccount = accountResolver.find(db, userName);
} catch (OrmException e) {
throw die(e);
}
if (userAccount == null) {
stdout.print("No single user could be found when searching for: " + userName + '\n');
stdout.flush();
return;
}
IdentifiedUser user = userFactory.create(userAccount.getId());
ProjectControl userProjectControl = projectControl.forUser(user);
try (Repository repo = repoManager.openRepository(userProjectControl.getProject().getNameKey())) {
try {
Map<String, Ref> refsMap = new VisibleRefFilter(tagCache, changeNotesFactory, changeCache, repo, userProjectControl, db, true).filter(repo.getRefDatabase().getRefs(ALL), false);
for (final String ref : refsMap.keySet()) {
if (!onlyRefsHeads || ref.startsWith(RefNames.REFS_HEADS)) {
stdout.println(ref);
}
}
} catch (IOException e) {
throw new Failure(1, "fatal: Error reading refs: '" + projectControl.getProject().getNameKey(), e);
}
} catch (RepositoryNotFoundException e) {
throw die("'" + projectControl.getProject().getNameKey() + "': not a git archive");
} catch (IOException e) {
throw die("Error opening: '" + projectControl.getProject().getNameKey());
}
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class PostReviewers method addByAccountId.
@Nullable
private Addition addByAccountId(String reviewer, ChangeResource rsrc, ReviewerState state, NotifyHandling notify, ListMultimap<RecipientType, Account.Id> accountsToNotify, boolean allowGroup, boolean allowByEmail) throws OrmException, PermissionBackendException {
Account.Id accountId = null;
try {
accountId = accounts.parse(reviewer).getAccountId();
} catch (UnprocessableEntityException | AuthException e) {
// AuthException won't occur since the user is authenticated at this point.
if (!allowGroup && !allowByEmail) {
// Only return failure if we aren't going to try other interpretations.
return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerNotFoundUser, reviewer));
}
return null;
}
ReviewerResource rrsrc = reviewerFactory.create(rsrc, accountId);
Account member = rrsrc.getReviewerUser().getAccount();
PermissionBackend.ForRef perm = permissionBackend.user(rrsrc.getReviewerUser()).ref(rrsrc.getChange().getDest());
if (isValidReviewer(member, perm)) {
return new Addition(reviewer, rsrc, ImmutableSet.of(member.getId()), null, state, notify, accountsToNotify);
}
if (!member.isActive()) {
if (allowByEmail && state == CC) {
return null;
}
return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerInactive, reviewer));
}
return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerCantSeeChange, reviewer));
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class NoteDbUpdateManager method checkExpectedState.
private void checkExpectedState() throws OrmException, IOException {
if (!checkExpectedState) {
return;
}
// that got passed into the ChangeUpdate.
for (Collection<ChangeUpdate> us : changeUpdates.asMap().values()) {
ChangeUpdate u = us.iterator().next();
NoteDbChangeState expectedState = NoteDbChangeState.parse(u.getChange());
if (expectedState == null) {
// MismatchedStateException.
continue;
}
if (expectedState.getPrimaryStorage() == PrimaryStorage.NOTE_DB) {
// NoteDb is primary, no need to compare state to ReviewDb.
continue;
}
if (!expectedState.isChangeUpToDate(changeRepo.cmds.getRepoRefCache())) {
throw new MismatchedStateException(u.getId(), expectedState);
}
}
for (Collection<ChangeDraftUpdate> us : draftUpdates.asMap().values()) {
ChangeDraftUpdate u = us.iterator().next();
NoteDbChangeState expectedState = NoteDbChangeState.parse(u.getChange());
if (expectedState == null || expectedState.getPrimaryStorage() == PrimaryStorage.NOTE_DB) {
// See above.
continue;
}
Account.Id accountId = u.getAccountId();
if (!expectedState.areDraftsUpToDate(allUsersRepo.cmds.getRepoRefCache(), accountId)) {
ObjectId expectedDraftId = firstNonNull(expectedState.getDraftIds().get(accountId), ObjectId.zeroId());
throw new OrmConcurrencyException(String.format("cannot apply NoteDb updates for change %s;" + " draft ref for account %s does not match %s", u.getId(), accountId, expectedDraftId.name()));
}
}
}
Aggregations