diff options
author | Patrick Hiesel <hiesel@google.com> | 2018-10-12 13:00:33 +0200 |
---|---|---|
committer | Patrick Hiesel <hiesel@google.com> | 2018-10-12 12:07:12 +0000 |
commit | b3901122eafc322700d178b7136dee5c0d4254ae (patch) | |
tree | ec88d6612ab17229b5d26bad4aebd2c5ea37d0aa | |
parent | 7ec85d808874b0d9c91ba581905006ce87a1b90c (diff) |
ChangeJson: Make PluginDefinedAttributesFactory final
We are striving to reduce the complexity of ChangeJson. One dimension of
this is to make all members final to ensure a consistent object state.
PluginDefinedAttributesFactory is used to create PluginDefinedAttributes
using a query processor as a parameter. Therfore it can't be easily
removed as ChangeJson does not know about the query parameter that was
used to get the results (if any).
As a stop-gap, pass in a PluginDefinedAttributesFactory as an optional
paramater.
Change-Id: Ib1c6d58331dc36c9cbd8dcd1ab6e9f639b7874a8
-rw-r--r-- | java/com/google/gerrit/server/change/ChangeJson.java | 28 | ||||
-rw-r--r-- | java/com/google/gerrit/server/restapi/change/QueryChanges.java | 6 |
2 files changed, 19 insertions, 15 deletions
diff --git a/java/com/google/gerrit/server/change/ChangeJson.java b/java/com/google/gerrit/server/change/ChangeJson.java index 4440191a15..bb0f51156e 100644 --- a/java/com/google/gerrit/server/change/ChangeJson.java +++ b/java/com/google/gerrit/server/change/ChangeJson.java @@ -155,7 +155,13 @@ public class ChangeJson { } public ChangeJson create(Iterable<ListChangesOption> options) { - return factory.create(options); + return factory.create(options, Optional.empty()); + } + + public ChangeJson create( + Iterable<ListChangesOption> options, + PluginDefinedAttributesFactory pluginDefinedAttributesFactory) { + return factory.create(options, Optional.of(pluginDefinedAttributesFactory)); } public ChangeJson create(ListChangesOption first, ListChangesOption... rest) { @@ -164,7 +170,9 @@ public class ChangeJson { } public interface AssistedFactory { - ChangeJson create(Iterable<ListChangesOption> options); + ChangeJson create( + Iterable<ListChangesOption> options, + Optional<PluginDefinedAttributesFactory> pluginDefinedAttributesFactory); } @Singleton @@ -211,11 +219,11 @@ public class ChangeJson { private final TrackingFooters trackingFooters; private final Metrics metrics; private final RevisionJson revisionJson; + private final Optional<PluginDefinedAttributesFactory> pluginDefinedAttributesFactory; private final boolean lazyLoad; private AccountLoader accountLoader; private FixInput fix; - private PluginDefinedAttributesFactory pluginDefinedAttributesFactory; @Inject ChangeJson( @@ -233,7 +241,8 @@ public class ChangeJson { TrackingFooters trackingFooters, Metrics metrics, RevisionJson.Factory revisionJsonFactory, - @Assisted Iterable<ListChangesOption> options) { + @Assisted Iterable<ListChangesOption> options, + @Assisted Optional<PluginDefinedAttributesFactory> pluginDefinedAttributesFactory) { this.db = db; this.userProvider = user; this.changeDataFactory = cdf; @@ -250,6 +259,8 @@ public class ChangeJson { this.revisionJson = revisionJsonFactory.create(options); this.options = Sets.immutableEnumSet(options); this.lazyLoad = containsAnyOf(this.options, REQUIRE_LAZY_LOAD); + this.pluginDefinedAttributesFactory = pluginDefinedAttributesFactory; + logger.atFine().log("options = %s", options); } @@ -272,10 +283,6 @@ public class ChangeJson { return this; } - public void setPluginDefinedAttributesFactory(PluginDefinedAttributesFactory pluginsFactory) { - this.pluginDefinedAttributesFactory = pluginsFactory; - } - public ChangeInfo format(ChangeResource rsrc) throws OrmException { return format(changeDataFactory.create(db.get(), rsrc.getNotes())); } @@ -582,8 +589,9 @@ public class ChangeJson { } setSubmitter(cd, out); - out.plugins = - pluginDefinedAttributesFactory != null ? pluginDefinedAttributesFactory.create(cd) : null; + if (pluginDefinedAttributesFactory.isPresent()) { + out.plugins = pluginDefinedAttributesFactory.get().create(cd); + } out.revertOf = cd.change().getRevertOf() != null ? cd.change().getRevertOf().get() : null; if (has(REVIEWER_UPDATES)) { diff --git a/java/com/google/gerrit/server/restapi/change/QueryChanges.java b/java/com/google/gerrit/server/restapi/change/QueryChanges.java index 6610ebb2c0..599b2a5c6f 100644 --- a/java/com/google/gerrit/server/restapi/change/QueryChanges.java +++ b/java/com/google/gerrit/server/restapi/change/QueryChanges.java @@ -131,11 +131,7 @@ public class QueryChanges implements RestReadView<TopLevelResource> { int cnt = queries.size(); List<QueryResult<ChangeData>> results = imp.query(qb.parse(queries)); - - ChangeJson cjson = json.create(options); - cjson.setPluginDefinedAttributesFactory(this.imp); - List<List<ChangeInfo>> res = cjson.formatQueryResults(results); - + List<List<ChangeInfo>> res = json.create(options, this.imp).formatQueryResults(results); for (int n = 0; n < cnt; n++) { List<ChangeInfo> info = res.get(n); if (results.get(n).more() && !info.isEmpty()) { |