use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.
the class PutOptions method apply.
@Override
public GroupOptionsInfo apply(GroupResource resource, GroupOptionsInfo input) throws MethodNotAllowedException, AuthException, BadRequestException, ResourceNotFoundException, OrmException, IOException {
if (resource.toAccountGroup() == null) {
throw new MethodNotAllowedException();
} else if (!resource.getControl().isOwner()) {
throw new AuthException("Not group owner");
}
if (input == null) {
throw new BadRequestException("options are required");
}
if (input.visibleToAll == null) {
input.visibleToAll = false;
}
AccountGroup group = db.get().accountGroups().get(resource.toAccountGroup().getId());
if (group == null) {
throw new ResourceNotFoundException();
}
group.setVisibleToAll(input.visibleToAll);
db.get().accountGroups().update(Collections.singleton(group));
groupCache.evict(group);
GroupOptionsInfo options = new GroupOptionsInfo();
if (group.isVisibleToAll()) {
options.visibleToAll = true;
}
return options;
}
use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.
the class BatchUpdate method wrapAndThrowException.
static void wrapAndThrowException(Exception e) throws UpdateException, RestApiException {
Throwables.throwIfUnchecked(e);
// Propagate REST API exceptions thrown by operations; they commonly throw exceptions like
// ResourceConflictException to indicate an atomic update failure.
Throwables.throwIfInstanceOf(e, UpdateException.class);
Throwables.throwIfInstanceOf(e, RestApiException.class);
// REST exception types
if (e instanceof InvalidChangeOperationException) {
throw new ResourceConflictException(e.getMessage(), e);
} else if (e instanceof NoSuchChangeException || e instanceof NoSuchRefException || e instanceof NoSuchProjectException) {
throw new ResourceNotFoundException(e.getMessage(), e);
}
// Otherwise, wrap in a generic UpdateException, which does not include a user-visible message.
throw new UpdateException(e);
}
use of com.google.gerrit.extensions.restapi.ResourceNotFoundException 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) {
AddReviewerInput input = new AddReviewerInput();
input.reviewer = reviewer;
input.confirmed = true;
String error;
try {
error = postReviewers.apply(changeRsrc, input).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;
}
use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.
the class Rebuild method apply.
@Override
public BinaryResult apply(ChangeResource rsrc, Input input) throws ResourceNotFoundException, IOException, OrmException, ConfigInvalidException {
if (!migration.commitChangeWrites()) {
throw new ResourceNotFoundException();
}
if (!migration.readChanges()) {
// ChangeBundle#fromNotes currently doesn't work if reading isn't enabled,
// so don't attempt a diff.
rebuild(rsrc);
return BinaryResult.create("Rebuilt change successfully");
}
// Not the same transaction as the rebuild, so may result in spurious diffs
// in the case of races. This should be easy enough to detect by rerunning.
ChangeBundle reviewDbBundle = bundleReader.fromReviewDb(ReviewDbUtil.unwrapDb(db.get()), rsrc.getId());
rebuild(rsrc);
ChangeNotes notes = notesFactory.create(db.get(), rsrc.getChange().getProject(), rsrc.getId());
ChangeBundle noteDbBundle = ChangeBundle.fromNotes(commentsUtil, notes);
List<String> diffs = reviewDbBundle.differencesFrom(noteDbBundle);
if (diffs.isEmpty()) {
return BinaryResult.create("No differences between ReviewDb and NoteDb");
}
return BinaryResult.create(diffs.stream().collect(joining("\n", "Differences between ReviewDb and NoteDb:\n", "\n")));
}
use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.
the class RevisionReviewers method parse.
@Override
public ReviewerResource parse(RevisionResource rsrc, IdString id) throws OrmException, ResourceNotFoundException, AuthException, MethodNotAllowedException {
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(dbProvider.get(), 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);
}
Aggregations