ChangeJson: Move out ApprovalInfo creation and remove method

Change-Id: Ib60fcbdd335278c2240fe11383fce2c7d02ff294
This commit is contained in:
Patrick Hiesel 2018-10-12 13:42:33 +02:00
parent b3901122ea
commit 20a3c80765
6 changed files with 31 additions and 42 deletions

View File

@ -26,4 +26,13 @@ public class ApprovalInfo extends AccountInfo {
public ApprovalInfo(Integer id) {
super(id);
}
public ApprovalInfo(
Integer id, Integer value, VotingRangeInfo permittedVotingRange, String tag, Timestamp date) {
super(id);
this.value = value;
this.permittedVotingRange = permittedVotingRange;
this.date = date;
this.tag = tag;
}
}

View File

@ -61,7 +61,6 @@ import com.google.gerrit.extensions.common.ReviewerUpdateInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.common.SubmitRequirementInfo;
import com.google.gerrit.extensions.common.TrackingIdInfo;
import com.google.gerrit.extensions.common.VotingRangeInfo;
import com.google.gerrit.extensions.restapi.Url;
import com.google.gerrit.index.query.QueryResult;
import com.google.gerrit.mail.Address;
@ -104,7 +103,6 @@ import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -264,20 +262,6 @@ public class ChangeJson {
logger.atFine().log("options = %s", options);
}
public static ApprovalInfo getApprovalInfo(
Account.Id id,
Integer value,
VotingRangeInfo permittedVotingRange,
String tag,
Timestamp date) {
ApprovalInfo ai = new ApprovalInfo(id.get());
ai.value = value;
ai.permittedVotingRange = permittedVotingRange;
ai.date = date;
ai.tag = tag;
return ai;
}
public ChangeJson fix(FixInput fix) {
this.fix = fix;
return this;
@ -295,27 +279,8 @@ public class ChangeJson {
return format(project, id, ChangeInfo::new);
}
public <I extends ChangeInfo> I format(
Project.NameKey project, Change.Id id, Supplier<I> changeInfoSupplier) throws OrmException {
ChangeNotes notes;
try {
notes = notesFactory.createChecked(db.get(), project, id);
} catch (OrmException e) {
if (!has(CHECK)) {
throw e;
}
return checkOnly(changeDataFactory.create(db.get(), project, id), changeInfoSupplier);
}
return format(changeDataFactory.create(db.get(), notes), changeInfoSupplier);
}
public ChangeInfo format(ChangeData cd) throws OrmException {
return format(cd, ChangeInfo::new);
}
public <I extends ChangeInfo> I format(ChangeData cd, Supplier<I> changeInfoSupplier)
throws OrmException {
return format(cd, Optional.empty(), true, changeInfoSupplier);
return format(cd, Optional.empty(), true, ChangeInfo::new);
}
public ChangeInfo format(RevisionResource rsrc) throws OrmException {
@ -323,7 +288,7 @@ public class ChangeJson {
return format(cd, Optional.of(rsrc.getPatchSet().getId()), true, ChangeInfo::new);
}
public List<List<ChangeInfo>> formatQueryResults(List<QueryResult<ChangeData>> in)
public List<List<ChangeInfo>> format(List<QueryResult<ChangeData>> in)
throws PermissionBackendException {
try (Timer0.Context ignored = metrics.formatQueryResultsLatency.start()) {
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
@ -342,7 +307,7 @@ public class ChangeJson {
}
}
public List<ChangeInfo> formatChangeDatas(Collection<ChangeData> in)
public List<ChangeInfo> format(Collection<ChangeData> in)
throws OrmException, PermissionBackendException {
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
ensureLoaded(in);
@ -354,6 +319,21 @@ public class ChangeJson {
return out;
}
public <I extends ChangeInfo> I format(
Project.NameKey project, Change.Id id, Supplier<I> changeInfoSupplier) throws OrmException {
ChangeNotes notes;
try {
notes = notesFactory.createChecked(db.get(), project, id);
} catch (OrmException e) {
if (!has(CHECK)) {
throw e;
}
return checkOnly(changeDataFactory.create(db.get(), project, id), changeInfoSupplier);
}
return format(
changeDataFactory.create(db.get(), notes), Optional.empty(), true, changeInfoSupplier);
}
private static Collection<SubmitRequirementInfo> requirementsFor(ChangeData cd) {
Collection<SubmitRequirementInfo> reqInfos = new ArrayList<>();
for (SubmitRecord submitRecord : cd.submitRecords(SUBMIT_RULE_OPTIONS_STRICT)) {

View File

@ -242,7 +242,7 @@ public class LabelsJson {
VotingRangeInfo permittedVotingRange,
String tag,
Timestamp date) {
ApprovalInfo ai = ChangeJson.getApprovalInfo(id, value, permittedVotingRange, tag, date);
ApprovalInfo ai = new ApprovalInfo(id.get(), value, permittedVotingRange, tag, date);
accountLoader.put(ai);
return ai;
}

View File

@ -115,7 +115,7 @@ public class EventUtil {
Integer value = e.getValue() != null ? Integer.valueOf(e.getValue()) : null;
result.put(
e.getKey(),
ChangeJson.getApprovalInfo(accountState.getAccount().getId(), value, null, null, ts));
new ApprovalInfo(accountState.getAccount().getId().get(), value, null, null, ts));
}
return result;
}

View File

@ -131,7 +131,7 @@ public class QueryChanges implements RestReadView<TopLevelResource> {
int cnt = queries.size();
List<QueryResult<ChangeData>> results = imp.query(qb.parse(queries));
List<List<ChangeInfo>> res = json.create(options, this.imp).formatQueryResults(results);
List<List<ChangeInfo>> res = json.create(options, this.imp).format(results);
for (int n = 0; n < cnt; n++) {
List<ChangeInfo> info = res.get(n);
if (results.get(n).more() && !info.isEmpty()) {

View File

@ -147,7 +147,7 @@ public class SubmittedTogether implements RestReadView<ChangeResource> {
cds = sort(cds, hidden);
SubmittedTogetherInfo info = new SubmittedTogetherInfo();
info.changes = json.create(jsonOpt).formatChangeDatas(cds);
info.changes = json.create(jsonOpt).format(cds);
info.nonVisibleChanges = hidden;
return info;
} catch (OrmException | IOException e) {