ChangeQueryProcessor: Don't implement PluginAttributesFactory
Return a PluginDefinedAttributesFactory via a named getter on ChangeQueryProcessor, instead of making ChangeQueryProcessor implement the interface directly. Without knowing about this interface, a reader seeing `queryProcessor.create(cd)` might be confused: create what, a ChangeInfo? (Wrong.) Change-Id: I07c03169cc13758a7b5649123ccfb945390dd46d
This commit is contained in:
@@ -17,6 +17,7 @@ package com.google.gerrit.server.query.change;
|
|||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.gerrit.server.query.change.ChangeQueryBuilder.FIELD_LIMIT;
|
import static com.google.gerrit.server.query.change.ChangeQueryBuilder.FIELD_LIMIT;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableListMultimap;
|
import com.google.common.collect.ImmutableListMultimap;
|
||||||
import com.google.gerrit.extensions.common.PluginDefinedInfo;
|
import com.google.gerrit.extensions.common.PluginDefinedInfo;
|
||||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||||
@@ -45,7 +46,6 @@ import com.google.gerrit.server.project.ProjectCache;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -56,9 +56,7 @@ import java.util.Set;
|
|||||||
* holding on to a single instance.
|
* holding on to a single instance.
|
||||||
*/
|
*/
|
||||||
public class ChangeQueryProcessor extends QueryProcessor<ChangeData>
|
public class ChangeQueryProcessor extends QueryProcessor<ChangeData>
|
||||||
implements DynamicOptions.BeanReceiver,
|
implements DynamicOptions.BeanReceiver, DynamicOptions.BeanProvider {
|
||||||
DynamicOptions.BeanProvider,
|
|
||||||
PluginDefinedAttributesFactory {
|
|
||||||
private final Provider<CurrentUser> userProvider;
|
private final Provider<CurrentUser> userProvider;
|
||||||
private final ChangeNotes.Factory notesFactory;
|
private final ChangeNotes.Factory notesFactory;
|
||||||
private final ImmutableListMultimap<String, ChangeAttributeFactory> attributeFactoriesByPlugin;
|
private final ImmutableListMultimap<String, ChangeAttributeFactory> attributeFactoriesByPlugin;
|
||||||
@@ -131,8 +129,11 @@ public class ChangeQueryProcessor extends QueryProcessor<ChangeData>
|
|||||||
return dynamicBeans.get(plugin);
|
return dynamicBeans.get(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public PluginDefinedAttributesFactory getAttributesFactory() {
|
||||||
public List<PluginDefinedInfo> create(ChangeData cd) {
|
return this::buildPluginInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImmutableList<PluginDefinedInfo> buildPluginInfo(ChangeData cd) {
|
||||||
return PluginDefinedAttributesFactories.createAll(
|
return PluginDefinedAttributesFactories.createAll(
|
||||||
cd,
|
cd,
|
||||||
this,
|
this,
|
||||||
|
@@ -324,7 +324,7 @@ public class OutputStreamQuery {
|
|||||||
eventFactory.addDependencies(rw, c, d.change(), d.currentPatchSet());
|
eventFactory.addDependencies(rw, c, d.change(), d.currentPatchSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
c.plugins = queryProcessor.create(d);
|
c.plugins = queryProcessor.getAttributesFactory().create(d);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -143,7 +143,8 @@ public class QueryChanges implements RestReadView<TopLevelResource>, DynamicOpti
|
|||||||
|
|
||||||
int cnt = queries.size();
|
int cnt = queries.size();
|
||||||
List<QueryResult<ChangeData>> results = imp.query(qb.parse(queries));
|
List<QueryResult<ChangeData>> results = imp.query(qb.parse(queries));
|
||||||
List<List<ChangeInfo>> res = json.create(options, this.imp).format(results);
|
List<List<ChangeInfo>> res =
|
||||||
|
json.create(options, this.imp.getAttributesFactory()).format(results);
|
||||||
for (int n = 0; n < cnt; n++) {
|
for (int n = 0; n < cnt; n++) {
|
||||||
List<ChangeInfo> info = res.get(n);
|
List<ChangeInfo> info = res.get(n);
|
||||||
if (results.get(n).more() && !info.isEmpty()) {
|
if (results.get(n).more() && !info.isEmpty()) {
|
||||||
|
Reference in New Issue
Block a user