ListPlugins: Add convenience method to set all options from ListRequest
When invoking ListPlugins from the API implementation, it is necessary to individually call each set method to set the necessary options. To make this simpler, introduce a new method that sets them all at once, using the builder pattern so that the caller can inline the whole thing into a single line. This will also have the advantage that if/when new options are added, it will not be necessary to add extra code at the call location; it can just be added in the new method. Change-Id: Ifcece96c91bdb3350af2ba39e400150ad4328c85
This commit is contained in:
@@ -59,14 +59,7 @@ public class PluginsImpl implements Plugins {
|
||||
return new ListRequest() {
|
||||
@Override
|
||||
public SortedMap<String, PluginInfo> getAsMap() throws RestApiException {
|
||||
ListPlugins list = listProvider.get();
|
||||
list.setAll(this.getAll());
|
||||
list.setStart(this.getStart());
|
||||
list.setLimit(this.getLimit());
|
||||
list.setMatchPrefix(this.getPrefix());
|
||||
list.setMatchSubstring(this.getSubstring());
|
||||
list.setMatchRegex(this.getRegex());
|
||||
return list.apply(TopLevelResource.INSTANCE);
|
||||
return listProvider.get().request(this).apply(TopLevelResource.INSTANCE);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import static java.util.Comparator.comparing;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.api.plugins.Plugins;
|
||||
import com.google.gerrit.extensions.common.PluginInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
@@ -104,6 +105,16 @@ public class ListPlugins implements RestReadView<TopLevelResource> {
|
||||
this.pluginLoader = pluginLoader;
|
||||
}
|
||||
|
||||
public ListPlugins request(Plugins.ListRequest request) {
|
||||
this.setAll(request.getAll());
|
||||
this.setStart(request.getStart());
|
||||
this.setLimit(request.getLimit());
|
||||
this.setMatchPrefix(request.getPrefix());
|
||||
this.setMatchSubstring(request.getSubstring());
|
||||
this.setMatchRegex(request.getRegex());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<String, PluginInfo> apply(TopLevelResource resource) throws BadRequestException {
|
||||
Stream<Plugin> s = Streams.stream(pluginLoader.getPlugins(all));
|
||||
|
||||
Reference in New Issue
Block a user