use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class TestSubmitRule method apply.
@Override
public Response<TestSubmitRuleInfo> apply(RevisionResource rsrc, TestSubmitRuleInput input) throws AuthException, PermissionBackendException, BadRequestException {
if (input == null) {
input = new TestSubmitRuleInput();
}
if (input.rule == null) {
throw new BadRequestException("rule is required");
}
if (!rules.isProjectRulesEnabled()) {
throw new AuthException("project rules are disabled");
}
input.filters = MoreObjects.firstNonNull(input.filters, filters);
Project.NameKey name = rsrc.getProject();
Optional<ProjectState> project = projectCache.get(name);
if (!project.isPresent()) {
throw new BadRequestException("project not found " + name);
}
ChangeData cd = changeDataFactory.create(rsrc.getNotes());
SubmitRecord record = prologRule.evaluate(cd, PrologOptions.dryRunOptions(input.rule, input.filters == Filters.SKIP));
AccountLoader accounts = accountInfoFactory.create(true);
TestSubmitRuleInfo out = newSubmitRuleInfo(record, accounts);
accounts.fill();
return Response.ok(out);
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class RevertSubmission method checkPermissionsForAllChanges.
private void checkPermissionsForAllChanges(ChangeResource changeResource, List<ChangeData> changeDatas) throws IOException, AuthException, PermissionBackendException, ResourceConflictException {
for (ChangeData changeData : changeDatas) {
Change change = changeData.change();
// Might do the permission tests multiple times, but these are necessary to ensure that the
// user has permissions to revert all changes. If they lack any permission, no revert will be
// done.
contributorAgreements.check(change.getProject(), changeResource.getUser());
permissionBackend.currentUser().ref(change.getDest()).check(CREATE_CHANGE);
permissionBackend.currentUser().change(changeData).check(REVERT);
permissionBackend.currentUser().change(changeData).check(ChangePermission.READ);
projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject())).checkStatePermitsWrite();
requireNonNull(psUtil.get(changeData.notes(), change.currentPatchSetId()), String.format("current patch set %s of change %s not found", change.currentPatchSetId(), change.currentPatchSetId()));
}
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class SubmittedTogether method applyInfo.
public SubmittedTogetherInfo applyInfo(ChangeResource resource) throws AuthException, IOException, PermissionBackendException {
Change c = resource.getChange();
try {
List<ChangeData> cds;
int hidden;
if (c.isNew()) {
ChangeSet cs = mergeSuperSet.get().completeChangeSet(c, resource.getUser(), options.contains(TOPIC_CLOSURE));
cds = ensureRequiredDataIsLoaded(cs.changes().asList());
hidden = cs.nonVisibleChanges().size();
} else if (c.isMerged()) {
cds = queryProvider.get().bySubmissionId(c.getSubmissionId());
hidden = 0;
} else {
cds = Collections.emptyList();
hidden = 0;
}
if (hidden != 0 && !options.contains(NON_VISIBLE_CHANGES)) {
throw new AuthException("change would be submitted with a change that you cannot see");
}
cds = sort(cds, hidden);
SubmittedTogetherInfo info = new SubmittedTogetherInfo();
info.changes = json.create(jsonOpt).format(cds);
info.nonVisibleChanges = hidden;
return info;
} catch (StorageException | IOException e) {
logger.atSevere().withCause(e).log("Error on getting a ChangeSet");
throw e;
}
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class SubmittedTogether method ensureRequiredDataIsLoaded.
private static List<ChangeData> ensureRequiredDataIsLoaded(List<ChangeData> cds) {
// lazyloading if so.
for (ChangeData cd : cds) {
cd.submitRecords(ChangeJson.SUBMIT_RULE_OPTIONS_LENIENT);
cd.submitRecords(ChangeJson.SUBMIT_RULE_OPTIONS_STRICT);
cd.currentPatchSet();
}
return cds;
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class SubmittedTogether method sort.
private ImmutableList<ChangeData> sort(List<ChangeData> cds, int hidden) throws IOException {
if (cds.size() <= 1 && hidden == 0) {
// repo just to fill out the commit field in PatchSetData.
return ImmutableList.of();
}
long numProjectsDistinct = cds.stream().map(ChangeData::project).distinct().count();
long numProjects = cds.stream().map(ChangeData::project).count();
if (numProjects == numProjectsDistinct || numProjectsDistinct > 5) {
// which would make WalkSorter too expensive for this call.
return cds.stream().sorted(COMPARATOR).collect(toImmutableList());
}
// Perform more expensive walk-sort.
ImmutableList.Builder<ChangeData> sorted = ImmutableList.builderWithExpectedSize(cds.size());
for (PatchSetData psd : sorter.get().sort(cds)) {
sorted.add(psd.data());
}
return sorted.build();
}
Aggregations