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;
}
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;
}
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"));
}
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;
}
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("");
}
Aggregations