Search in sources :

Example 6 with Change

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("");
    }
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.reviewdb.client.Change) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 7 with Change

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;
}
Also used : Status(com.google.gerrit.reviewdb.client.Change.Status) ObjectId(org.eclipse.jgit.lib.ObjectId) Change(com.google.gerrit.reviewdb.client.Change) NameKey(com.google.gerrit.reviewdb.client.Project.NameKey)

Example 8 with Change

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;
}
Also used : NoteDbUpdateManager(com.google.gerrit.server.notedb.NoteDbUpdateManager) Change(com.google.gerrit.reviewdb.client.Change) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate) Repository(org.eclipse.jgit.lib.Repository) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) Collection(java.util.Collection) ObjectReader(org.eclipse.jgit.lib.ObjectReader) RequestId(com.google.gerrit.server.util.RequestId) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 9 with Change

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);
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) Change(com.google.gerrit.reviewdb.client.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes)

Example 10 with Change

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);
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) Change(com.google.gerrit.reviewdb.client.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes)

Aggregations

Change (com.google.gerrit.reviewdb.client.Change)191 Test (org.junit.Test)96 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)53 ObjectId (org.eclipse.jgit.lib.ObjectId)32 Timestamp (java.sql.Timestamp)31 Account (com.google.gerrit.reviewdb.client.Account)30 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 OrmException (com.google.gwtorm.server.OrmException)28 Project (com.google.gerrit.reviewdb.client.Project)27 Repository (org.eclipse.jgit.lib.Repository)27 RevWalk (org.eclipse.jgit.revwalk.RevWalk)24 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)23 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)22 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)21 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)17 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)17 ChangeData (com.google.gerrit.server.query.change.ChangeData)16 RevId (com.google.gerrit.reviewdb.client.RevId)15