Search in sources :

Example 11 with IdString

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

the class Comments method parse.

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

Example 12 with IdString

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

the class CachesCollection method parse.

@Override
public CacheResource parse(ConfigResource parent, IdString id) throws AuthException, ResourceNotFoundException, PermissionBackendException {
    permissionBackend.user(self).check(GlobalPermission.VIEW_CACHES);
    String cacheName = id.get();
    String pluginName = "gerrit";
    int i = cacheName.lastIndexOf('-');
    if (i != -1) {
        pluginName = cacheName.substring(0, i);
        cacheName = cacheName.length() > i + 1 ? cacheName.substring(i + 1) : "";
    }
    Provider<Cache<?, ?>> cacheProvider = cacheMap.byPlugin(pluginName).get(cacheName);
    if (cacheProvider == null) {
        throw new ResourceNotFoundException(id);
    }
    return new CacheResource(pluginName, cacheName, cacheProvider);
}
Also used : IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Cache(com.google.common.cache.Cache)

Example 13 with IdString

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

the class BranchesCollection method parse.

@Override
public BranchResource parse(ProjectResource parent, IdString id) throws ResourceNotFoundException, IOException, BadRequestException {
    String branchName = id.get();
    if (!branchName.equals(Constants.HEAD)) {
        branchName = RefNames.fullName(branchName);
    }
    List<BranchInfo> branches = list.get().apply(parent);
    for (BranchInfo b : branches) {
        if (branchName.equals(b.ref)) {
            return new BranchResource(parent.getControl(), b);
        }
    }
    throw new ResourceNotFoundException();
}
Also used : BranchInfo(com.google.gerrit.extensions.api.projects.BranchInfo) IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 14 with IdString

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

the class ListTags method get.

public TagInfo get(ProjectResource resource, IdString id) throws ResourceNotFoundException, IOException {
    try (Repository repo = getRepository(resource.getNameKey());
        RevWalk rw = new RevWalk(repo)) {
        String tagName = id.get();
        if (!tagName.startsWith(Constants.R_TAGS)) {
            tagName = Constants.R_TAGS + tagName;
        }
        Ref ref = repo.getRefDatabase().exactRef(tagName);
        ProjectControl control = resource.getControl();
        if (ref != null && !visibleTags(control, repo, ImmutableMap.of(ref.getName(), ref)).isEmpty()) {
            return createTagInfo(permissionBackend.user(control.getUser()).project(resource.getNameKey()).ref(ref.getName()), ref, rw);
        }
    }
    throw new ResourceNotFoundException(id);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) IdString(com.google.gerrit.extensions.restapi.IdString) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Aggregations

IdString (com.google.gerrit.extensions.restapi.IdString)14 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)12 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)3 AcceptsPost (com.google.gerrit.extensions.restapi.AcceptsPost)2 RestResource (com.google.gerrit.extensions.restapi.RestResource)2 Comment (com.google.gerrit.reviewdb.client.Comment)2 RobotComment (com.google.gerrit.reviewdb.client.RobotComment)2 Cache (com.google.common.cache.Cache)1 ExtendedHttpAuditEvent (com.google.gerrit.audit.ExtendedHttpAuditEvent)1 GlobalOrPluginPermission (com.google.gerrit.extensions.api.access.GlobalOrPluginPermission)1 PluginPermission (com.google.gerrit.extensions.api.access.PluginPermission)1 BranchInfo (com.google.gerrit.extensions.api.projects.BranchInfo)1 DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)1 AcceptsCreate (com.google.gerrit.extensions.restapi.AcceptsCreate)1 AcceptsDelete (com.google.gerrit.extensions.restapi.AcceptsDelete)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 NeedsParams (com.google.gerrit.extensions.restapi.NeedsParams)1