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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations