Search in sources :

Example 1 with ResourceNotFoundException

use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.

the class Capabilities method parse.

@Override
public Capability parse(AccountResource parent, IdString id) throws ResourceNotFoundException, AuthException, PermissionBackendException {
    IdentifiedUser target = parent.getUser();
    if (self.get() != target) {
        permissionBackend.user(self).check(GlobalPermission.ADMINISTRATE_SERVER);
    }
    GlobalOrPluginPermission perm = parse(id);
    if (permissionBackend.user(target).test(perm)) {
        return new AccountResource.Capability(target, perm.permissionName());
    }
    throw new ResourceNotFoundException(id);
}
Also used : Capability(com.google.gerrit.server.account.AccountResource.Capability) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) GlobalOrPluginPermission(com.google.gerrit.extensions.api.access.GlobalOrPluginPermission)

Example 2 with ResourceNotFoundException

use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.

the class Capabilities method parse.

private GlobalOrPluginPermission parse(IdString id) throws ResourceNotFoundException {
    String name = id.get();
    GlobalOrPluginPermission perm = GlobalPermission.byName(name);
    if (perm != null) {
        return perm;
    }
    int dash = name.lastIndexOf('-');
    if (dash < 0) {
        throw new ResourceNotFoundException(id);
    }
    String pluginName = name.substring(0, dash);
    String capability = name.substring(dash + 1);
    if (pluginName.isEmpty() || capability.isEmpty()) {
        throw new ResourceNotFoundException(id);
    }
    return new PluginPermission(pluginName, capability);
}
Also used : GlobalOrPluginPermission(com.google.gerrit.extensions.api.access.GlobalOrPluginPermission) PluginPermission(com.google.gerrit.extensions.api.access.PluginPermission) IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) GlobalOrPluginPermission(com.google.gerrit.extensions.api.access.GlobalOrPluginPermission)

Example 3 with ResourceNotFoundException

use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.

the class MetricsCollection method parse.

@Override
public MetricResource parse(ConfigResource parent, IdString id) throws ResourceNotFoundException, AuthException, PermissionBackendException {
    permissionBackend.user(user).check(GlobalPermission.VIEW_CACHES);
    Metric metric = metrics.getMetric(id.get());
    if (metric == null) {
        throw new ResourceNotFoundException(id.get());
    }
    return new MetricResource(id.get(), metric);
}
Also used : Metric(com.codahale.metrics.Metric) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 4 with ResourceNotFoundException

use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.

the class DraftComments method parse.

@Override
public DraftCommentResource parse(RevisionResource rev, IdString id) throws ResourceNotFoundException, OrmException, AuthException {
    checkIdentifiedUser();
    String uuid = id.get();
    for (Comment c : commentsUtil.draftByPatchSetAuthor(dbProvider.get(), rev.getPatchSet().getId(), rev.getAccountId(), rev.getNotes())) {
        if (uuid.equals(c.key.uuid)) {
            return new DraftCommentResource(rev, c);
        }
    }
    throw new ResourceNotFoundException(id);
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 5 with ResourceNotFoundException

use of com.google.gerrit.extensions.restapi.ResourceNotFoundException in project gerrit by GerritCodeReview.

the class FileContentUtil method getContent.

/**
   * Get the content of a file at a specific commit or one of it's parent commits.
   *
   * @param project A {@code Project} that this request refers to.
   * @param revstr An {@code ObjectId} specifying the commit.
   * @param path A string specifying the filepath.
   * @param parent A 1-based parent index to get the content from instead. Null if the content
   *     should be obtained from {@code revstr} instead.
   * @return Content of the file as {@code BinaryResult}.
   * @throws ResourceNotFoundException
   * @throws IOException
   */
public BinaryResult getContent(ProjectState project, ObjectId revstr, String path, @Nullable Integer parent) throws BadRequestException, ResourceNotFoundException, IOException {
    try (Repository repo = openRepository(project);
        RevWalk rw = new RevWalk(repo)) {
        if (parent != null) {
            RevCommit revCommit = rw.parseCommit(revstr);
            if (revCommit == null) {
                throw new ResourceNotFoundException("commit not found");
            }
            if (parent > revCommit.getParentCount()) {
                throw new BadRequestException("invalid parent");
            }
            revstr = rw.parseCommit(revstr).getParent(Integer.max(0, parent - 1)).toObjectId();
        }
        return getContent(repo, project, revstr, path);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)75 IdString (com.google.gerrit.extensions.restapi.IdString)18 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)17 AuthException (com.google.gerrit.extensions.restapi.AuthException)15 Repository (org.eclipse.jgit.lib.Repository)14 Project (com.google.gerrit.reviewdb.client.Project)13 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)12 Account (com.google.gerrit.reviewdb.client.Account)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 RevWalk (org.eclipse.jgit.revwalk.RevWalk)11 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)10 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)10 IOException (java.io.IOException)9 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)9 ObjectId (org.eclipse.jgit.lib.ObjectId)9 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)8 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)8 CurrentUser (com.google.gerrit.server.CurrentUser)7 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)7 ArrayList (java.util.ArrayList)7