Search in sources :

Example 1 with IdString

use of com.google.gerrit.extensions.restapi.IdString 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 2 with IdString

use of com.google.gerrit.extensions.restapi.IdString 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 3 with IdString

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

the class Stars method parse.

@Override
public Star parse(AccountResource parent, IdString id) throws ResourceNotFoundException, OrmException {
    IdentifiedUser user = parent.getUser();
    ChangeResource change = changes.parse(TopLevelResource.INSTANCE, id);
    Set<String> labels = starredChangesUtil.getLabels(user.getAccountId(), change.getId());
    return new AccountResource.Star(user, change, labels);
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource) Star(com.google.gerrit.server.account.AccountResource.Star) IdString(com.google.gerrit.extensions.restapi.IdString) IdentifiedUser(com.google.gerrit.server.IdentifiedUser)

Example 4 with IdString

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

the class DashboardsCollection method parse.

@Override
public DashboardResource parse(ProjectResource parent, IdString id) throws ResourceNotFoundException, IOException, ConfigInvalidException {
    ProjectControl myCtl = parent.getControl();
    if (id.toString().equals("default")) {
        return DashboardResource.projectDefault(myCtl);
    }
    List<String> parts = Lists.newArrayList(Splitter.on(':').limit(2).split(id.get()));
    if (parts.size() != 2) {
        throw new ResourceNotFoundException(id);
    }
    CurrentUser user = myCtl.getUser();
    String ref = parts.get(0);
    String path = parts.get(1);
    for (ProjectState ps : myCtl.getProjectState().tree()) {
        try {
            return parse(ps.controlFor(user), ref, path, myCtl);
        } catch (AmbiguousObjectException | ConfigInvalidException | IncorrectObjectTypeException e) {
            throw new ResourceNotFoundException(id);
        } catch (ResourceNotFoundException e) {
            continue;
        }
    }
    throw new ResourceNotFoundException(id);
}
Also used : AmbiguousObjectException(org.eclipse.jgit.errors.AmbiguousObjectException) CurrentUser(com.google.gerrit.server.CurrentUser) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 5 with IdString

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

the class GpgKeys method parse.

@Override
public GpgKey parse(AccountResource parent, IdString id) throws ResourceNotFoundException, PGPException, OrmException, IOException {
    checkVisible(self, parent);
    String str = CharMatcher.whitespace().removeFrom(id.get()).toUpperCase();
    if ((str.length() != 8 && str.length() != 40) || !CharMatcher.anyOf("0123456789ABCDEF").matchesAllOf(str)) {
        throw new ResourceNotFoundException(id);
    }
    byte[] fp = parseFingerprint(id.get(), getGpgExtIds(parent));
    try (PublicKeyStore store = storeProvider.get()) {
        long keyId = keyId(fp);
        for (PGPPublicKeyRing keyRing : store.get(keyId)) {
            PGPPublicKey key = keyRing.getPublicKey();
            if (Arrays.equals(key.getFingerprint(), fp)) {
                return new GpgKey(parent.getUser(), keyRing);
            }
        }
    }
    throw new ResourceNotFoundException(id);
}
Also used : PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) PublicKeyStore(com.google.gerrit.gpg.PublicKeyStore) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) IdString(com.google.gerrit.extensions.restapi.IdString) 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