Migrate ApprovalTypes away from ApprovalCategory(Value)
Many callers of ApprovalTypes depend directly on ApprovalCategory and ApprovalCategoryValue, which are the types stored in the database. We want to move away from storing approval categories in the database in favor of arbitrary labels that can be defined on a per-project level, including implicitly in submit rules. Leaking the database types around the code makes this harder. Replace ApprovalCategoryValue everywhere except the database code with a similar and more concise LabelValue type. Use Strings instead of the database Id types when referring to labels in general. In the short term this may create some confusion in the code (alleviated, hopefully, by documentation and variable names), since some places use legacy category IDs as unique keys and others use new style label names as unique keys. In the long term we will stop using category IDs except to map them to unique label names. Unlike ApprovalCategory, the new and improved ApprovalType does not distinguish between the label name and the human-readable name. Generally these do not vary significantly other than the label name having dashes instead of spaces, which is minor enough in the UI. The other affected functionality here is searching by label; since label names can no longer contain spaces "label:CodeReview" no longer works, only "label:Code-Review". Change-Id: I6854259d60af88b6d9df8d7553120a9af64c74ad
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import static com.google.gerrit.reviewdb.client.ApprovalCategoryValue.formatValue;
|
||||
import static com.google.gerrit.common.data.LabelValue.formatValue;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -85,7 +85,7 @@ public class ReviewerJson {
|
||||
|
||||
FunctionState fs = functionState.create(ctl, psId, approvals);
|
||||
for (ApprovalType at : approvalTypes.getApprovalTypes()) {
|
||||
CategoryFunction.forCategory(at.getCategory()).run(at, fs);
|
||||
CategoryFunction.forType(at).run(at, fs);
|
||||
}
|
||||
|
||||
// Don't use Maps.newTreeMap(Comparator) due to OpenJDK bug 100167.
|
||||
@@ -95,10 +95,9 @@ public class ReviewerJson {
|
||||
for (PermissionRange pr : ctl.getLabelRanges()) {
|
||||
if (!pr.isEmpty()) {
|
||||
// TODO: Support arbitrary labels.
|
||||
ApprovalType at = approvalTypes.byId(ca.getCategoryId());
|
||||
ApprovalType at = approvalTypes.byId(ca.getCategoryId().get());
|
||||
if (at != null) {
|
||||
out.approvals.put(at.getCategory().getLabelName(),
|
||||
formatValue(ca.getValue())); }
|
||||
out.approvals.put(at.getName(), formatValue(ca.getValue())); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user