use of com.google.gerrit.server.update.RetryableAction.Action in project gerrit by GerritCodeReview.
the class RestApiServlet method view.
private ViewData view(RestCollection<RestResource, RestResource> rc, String method, List<IdString> path) throws AmbiguousViewException, RestApiException {
DynamicMap<RestView<RestResource>> views = rc.views();
final IdString projection = path.isEmpty() ? IdString.fromUrl("/") : path.remove(0);
if (!path.isEmpty()) {
// If there are path components still remaining after this projection
// is chosen, look for the projection based upon GET as the method as
// the client thinks it is a nested collection.
method = "GET";
} else if ("HEAD".equals(method)) {
method = "GET";
}
List<String> p = splitProjection(projection);
if (p.size() == 2) {
String viewname = p.get(1);
if (Strings.isNullOrEmpty(viewname)) {
viewname = "/";
}
RestView<RestResource> view = views.get(p.get(0), method + "." + viewname);
if (view != null) {
return new ViewData(p.get(0), view);
}
view = views.get(p.get(0), "GET." + viewname);
if (view != null) {
return new ViewData(p.get(0), view);
}
throw new ResourceNotFoundException(projection);
}
String name = method + "." + p.get(0);
RestView<RestResource> core = views.get(PluginName.GERRIT, name);
if (core != null) {
return new ViewData(PluginName.GERRIT, core);
}
// GET.name so we have to check for this since we haven't found any other views.
if (method.equals("GET")) {
core = views.get(PluginName.GERRIT, "GET." + p.get(0));
if (core != null) {
return new ViewData(PluginName.GERRIT, core);
}
}
Map<String, RestView<RestResource>> r = new TreeMap<>();
for (String plugin : views.plugins()) {
RestView<RestResource> action = views.get(plugin, name);
if (action != null) {
r.put(plugin, action);
}
}
if (r.isEmpty()) {
// GET.name so we have to check for this since we haven't found any other views.
for (String plugin : views.plugins()) {
RestView<RestResource> action = views.get(plugin, "GET." + p.get(0));
if (action != null) {
r.put(plugin, action);
}
}
}
if (r.size() == 1) {
Map.Entry<String, RestView<RestResource>> entry = Iterables.getOnlyElement(r.entrySet());
return new ViewData(entry.getKey(), entry.getValue());
}
if (r.isEmpty()) {
throw new ResourceNotFoundException(projection);
}
throw new AmbiguousViewException(String.format("Projection %s is ambiguous: %s", name, r.keySet().stream().map(in -> in + "~" + projection).collect(joining(", "))));
}
Aggregations