Search in sources :

Example 11 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class AbandonUtil method getValidChanges.

private Collection<ChangeControl> getValidChanges(Collection<ChangeControl> changeControls, String query) throws OrmException, QueryParseException {
    Collection<ChangeControl> validChanges = new ArrayList<>();
    for (ChangeControl cc : changeControls) {
        String newQuery = query + " change:" + cc.getId();
        List<ChangeData> changesToAbandon = queryProcessor.enforceVisibility(false).query(queryBuilder.parse(newQuery)).entities();
        if (!changesToAbandon.isEmpty()) {
            validChanges.add(cc);
        } else {
            log.debug("Change data with id \"{}\" does not satisfy the query \"{}\"" + " any more, hence skipping it in clean up", cc.getId(), query);
        }
    }
    return validChanges;
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) ArrayList(java.util.ArrayList) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Example 12 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class TestChanges method stubChangeControl.

private static ChangeControl stubChangeControl(AbstractChangeNotes.Args args, Change c, CurrentUser user) throws OrmException {
    ChangeControl ctl = EasyMock.createMock(ChangeControl.class);
    expect(ctl.getChange()).andStubReturn(c);
    expect(ctl.getProject()).andStubReturn(new Project(c.getProject()));
    expect(ctl.getUser()).andStubReturn(user);
    ChangeNotes notes = new ChangeNotes(args, c).load();
    expect(ctl.getNotes()).andStubReturn(notes);
    expect(ctl.getId()).andStubReturn(c.getId());
    EasyMock.replay(ctl);
    return ctl;
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ChangeControl(com.google.gerrit.server.project.ChangeControl) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractChangeNotes(com.google.gerrit.server.notedb.AbstractChangeNotes)

Example 13 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method invalidRevision.

@Test
public void invalidRevision() throws Exception {
    // NoteDb always parses the revision when inserting a patch set, so we can't
    // create an invalid patch set.
    assume().that(notesMigration.enabled()).isFalse();
    ChangeControl ctl = insertChange();
    PatchSet ps = newPatchSet(ctl.getChange().currentPatchSetId(), "fooooooooooooooooooooooooooooooooooooooo", adminId);
    db.patchSets().update(singleton(ps));
    assertProblems(ctl, null, problem("Invalid revision on patch set 1: fooooooooooooooooooooooooooooooooooooooo"));
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) TestChanges.newPatchSet(com.google.gerrit.testutil.TestChanges.newPatchSet) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class ChangeFinder method asChangeControls.

private List<ChangeControl> asChangeControls(List<ChangeData> cds, CurrentUser user) throws OrmException {
    List<ChangeControl> ctls = new ArrayList<>(cds.size());
    if (!indexConfig.separateChangeSubIndexes()) {
        for (ChangeData cd : cds) {
            ctls.add(cd.changeControl(user));
        }
        return ctls;
    }
    // If an index implementation uses separate non-atomic subindexes, it's possible to temporarily
    // observe a change as present in both subindexes, if this search is concurrent with a write.
    // Dedup to avoid confusing the caller. We can choose an arbitrary ChangeData instance because
    // the index results have no stored fields, so the data is already reloaded. (It's also possible
    // that a change might appear in zero subindexes, but there's nothing we can do here to help
    // this case.)
    Set<Change.Id> seen = Sets.newHashSetWithExpectedSize(cds.size());
    for (ChangeData cd : cds) {
        if (seen.add(cd.getId())) {
            ctls.add(cd.changeControl(user));
        }
    }
    return ctls;
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) ArrayList(java.util.ArrayList) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Example 15 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class PostPrivate method applyImpl.

@Override
public Response<String> applyImpl(BatchUpdate.Factory updateFactory, ChangeResource rsrc, SetPrivateOp.Input input) throws RestApiException, UpdateException {
    if (!canSetPrivate(rsrc)) {
        throw new AuthException("not allowed to mark private");
    }
    if (rsrc.getChange().isPrivate()) {
        return Response.ok("");
    }
    ChangeControl control = rsrc.getControl();
    SetPrivateOp op = new SetPrivateOp(cmUtil, true, input);
    try (BatchUpdate u = updateFactory.create(dbProvider.get(), control.getProject().getNameKey(), control.getUser(), TimeUtil.nowTs())) {
        u.addOp(control.getId(), op).execute();
    }
    return Response.created("");
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) AuthException(com.google.gerrit.extensions.restapi.AuthException) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Aggregations

ChangeControl (com.google.gerrit.server.project.ChangeControl)34 Change (com.google.gerrit.reviewdb.client.Change)11 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)9 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)7 AuthException (com.google.gerrit.extensions.restapi.AuthException)6 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)6 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)5 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 Project (com.google.gerrit.reviewdb.client.Project)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 HashMap (java.util.HashMap)5 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)4 ObjectId (org.eclipse.jgit.lib.ObjectId)4 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)4 ObjectReader (org.eclipse.jgit.lib.ObjectReader)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 LabelType (com.google.gerrit.common.data.LabelType)3 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 Branch (com.google.gerrit.reviewdb.client.Branch)3