use of com.google.gerrit.extensions.restapi.TopLevelResource in project gerrit by GerritCodeReview.
the class GroupsImpl method list.
private SortedMap<String, GroupInfo> list(ListRequest req) throws RestApiException {
TopLevelResource tlr = TopLevelResource.INSTANCE;
ListGroups list = listGroups.get();
list.setOptions(req.getOptions());
for (String project : req.getProjects()) {
try {
ProjectResource rsrc = projects.parse(tlr, IdString.fromDecoded(project));
list.addProject(rsrc.getProjectState());
} catch (Exception e) {
throw asRestApiException("Error looking up project " + project, e);
}
}
for (String group : req.getGroups()) {
list.addGroup(groupResolver.parse(group).getGroupUUID());
}
list.setVisibleToAll(req.getVisibleToAll());
if (req.getOwnedBy() != null) {
list.setOwnedBy(req.getOwnedBy());
}
if (req.getUser() != null) {
try {
list.setUser(accountResolver.resolve(req.getUser()).asUnique().account().id());
} catch (Exception e) {
throw asRestApiException("Error looking up user " + req.getUser(), e);
}
}
list.setOwned(req.getOwned());
list.setLimit(req.getLimit());
list.setStart(req.getStart());
list.setMatchSubstring(req.getSubstring());
list.setMatchRegex(req.getRegex());
list.setSuggest(req.getSuggest());
try {
return list.apply(tlr).value();
} catch (Exception e) {
throw asRestApiException("Cannot list groups", e);
}
}
use of com.google.gerrit.extensions.restapi.TopLevelResource in project gerrit by GerritCodeReview.
the class ListPlugins method apply.
@Override
public Response<SortedMap<String, PluginInfo>> apply(TopLevelResource resource) throws BadRequestException {
Stream<Plugin> s = Streams.stream(pluginLoader.getPlugins(all));
if (matchPrefix != null) {
checkMatchOptions(matchSubstring == null && matchRegex == null);
s = s.filter(p -> p.getName().startsWith(matchPrefix));
} else if (matchSubstring != null) {
checkMatchOptions(matchPrefix == null && matchRegex == null);
String substring = matchSubstring.toLowerCase(Locale.US);
s = s.filter(p -> p.getName().toLowerCase(Locale.US).contains(substring));
} else if (matchRegex != null) {
checkMatchOptions(matchPrefix == null && matchSubstring == null);
Pattern pattern = Pattern.compile(matchRegex);
s = s.filter(p -> pattern.matcher(p.getName()).matches());
}
s = s.sorted(comparing(Plugin::getName));
if (start > 0) {
s = s.skip(start);
}
if (limit > 0) {
s = s.limit(limit);
}
return Response.ok(new TreeMap<>(s.collect(toMap(Plugin::getName, ListPlugins::toPluginInfo))));
}
Aggregations