use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.
the class SetReadyForReview method applyImpl.
@Override
protected Response<?> applyImpl(BatchUpdate.Factory updateFactory, ChangeResource rsrc, Input input) throws RestApiException, UpdateException {
Change change = rsrc.getChange();
if (!rsrc.isUserOwner()) {
throw new AuthException("not allowed to set ready for review");
}
if (change.getStatus() != Status.NEW) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
}
if (!change.isWorkInProgress()) {
throw new ResourceConflictException("change is not work in progress");
}
try (BatchUpdate bu = updateFactory.create(db.get(), rsrc.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
bu.addOp(rsrc.getChange().getId(), new WorkInProgressOp(cmUtil, false, input));
bu.execute();
return Response.ok("");
}
}
use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.
the class Schema_108 method getOpenChangesByProject.
private SetMultimap<Project.NameKey, Change.Id> getOpenChangesByProject(ReviewDb db, UpdateUI ui) throws OrmException {
SortedSet<NameKey> projects = repoManager.list();
SortedSet<NameKey> nonExistentProjects = Sets.newTreeSet();
SetMultimap<Project.NameKey, Change.Id> openByProject = MultimapBuilder.hashKeys().hashSetValues().build();
for (Change c : db.changes().all()) {
Status status = c.getStatus();
if (status != null && status.isClosed()) {
continue;
}
NameKey projectKey = c.getProject();
if (!projects.contains(projectKey)) {
nonExistentProjects.add(projectKey);
} else {
// The old "submitted" state is not supported anymore
// (thus status is null) but it was an opened state and needs
// to be migrated as such
openByProject.put(projectKey, c.getId());
}
}
if (!nonExistentProjects.isEmpty()) {
ui.message("Detected open changes referring to the following non-existent projects:");
ui.message(Joiner.on(", ").join(nonExistentProjects));
ui.message("It is highly recommended to remove\n" + "the obsolete open changes, comments and patch-sets from your DB.\n");
}
return openByProject;
}
use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.
the class UnfusedNoteDbBatchUpdate method executeChangeOps.
private Map<Change.Id, ChangeResult> executeChangeOps(boolean dryrun) throws Exception {
logDebug("Executing change ops");
Map<Change.Id, ChangeResult> result = Maps.newLinkedHashMapWithExpectedSize(ops.keySet().size());
initRepository();
Repository repo = repoView.getRepository();
// update as in executeUpdateRepo.
try (ObjectInserter ins = repo.newObjectInserter();
ObjectReader reader = ins.newReader();
RevWalk rw = new RevWalk(reader);
NoteDbUpdateManager updateManager = updateManagerFactory.create(project).setChangeRepo(repo, rw, ins, new ChainedReceiveCommands(repo))) {
if (user.isIdentifiedUser()) {
updateManager.setRefLogIdent(user.asIdentifiedUser().newRefLogIdent(when, tz));
}
for (Map.Entry<Change.Id, Collection<BatchUpdateOp>> e : ops.asMap().entrySet()) {
Change.Id id = e.getKey();
ChangeContextImpl ctx = newChangeContext(id);
boolean dirty = false;
logDebug("Applying {} ops for change {}", e.getValue().size(), id);
for (BatchUpdateOp op : e.getValue()) {
dirty |= op.updateChange(ctx);
}
if (!dirty) {
logDebug("No ops reported dirty, short-circuiting");
result.put(id, ChangeResult.SKIPPED);
continue;
}
for (ChangeUpdate u : ctx.updates.values()) {
updateManager.add(u);
}
if (ctx.deleted) {
logDebug("Change {} was deleted", id);
updateManager.deleteChange(id);
result.put(id, ChangeResult.DELETED);
} else {
result.put(id, ChangeResult.UPSERTED);
}
}
if (!dryrun) {
logDebug("Executing NoteDb updates");
updateManager.execute();
}
}
return result;
}
use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.
the class UnfusedNoteDbBatchUpdate method newChangeContext.
private ChangeContextImpl newChangeContext(Change.Id id) throws OrmException {
logDebug("Opening change {} for update", id);
Change c = newChanges.get(id);
boolean isNew = c != null;
if (!isNew) {
// Pass a synthetic change into ChangeNotes.Factory, which will take care of checking for
// existence and populating columns from the parsed notes state.
// TODO(dborowitz): This dance made more sense when using Reviewdb; consider a nicer way.
c = ChangeNotes.Factory.newNoteDbOnlyChange(project, id);
} else {
logDebug("Change {} is new", id);
}
ChangeNotes notes = changeNotesFactory.createForBatchUpdate(c, !isNew);
ChangeControl ctl = changeControlFactory.controlFor(notes, user);
return new ChangeContextImpl(ctl);
}
use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.
the class FusedNoteDbBatchUpdate method newChangeContext.
private ChangeContextImpl newChangeContext(Change.Id id) throws OrmException {
logDebug("Opening change {} for update", id);
Change c = newChanges.get(id);
boolean isNew = c != null;
if (!isNew) {
// Pass a synthetic change into ChangeNotes.Factory, which will take care of checking for
// existence and populating columns from the parsed notes state.
// TODO(dborowitz): This dance made more sense when using Reviewdb; consider a nicer way.
c = ChangeNotes.Factory.newNoteDbOnlyChange(project, id);
} else {
logDebug("Change {} is new", id);
}
ChangeNotes notes = changeNotesFactory.createForBatchUpdate(c, !isNew);
ChangeControl ctl = changeControlFactory.controlFor(notes, user);
return new ChangeContextImpl(ctl);
}
Aggregations