use of com.google.gerrit.server.change.ReviewerResource in project gerrit by GerritCodeReview.
the class RevisionReviewers method parse.
@Override
public ReviewerResource parse(RevisionResource rsrc, IdString id) throws ResourceNotFoundException, AuthException, MethodNotAllowedException, IOException, ConfigInvalidException {
if (!rsrc.isCurrent()) {
throw new MethodNotAllowedException("Cannot access on non-current patch set");
}
Address address = Address.tryParse(id.get());
Account.Id accountId = null;
try {
accountId = accounts.parse(TopLevelResource.INSTANCE, id).getUser().getAccountId();
} catch (ResourceNotFoundException e) {
if (address == null) {
throw e;
}
}
Collection<Account.Id> reviewers = approvalsUtil.getReviewers(rsrc.getNotes()).all();
// See if the id exists as a reviewer for this change
if (reviewers.contains(accountId)) {
return resourceFactory.create(rsrc, accountId);
}
// See if the address exists as a reviewer on the change
if (address != null && rsrc.getNotes().getReviewersByEmail().all().contains(address)) {
return new ReviewerResource(rsrc, address);
}
throw new ResourceNotFoundException(id);
}
use of com.google.gerrit.server.change.ReviewerResource in project gerrit by GerritCodeReview.
the class DeleteVote method apply.
@Override
public Response<Object> apply(VoteResource rsrc, DeleteVoteInput input) throws RestApiException, UpdateException, IOException, ConfigInvalidException {
if (input == null) {
input = new DeleteVoteInput();
}
if (input.label != null && !rsrc.getLabel().equals(input.label)) {
throw new BadRequestException("label must match URL");
}
if (input.notify == null) {
input.notify = NotifyHandling.ALL;
}
ReviewerResource r = rsrc.getReviewer();
Change change = r.getChange();
if (r.getRevisionResource() != null && !r.getRevisionResource().isCurrent()) {
throw new MethodNotAllowedException("Cannot delete vote on non-current patch set");
}
try (BatchUpdate bu = updateFactory.create(change.getProject(), r.getChangeResource().getUser(), TimeUtil.now())) {
bu.setNotify(notifyResolver.resolve(firstNonNull(input.notify, NotifyHandling.ALL), input.notifyDetails));
bu.addOp(change.getId(), new Op(projectCache.get(r.getChange().getProject()).orElseThrow(illegalState(r.getChange().getProject())), r.getReviewerUser().state(), rsrc.getLabel(), input));
if (!input.ignoreAutomaticAttentionSetRules && !r.getReviewerUser().getAccountId().equals(currentUserProvider.get().getAccountId())) {
bu.addOp(change.getId(), attentionSetOpFactory.create(r.getReviewerUser().getAccountId(), /* reason= */
"Their vote was deleted", /* notify= */
false));
}
if (input.ignoreAutomaticAttentionSetRules) {
bu.addOp(change.getId(), new AttentionSetUnchangedOp());
}
bu.execute();
}
return Response.none();
}
use of com.google.gerrit.server.change.ReviewerResource in project gerrit by GerritCodeReview.
the class SetReviewersCommand method modifyOne.
private boolean modifyOne(ChangeResource changeRsrc) throws Exception {
boolean ok = true;
//
for (Account.Id reviewer : toRemove) {
ReviewerResource rsrc = reviewerFactory.create(changeRsrc, reviewer);
String error = null;
try {
deleteReviewer.apply(rsrc, new DeleteReviewerInput());
} catch (ResourceNotFoundException e) {
error = String.format("could not remove %s: not found", reviewer);
} catch (Exception e) {
error = String.format("could not remove %s: %s", reviewer, e.getMessage());
}
if (error != null) {
ok = false;
writeError("error", error);
}
}
//
for (String reviewer : toAdd) {
ReviewerInput input = new ReviewerInput();
input.reviewer = reviewer;
input.confirmed = true;
String error;
try {
error = postReviewers.apply(changeRsrc, input).value().error;
} catch (Exception e) {
error = String.format("could not add %s: %s", reviewer, e.getMessage());
}
if (error != null) {
ok = false;
writeError("error", error);
}
}
return ok;
}
Aggregations