use of com.google.gerrit.extensions.restapi.MethodNotAllowedException in project gerrit by GerritCodeReview.
the class GetReflog method apply.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Override
public Response<List<ReflogEntryInfo>> apply(BranchResource rsrc) throws RestApiException, IOException, PermissionBackendException {
permissionBackend.user(rsrc.getUser()).project(rsrc.getNameKey()).check(ProjectPermission.READ_REFLOG);
try (Repository repo = repoManager.openRepository(rsrc.getNameKey())) {
ReflogReader r;
try {
r = repo.getReflogReader(rsrc.getRef());
} catch (UnsupportedOperationException e) {
String msg = "reflog not supported on repo " + rsrc.getNameKey().get();
logger.atSevere().log("%s", msg);
throw new MethodNotAllowedException(msg, e);
}
if (r == null) {
throw new ResourceNotFoundException(rsrc.getRef());
}
List<ReflogEntry> entries;
if (from == null && to == null) {
entries = limit > 0 ? r.getReverseEntries(limit) : r.getReverseEntries();
} else {
entries = limit > 0 ? new ArrayList<>(limit) : new ArrayList<>();
for (ReflogEntry e : r.getReverseEntries()) {
Instant timestamp = e.getWho().getWhen().toInstant();
if ((from == null || from.isBefore(timestamp)) && (to == null || to.isAfter(timestamp))) {
entries.add(e);
}
if (limit > 0 && entries.size() >= limit) {
break;
}
}
}
return Response.ok(Lists.transform(entries, this::newReflogEntryInfo));
}
}
use of com.google.gerrit.extensions.restapi.MethodNotAllowedException in project gerrit by GerritCodeReview.
the class DeleteDashboard method apply.
@Override
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input) throws Exception {
if (resource.isProjectDefault()) {
SetDashboardInput in = new SetDashboardInput();
in.commitMessage = input != null ? input.commitMessage : null;
return defaultSetter.get().apply(resource, in);
}
// TODO: Implement delete of dashboards by API.
throw new MethodNotAllowedException("cannot delete non-default dashboard");
}
use of com.google.gerrit.extensions.restapi.MethodNotAllowedException in project gerrit by GerritCodeReview.
the class GetArchive method apply.
@Override
public Response<BinaryResult> apply(RevisionResource rsrc) throws BadRequestException, IOException, MethodNotAllowedException {
if (Strings.isNullOrEmpty(format)) {
throw new BadRequestException("format is not specified");
}
ArchiveFormatInternal f = allowedFormats.extensions.get("." + format);
if (f == null) {
throw new BadRequestException("unknown archive format");
}
if (f == ArchiveFormatInternal.ZIP) {
throw new MethodNotAllowedException("zip format is disabled");
}
boolean close = true;
Repository repo = repoManager.openRepository(rsrc.getProject());
try {
RevCommit commit;
String name;
try (RevWalk rw = new RevWalk(repo)) {
commit = rw.parseCommit(rsrc.getPatchSet().commitId());
name = name(f, rw, commit);
}
BinaryResult bin = new BinaryResult() {
@Override
public void writeTo(OutputStream out) throws IOException {
try {
new ArchiveCommand(repo).setFormat(f.name()).setTree(commit.getTree()).setOutputStream(out).call();
} catch (GitAPIException e) {
throw new IOException(e);
}
}
@Override
public void close() throws IOException {
repo.close();
}
};
bin.disableGzip().setContentType(f.getMimeType()).setAttachmentName(name);
close = false;
return Response.ok(bin);
} finally {
if (close) {
repo.close();
}
}
}
use of com.google.gerrit.extensions.restapi.MethodNotAllowedException in project gerrit by GerritCodeReview.
the class ChangeIT method deleteMergedChange.
@Test
public void deleteMergedChange() throws Exception {
PushOneCommit.Result changeResult = createChange();
String changeId = changeResult.getChangeId();
merge(changeResult);
MethodNotAllowedException thrown = assertThrows(MethodNotAllowedException.class, () -> gApi.changes().id(changeId).delete());
assertThat(thrown).hasMessageThat().contains("delete not permitted");
}
use of com.google.gerrit.extensions.restapi.MethodNotAllowedException in project gerrit by GerritCodeReview.
the class PluginIT method installNotAllowed.
@Test
public void installNotAllowed() throws Exception {
MethodNotAllowedException thrown = assertThrows(MethodNotAllowedException.class, () -> gApi.plugins().install("test.js", new InstallPluginInput()));
assertThat(thrown).hasMessageThat().contains("remote plugin administration is disabled");
}
Aggregations