use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.
the class DbGroupMemberAuditListener method onAddGroupsToGroup.
@Override
public void onAddGroupsToGroup(Account.Id me, Collection<AccountGroupById> added) {
List<AccountGroupByIdAud> includesAudit = new ArrayList<>();
for (AccountGroupById groupInclude : added) {
AccountGroupByIdAud audit = new AccountGroupByIdAud(groupInclude, me, TimeUtil.nowTs());
includesAudit.add(audit);
}
try (ReviewDb db = schema.open()) {
db.accountGroupByIdAud().insert(includesAudit);
} catch (OrmException e) {
logOrmExceptionForGroups("Cannot log add groups to group event performed by user", me, added, e);
}
}
use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.
the class DbGroupMemberAuditListener method onAddAccountsToGroup.
@Override
public void onAddAccountsToGroup(Account.Id me, Collection<AccountGroupMember> added) {
List<AccountGroupMemberAudit> auditInserts = new ArrayList<>();
for (AccountGroupMember m : added) {
AccountGroupMemberAudit audit = new AccountGroupMemberAudit(m, me, TimeUtil.nowTs());
auditInserts.add(audit);
}
try (ReviewDb db = schema.open()) {
db.accountGroupMembersAudit().insert(auditInserts);
} catch (OrmException e) {
logOrmExceptionForAccounts("Cannot log add accounts to group event performed by user", me, added, e);
}
}
use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.
the class SubmitStrategyOp method updateChange.
@Override
public final boolean updateChange(ChangeContext ctx) throws Exception {
logDebug("{}#updateChange for change {}", getClass().getSimpleName(), toMerge.change().getId());
// Update change and notes from ctx.
toMerge.setControl(ctx.getControl());
PatchSet.Id oldPsId = checkNotNull(toMerge.getPatchsetId());
PatchSet.Id newPsId;
if (alreadyMerged != null) {
alreadyMerged.setControl(ctx.getControl());
mergedPatchSet = getOrCreateAlreadyMergedPatchSet(ctx);
newPsId = mergedPatchSet.getId();
} else {
PatchSet newPatchSet = updateChangeImpl(ctx);
newPsId = checkNotNull(ctx.getChange().currentPatchSetId());
if (newPatchSet == null) {
checkState(oldPsId.equals(newPsId), "patch set advanced from %s to %s but updateChangeImpl did not" + " return new patch set instance", oldPsId, newPsId);
// Ok to use stale notes to get the old patch set, which didn't change
// during the submit strategy.
mergedPatchSet = checkNotNull(args.psUtil.get(ctx.getDb(), ctx.getNotes(), oldPsId), "missing old patch set %s", oldPsId);
} else {
PatchSet.Id n = newPatchSet.getId();
checkState(!n.equals(oldPsId) && n.equals(newPsId), "current patch was %s and is now %s, but updateChangeImpl returned" + " new patch set instance at %s", oldPsId, newPsId, n);
mergedPatchSet = newPatchSet;
}
}
Change c = ctx.getChange();
Change.Id id = c.getId();
CodeReviewCommit commit = args.commitStatus.get(id);
checkNotNull(commit, "missing commit for change " + id);
CommitMergeStatus s = commit.getStatusCode();
checkNotNull(s, "status not set for change " + id + " expected to previously fail fast");
logDebug("Status of change {} ({}) on {}: {}", id, commit.name(), c.getDest(), s);
setApproval(ctx, args.caller);
mergeResultRev = alreadyMerged == null ? args.mergeTip.getMergeResults().get(commit) : // ChangeMergedEvent in the fixup case, but we'll just live with that.
alreadyMerged;
try {
setMerged(ctx, message(ctx, commit, s));
} catch (OrmException err) {
String msg = "Error updating change status for " + id;
log.error(msg, err);
args.commitStatus.logProblem(id, msg);
// It's possible this happened before updating anything in the db, but
// it's hard to know for sure, so just return true below to be safe.
}
updatedChange = c;
return true;
}
use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.
the class ConflictsPredicate method listFiles.
public static List<String> listFiles(Change c, Arguments args, ChangeDataCache changeDataCache) throws OrmException {
try (Repository repo = args.repoManager.openRepository(c.getProject());
RevWalk rw = new RevWalk(repo)) {
RevCommit ps = rw.parseCommit(changeDataCache.getTestAgainst());
if (ps.getParentCount() > 1) {
String dest = c.getDest().get();
Ref destBranch = repo.getRefDatabase().getRef(dest);
destBranch.getObjectId();
rw.setRevFilter(RevFilter.MERGE_BASE);
rw.markStart(rw.parseCommit(destBranch.getObjectId()));
rw.markStart(ps);
RevCommit base = rw.next();
// TODO(zivkov): handle the case with multiple merge bases
List<String> files = new ArrayList<>();
try (TreeWalk tw = new TreeWalk(repo)) {
if (base != null) {
tw.setFilter(TreeFilter.ANY_DIFF);
tw.addTree(base.getTree());
}
tw.addTree(ps.getTree());
tw.setRecursive(true);
while (tw.next()) {
files.add(tw.getPathString());
}
}
return files;
}
return args.changeDataFactory.create(args.db.get(), c).currentFilePaths();
} catch (IOException e) {
throw new OrmException(e);
}
}
use of com.google.gwtorm.server.OrmException in project gerrit by GerritCodeReview.
the class FuzzyTopicPredicate method match.
@Override
public boolean match(final ChangeData cd) throws OrmException {
Change change = cd.change();
if (change == null) {
return false;
}
String t = change.getTopic();
if (t == null) {
return false;
}
try {
Predicate<ChangeData> thisId = new LegacyChangeIdPredicate(cd.getId());
Iterable<ChangeData> results = index.getSource(and(thisId, this), IndexedChangeQuery.oneResult()).read();
return !Iterables.isEmpty(results);
} catch (QueryParseException e) {
throw new OrmException(e);
}
}
Aggregations