Rename ApprovalType(s) to LabelType(s)
Change-Id: Icb860eb84d481d519aa0facbef99392b45784843
This commit is contained in:
@@ -17,8 +17,8 @@ package com.google.gerrit.server;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Account.Id;
|
||||
import com.google.gerrit.reviewdb.client.ApprovalCategory;
|
||||
@@ -46,12 +46,12 @@ import java.util.Set;
|
||||
*/
|
||||
public class ApprovalsUtil {
|
||||
private final ReviewDb db;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final LabelTypes labelTypes;
|
||||
|
||||
@Inject
|
||||
public ApprovalsUtil(ReviewDb db, ApprovalTypes approvalTypes) {
|
||||
public ApprovalsUtil(ReviewDb db, LabelTypes labelTypes) {
|
||||
this.db = db;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.labelTypes = labelTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,7 @@ public class ApprovalsUtil {
|
||||
for (PatchSetApproval a : patchSetApprovals) {
|
||||
// ApprovalCategory.SUBMIT is still in db but not relevant in git-store
|
||||
if (!ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
|
||||
final ApprovalType type = approvalTypes.byId(a.getCategoryId().get());
|
||||
final LabelType type = labelTypes.byId(a.getCategoryId().get());
|
||||
if (a.getPatchSetId().equals(source) &&
|
||||
type.isCopyMinScore() &&
|
||||
type.isMaxNegative(a)) {
|
||||
@@ -106,7 +106,7 @@ public class ApprovalsUtil {
|
||||
public void addReviewers(ReviewDb db, Change change, PatchSet ps,
|
||||
PatchSetInfo info, Set<Id> wantReviewers,
|
||||
Set<Account.Id> existingReviewers) throws OrmException {
|
||||
List<ApprovalType> allTypes = approvalTypes.getApprovalTypes();
|
||||
List<LabelType> allTypes = labelTypes.getLabelTypes();
|
||||
if (allTypes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.changes.ListChangesOption;
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.LabelValue;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRange;
|
||||
@@ -114,7 +114,7 @@ public class ChangeJson {
|
||||
}
|
||||
|
||||
private final Provider<ReviewDb> db;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final LabelTypes labelTypes;
|
||||
private final FunctionState.Factory functionState;
|
||||
private final CurrentUser user;
|
||||
private final AnonymousUser anonymous;
|
||||
@@ -134,7 +134,7 @@ public class ChangeJson {
|
||||
@Inject
|
||||
ChangeJson(
|
||||
Provider<ReviewDb> db,
|
||||
ApprovalTypes at,
|
||||
LabelTypes at,
|
||||
FunctionState.Factory fs,
|
||||
CurrentUser u,
|
||||
AnonymousUser au,
|
||||
@@ -146,7 +146,7 @@ public class ChangeJson {
|
||||
@CanonicalWebUrl Provider<String> curl,
|
||||
Urls urls) {
|
||||
this.db = db;
|
||||
this.approvalTypes = at;
|
||||
this.labelTypes = at;
|
||||
this.functionState = fs;
|
||||
this.user = u;
|
||||
this.anonymous = au;
|
||||
@@ -338,7 +338,7 @@ public class ChangeJson {
|
||||
setAllApprovals(cd, labels);
|
||||
}
|
||||
for (Map.Entry<String, LabelInfo> e : labels.entrySet()) {
|
||||
ApprovalType type = approvalTypes.byLabel(e.getKey());
|
||||
LabelType type = labelTypes.byLabel(e.getKey());
|
||||
if (type == null) {
|
||||
continue; // TODO: Support arbitrary labels.
|
||||
}
|
||||
@@ -356,7 +356,7 @@ public class ChangeJson {
|
||||
throws OrmException {
|
||||
// Don't use Maps.newTreeMap(Comparator) due to OpenJDK bug 100167.
|
||||
Map<String, LabelInfo> labels =
|
||||
new TreeMap<String, LabelInfo>(LabelOrdering.create(approvalTypes));
|
||||
new TreeMap<String, LabelInfo>(LabelOrdering.create(labelTypes));
|
||||
for (SubmitRecord rec : submitRecords(cd)) {
|
||||
if (rec.labels == null) {
|
||||
continue;
|
||||
@@ -387,7 +387,7 @@ public class ChangeJson {
|
||||
return labels;
|
||||
}
|
||||
|
||||
private void setRecommendedAndDisliked(ChangeData cd, ApprovalType type,
|
||||
private void setRecommendedAndDisliked(ChangeData cd, LabelType type,
|
||||
LabelInfo label) throws OrmException {
|
||||
if (label.approved != null || label.rejected != null) {
|
||||
return;
|
||||
@@ -428,25 +428,25 @@ public class ChangeJson {
|
||||
Collection<PatchSetApproval> approvals = cd.currentApprovals(db);
|
||||
FunctionState fs =
|
||||
functionState.create(ctl, cd.change(db).currentPatchSetId(), approvals);
|
||||
for (ApprovalType at : approvalTypes.getApprovalTypes()) {
|
||||
CategoryFunction.forType(at).run(at, fs);
|
||||
for (LabelType lt : labelTypes.getLabelTypes()) {
|
||||
CategoryFunction.forType(lt).run(lt, fs);
|
||||
}
|
||||
|
||||
Multimap<Account.Id, String> existing =
|
||||
HashMultimap.create(approvals.size(), labels.size());
|
||||
for (PatchSetApproval psa : approvals) {
|
||||
ApprovalType at = approvalTypes.byId(psa.getCategoryId().get());
|
||||
if (at == null) {
|
||||
LabelType lt = labelTypes.byId(psa.getCategoryId().get());
|
||||
if (lt == null) {
|
||||
continue;
|
||||
}
|
||||
LabelInfo p = labels.get(at.getName());
|
||||
LabelInfo p = labels.get(lt.getName());
|
||||
if (p == null) {
|
||||
continue; // TODO: support arbitrary labels.
|
||||
}
|
||||
if (!getRange(ctl, psa.getAccountId(), at.getName()).isEmpty()) {
|
||||
if (!getRange(ctl, psa.getAccountId(), lt.getName()).isEmpty()) {
|
||||
p.addApproval(approvalInfo(psa.getAccountId(), psa.getValue()));
|
||||
}
|
||||
existing.put(psa.getAccountId(), at.getName());
|
||||
existing.put(psa.getAccountId(), lt.getName());
|
||||
}
|
||||
|
||||
// Add dummy approvals for all permitted labels for each user even if they
|
||||
@@ -475,9 +475,9 @@ public class ChangeJson {
|
||||
//
|
||||
// Don't use Maps.newTreeMap(Comparator) due to OpenJDK bug 100167.
|
||||
Map<String, LabelInfo> labels =
|
||||
new TreeMap<String, LabelInfo>(LabelOrdering.create(approvalTypes));
|
||||
new TreeMap<String, LabelInfo>(LabelOrdering.create(labelTypes));
|
||||
for (PatchSetApproval psa : cd.currentApprovals(db)) {
|
||||
ApprovalType type = approvalTypes.byId(psa.getCategoryId().get());
|
||||
LabelType type = labelTypes.byId(psa.getCategoryId().get());
|
||||
if (type == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -537,7 +537,7 @@ public class ChangeJson {
|
||||
return values.isEmpty() || (values.size() == 1 && values.contains(" 0"));
|
||||
}
|
||||
|
||||
private void setLabelValues(ApprovalType type, LabelInfo label) {
|
||||
private void setLabelValues(LabelType type, LabelInfo label) {
|
||||
label.values = Maps.newLinkedHashMap();
|
||||
for (LabelValue v : type.getValues()) {
|
||||
label.values.put(v.formatValue(), v.getText());
|
||||
@@ -556,7 +556,7 @@ public class ChangeJson {
|
||||
continue;
|
||||
}
|
||||
for (SubmitRecord.Label r : rec.labels) {
|
||||
ApprovalType type = approvalTypes.byLabel(r.label);
|
||||
LabelType type = labelTypes.byLabel(r.label);
|
||||
if (type == null) {
|
||||
continue; // TODO: Support arbitrary labels.
|
||||
}
|
||||
|
||||
@@ -16,17 +16,17 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
|
||||
class LabelOrdering {
|
||||
public static Ordering<String> create(final ApprovalTypes approvalTypes) {
|
||||
public static Ordering<String> create(final LabelTypes labelTypes) {
|
||||
return Ordering.natural().nullsLast().onResultOf(
|
||||
new Function<String, Short>() {
|
||||
@Override
|
||||
public Short apply(String n) {
|
||||
ApprovalType at = approvalTypes.byLabel(n);
|
||||
return at != null ? at.getPosition() : null;
|
||||
LabelType lt = labelTypes.byLabel(n);
|
||||
return lt != null ? lt.getPosition() : null;
|
||||
}
|
||||
}).compound(Ordering.natural());
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.ChangeHooks;
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRange;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
@@ -102,7 +102,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
}
|
||||
|
||||
private final ReviewDb db;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final LabelTypes labelTypes;
|
||||
private final EmailReviewComments.Factory email;
|
||||
@Deprecated private final ChangeHooks hooks;
|
||||
|
||||
@@ -116,11 +116,11 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
|
||||
@Inject
|
||||
PostReview(ReviewDb db,
|
||||
ApprovalTypes approvalTypes,
|
||||
LabelTypes labelTypes,
|
||||
EmailReviewComments.Factory email,
|
||||
ChangeHooks hooks) {
|
||||
this.db = db;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.labelTypes = labelTypes;
|
||||
this.email = email;
|
||||
this.hooks = hooks;
|
||||
}
|
||||
@@ -180,8 +180,8 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
Map.Entry<String, Short> ent = itr.next();
|
||||
|
||||
// TODO Support more generic label assignments.
|
||||
ApprovalType at = approvalTypes.byLabel(ent.getKey());
|
||||
if (at == null) {
|
||||
LabelType lt = labelTypes.byLabel(ent.getKey());
|
||||
if (lt == null) {
|
||||
if (strict) {
|
||||
throw new BadRequestException(String.format(
|
||||
"label \"%s\" is not a configured ApprovalCategory",
|
||||
@@ -198,7 +198,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (at.getValue(ent.getValue()) == null) {
|
||||
if (lt.getValue(ent.getValue()) == null) {
|
||||
if (strict) {
|
||||
throw new BadRequestException(String.format(
|
||||
"label \"%s\": %d is not a valid value",
|
||||
@@ -209,7 +209,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
}
|
||||
}
|
||||
|
||||
String name = at.getName();
|
||||
String name = lt.getName();
|
||||
PermissionRange range = ctl.getRange(Permission.forLabel(name));
|
||||
if (range == null || !range.contains(ent.getValue())) {
|
||||
if (strict) {
|
||||
@@ -345,8 +345,8 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
|
||||
for (Map.Entry<String, Short> ent : labels.entrySet()) {
|
||||
// TODO Support arbitrary label names.
|
||||
ApprovalType at = approvalTypes.byLabel(ent.getKey());
|
||||
String name = at.getName();
|
||||
LabelType lt = labelTypes.byLabel(ent.getKey());
|
||||
String name = lt.getName();
|
||||
if (change.getStatus().isClosed()) {
|
||||
// TODO Allow updating some labels even when closed.
|
||||
continue;
|
||||
@@ -368,23 +368,23 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
upd.add(c);
|
||||
labelDelta.add(format(name, c.getValue()));
|
||||
categories.put(
|
||||
at.getApprovalCategoryId(),
|
||||
at.getApprovalCategoryValueId(c.getValue()));
|
||||
lt.getApprovalCategoryId(),
|
||||
lt.getApprovalCategoryValueId(c.getValue()));
|
||||
} else if (c != null && c.getValue() == ent.getValue()) {
|
||||
current.put(name, c);
|
||||
} else if (c == null) {
|
||||
c = new PatchSetApproval(new PatchSetApproval.Key(
|
||||
rsrc.getPatchSet().getId(),
|
||||
rsrc.getAccountId(),
|
||||
at.getApprovalCategoryId()),
|
||||
lt.getApprovalCategoryId()),
|
||||
ent.getValue());
|
||||
c.setGranted(timestamp);
|
||||
c.cache(change);
|
||||
ins.add(c);
|
||||
labelDelta.add(format(name, c.getValue()));
|
||||
categories.put(
|
||||
at.getApprovalCategoryId(),
|
||||
at.getApprovalCategoryValueId(c.getValue()));
|
||||
lt.getApprovalCategoryId(),
|
||||
lt.getApprovalCategoryValueId(c.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,11 +402,11 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
// TODO Find another way to link reviewers to changes.
|
||||
if (del.isEmpty()) {
|
||||
// If no existing label is being set to 0, hack in the caller
|
||||
// as a reviewer by picking the first server-wide ApprovalType.
|
||||
// as a reviewer by picking the first server-wide LabelType.
|
||||
PatchSetApproval c = new PatchSetApproval(new PatchSetApproval.Key(
|
||||
rsrc.getPatchSet().getId(),
|
||||
rsrc.getAccountId(),
|
||||
approvalTypes.getApprovalTypes().get(0).getApprovalCategoryId()),
|
||||
labelTypes.getLabelTypes().get(0).getApprovalCategoryId()),
|
||||
(short) 0);
|
||||
c.setGranted(timestamp);
|
||||
c.cache(change);
|
||||
@@ -433,9 +433,9 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
|
||||
continue;
|
||||
}
|
||||
|
||||
ApprovalType at = approvalTypes.byId(a.getCategoryId().get());
|
||||
if (at != null) {
|
||||
current.put(at.getName(), a);
|
||||
LabelType lt = labelTypes.byId(a.getCategoryId().get());
|
||||
if (lt != null) {
|
||||
current.put(lt.getName(), a);
|
||||
} else {
|
||||
del.add(a);
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.ChangeHooks;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.GroupDescription;
|
||||
import com.google.gerrit.common.data.GroupDescriptions;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.errors.EmailException;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
@@ -98,7 +98,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|
||||
Provider<ReviewDb> db,
|
||||
IdentifiedUser currentUser,
|
||||
IdentifiedUser.GenericFactory identifiedUserFactory,
|
||||
ApprovalTypes approvalTypes,
|
||||
LabelTypes labelTypes,
|
||||
@GerritServerConfig Config cfg,
|
||||
ChangeHooks hooks,
|
||||
AccountCache accountCache,
|
||||
@@ -117,7 +117,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|
||||
this.accountCache = accountCache;
|
||||
this.json = json;
|
||||
|
||||
this.addReviewerCategoryId = Iterables.getLast(approvalTypes.getApprovalTypes())
|
||||
this.addReviewerCategoryId = Iterables.getLast(labelTypes.getLabelTypes())
|
||||
.getApprovalCategoryId();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ import static com.google.gerrit.common.data.LabelValue.formatValue;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRange;
|
||||
import com.google.gerrit.common.data.SubmitRecord;
|
||||
@@ -42,17 +42,17 @@ import java.util.TreeMap;
|
||||
|
||||
public class ReviewerJson {
|
||||
private final Provider<ReviewDb> db;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final LabelTypes labelTypes;
|
||||
private final FunctionState.Factory functionState;
|
||||
private final AccountInfo.Loader.Factory accountLoaderFactory;
|
||||
|
||||
@Inject
|
||||
ReviewerJson(Provider<ReviewDb> db,
|
||||
ApprovalTypes approvalTypes,
|
||||
LabelTypes labelTypes,
|
||||
FunctionState.Factory functionState,
|
||||
AccountInfo.Loader.Factory accountLoaderFactory) {
|
||||
this.db = db;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.labelTypes = labelTypes;
|
||||
this.functionState = functionState;
|
||||
this.accountLoaderFactory = accountLoaderFactory;
|
||||
}
|
||||
@@ -84,18 +84,18 @@ public class ReviewerJson {
|
||||
}
|
||||
|
||||
FunctionState fs = functionState.create(ctl, psId, approvals);
|
||||
for (ApprovalType at : approvalTypes.getApprovalTypes()) {
|
||||
for (LabelType at : labelTypes.getLabelTypes()) {
|
||||
CategoryFunction.forType(at).run(at, fs);
|
||||
}
|
||||
|
||||
// Don't use Maps.newTreeMap(Comparator) due to OpenJDK bug 100167.
|
||||
out.approvals = new TreeMap<String,String>(LabelOrdering.create(
|
||||
approvalTypes));
|
||||
labelTypes));
|
||||
for (PatchSetApproval ca : approvals) {
|
||||
for (PermissionRange pr : ctl.getLabelRanges()) {
|
||||
if (!pr.isEmpty()) {
|
||||
// TODO: Support arbitrary labels.
|
||||
ApprovalType at = approvalTypes.byId(ca.getCategoryId().get());
|
||||
LabelType at = labelTypes.byId(ca.getCategoryId().get());
|
||||
if (at != null) {
|
||||
out.approvals.put(at.getName(), formatValue(ca.getValue())); }
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import static com.google.inject.Scopes.SINGLETON;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.gerrit.audit.AuditModule;
|
||||
import com.google.gerrit.common.ChangeListener;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.extensions.events.GitReferenceUpdatedListener;
|
||||
import com.google.gerrit.extensions.events.NewProjectCreatedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
@@ -140,7 +140,7 @@ public class GerritGlobalModule extends FactoryModule {
|
||||
break;
|
||||
}
|
||||
|
||||
bind(ApprovalTypes.class).toProvider(ApprovalTypesProvider.class).in(
|
||||
bind(LabelTypes.class).toProvider(LabelTypesProvider.class).in(
|
||||
SINGLETON);
|
||||
bind(EmailExpander.class).toProvider(EmailExpanderProvider.class).in(
|
||||
SINGLETON);
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.reviewdb.client.ApprovalCategory;
|
||||
import com.google.gerrit.reviewdb.client.ApprovalCategoryValue;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
@@ -29,17 +29,17 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ApprovalTypesProvider implements Provider<ApprovalTypes> {
|
||||
public class LabelTypesProvider implements Provider<LabelTypes> {
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
|
||||
@Inject
|
||||
ApprovalTypesProvider(final SchemaFactory<ReviewDb> sf) {
|
||||
LabelTypesProvider(final SchemaFactory<ReviewDb> sf) {
|
||||
schema = sf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApprovalTypes get() {
|
||||
List<ApprovalType> types = new ArrayList<ApprovalType>(2);
|
||||
public LabelTypes get() {
|
||||
List<LabelType> types = new ArrayList<LabelType>(2);
|
||||
|
||||
try {
|
||||
final ReviewDb db = schema.open();
|
||||
@@ -47,7 +47,7 @@ public class ApprovalTypesProvider implements Provider<ApprovalTypes> {
|
||||
for (final ApprovalCategory c : db.approvalCategories().all()) {
|
||||
final List<ApprovalCategoryValue> values =
|
||||
db.approvalCategoryValues().byCategory(c.getId()).toList();
|
||||
types.add(ApprovalType.fromApprovalCategory(c, values));
|
||||
types.add(LabelType.fromApprovalCategory(c, values));
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
@@ -56,6 +56,6 @@ public class ApprovalTypesProvider implements Provider<ApprovalTypes> {
|
||||
throw new ProvisionException("Cannot query approval categories", e);
|
||||
}
|
||||
|
||||
return new ApprovalTypes(Collections.unmodifiableList(types));
|
||||
return new LabelTypes(Collections.unmodifiableList(types));
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.events;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.SubmitRecord;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
@@ -62,7 +62,7 @@ public class EventFactory {
|
||||
private static final Logger log = LoggerFactory.getLogger(EventFactory.class);
|
||||
private final AccountCache accountCache;
|
||||
private final Provider<String> urlProvider;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final LabelTypes labelTypes;
|
||||
private final PatchListCache patchListCache;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private final PatchSetInfoFactory psInfoFactory;
|
||||
@@ -71,13 +71,13 @@ public class EventFactory {
|
||||
@Inject
|
||||
EventFactory(AccountCache accountCache,
|
||||
@CanonicalWebUrl @Nullable Provider<String> urlProvider,
|
||||
ApprovalTypes approvalTypes,
|
||||
LabelTypes labelTypes,
|
||||
final PatchSetInfoFactory psif,
|
||||
PatchListCache patchListCache, SchemaFactory<ReviewDb> schema,
|
||||
@GerritPersonIdent PersonIdent myIdent) {
|
||||
this.accountCache = accountCache;
|
||||
this.urlProvider = urlProvider;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.labelTypes = labelTypes;
|
||||
this.patchListCache = patchListCache;
|
||||
this.schema = schema;
|
||||
this.psInfoFactory = psif;
|
||||
@@ -460,9 +460,9 @@ public class EventFactory {
|
||||
a.by = asAccountAttribute(approval.getAccountId());
|
||||
a.grantedOn = approval.getGranted().getTime() / 1000L;
|
||||
|
||||
ApprovalType at = approvalTypes.byId(approval.getCategoryId().get());
|
||||
if (at != null) {
|
||||
a.description = at.getName();
|
||||
LabelType lt = labelTypes.byId(approval.getCategoryId().get());
|
||||
if (lt != null) {
|
||||
a.description = lt.getName();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import static com.google.gerrit.server.git.MergeUtil.mergeOneCommit;
|
||||
import static com.google.gerrit.server.git.MergeUtil.getApprovalsForCommit;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetAncestor;
|
||||
@@ -53,19 +53,19 @@ import java.util.Map;
|
||||
public class CherryPick extends SubmitStrategy {
|
||||
private final PatchSetInfoFactory patchSetInfoFactory;
|
||||
private final Provider<String> urlProvider;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final LabelTypes labelTypes;
|
||||
private final GitReferenceUpdated gitRefUpdated;
|
||||
private final Map<Change.Id, CodeReviewCommit> newCommits;
|
||||
|
||||
CherryPick(final SubmitStrategy.Arguments args,
|
||||
final PatchSetInfoFactory patchSetInfoFactory,
|
||||
final Provider<String> urlProvider, final ApprovalTypes approvalTypes,
|
||||
final Provider<String> urlProvider, final LabelTypes labelTypes,
|
||||
final GitReferenceUpdated gitRefUpdated) {
|
||||
super(args);
|
||||
|
||||
this.patchSetInfoFactory = patchSetInfoFactory;
|
||||
this.urlProvider = urlProvider;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.labelTypes = labelTypes;
|
||||
this.gitRefUpdated = gitRefUpdated;
|
||||
this.newCommits = new HashMap<Change.Id, CodeReviewCommit>();
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class CherryPick extends SubmitStrategy {
|
||||
}
|
||||
|
||||
final String cherryPickCmtMsg =
|
||||
createCherryPickCommitMessage(n, approvalTypes, urlProvider, args.db,
|
||||
createCherryPickCommitMessage(n, labelTypes, urlProvider, args.db,
|
||||
args.identifiedUserFactory);
|
||||
|
||||
final CodeReviewCommit newCommit =
|
||||
|
||||
@@ -26,8 +26,8 @@ import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.gerrit.common.ChangeHooks;
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.Capable;
|
||||
import com.google.gerrit.common.data.SubmitTypeRecord;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -130,7 +130,7 @@ public class MergeOp {
|
||||
private final GitReferenceUpdated gitRefUpdated;
|
||||
private final MergedSender.Factory mergedSenderFactory;
|
||||
private final MergeFailSender.Factory mergeFailSenderFactory;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final LabelTypes labelTypes;
|
||||
private final PatchSetInfoFactory patchSetInfoFactory;
|
||||
private final IdentifiedUser.GenericFactory identifiedUserFactory;
|
||||
private final ChangeControl.GenericFactory changeControlFactory;
|
||||
@@ -164,7 +164,7 @@ public class MergeOp {
|
||||
final ProjectCache pc, final FunctionState.Factory fs,
|
||||
final GitReferenceUpdated gru, final MergedSender.Factory msf,
|
||||
final MergeFailSender.Factory mfsf,
|
||||
final ApprovalTypes approvalTypes, final PatchSetInfoFactory psif,
|
||||
final LabelTypes labelTypes, final PatchSetInfoFactory psif,
|
||||
final IdentifiedUser.GenericFactory iuf,
|
||||
final ChangeControl.GenericFactory changeControlFactory,
|
||||
final MergeQueue mergeQueue, @Assisted final Branch.NameKey branch,
|
||||
@@ -182,7 +182,7 @@ public class MergeOp {
|
||||
gitRefUpdated = gru;
|
||||
mergedSenderFactory = msf;
|
||||
mergeFailSenderFactory = mfsf;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.labelTypes = labelTypes;
|
||||
patchSetInfoFactory = psif;
|
||||
identifiedUserFactory = iuf;
|
||||
this.changeControlFactory = changeControlFactory;
|
||||
@@ -936,8 +936,8 @@ public class MergeOp {
|
||||
c,
|
||||
identifiedUserFactory.create(c.getOwner())),
|
||||
merged, approvals);
|
||||
for (ApprovalType at : approvalTypes.getApprovalTypes()) {
|
||||
CategoryFunction.forType(at).run(at, fs);
|
||||
for (LabelType lt : labelTypes.getLabelTypes()) {
|
||||
CategoryFunction.forType(lt).run(lt, fs);
|
||||
}
|
||||
for (PatchSetApproval a : approvals) {
|
||||
if (a.getValue() > 0
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.ApprovalCategory;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
@@ -165,7 +165,7 @@ public class MergeUtil {
|
||||
}
|
||||
|
||||
public static String createCherryPickCommitMessage(final CodeReviewCommit n,
|
||||
final ApprovalTypes approvalTypes, final Provider<String> urlProvider,
|
||||
final LabelTypes labelTypes, final Provider<String> urlProvider,
|
||||
final ReviewDb db, final IdentifiedUser.GenericFactory identifiedUserFactory) {
|
||||
final List<FooterLine> footers = n.getFooterLines();
|
||||
final StringBuilder msgbuf = new StringBuilder();
|
||||
@@ -254,12 +254,12 @@ public class MergeUtil {
|
||||
} else if (VRIF.equals(a.getCategoryId())) {
|
||||
tag = "Tested-by";
|
||||
} else {
|
||||
final ApprovalType at = approvalTypes.byId(a.getCategoryId().get());
|
||||
if (at == null) {
|
||||
final LabelType lt = labelTypes.byId(a.getCategoryId().get());
|
||||
if (lt == null) {
|
||||
// TODO: Support arbitrary labels.
|
||||
continue;
|
||||
}
|
||||
tag = at.getName();
|
||||
tag = lt.getName();
|
||||
}
|
||||
|
||||
if (!contains(footers, new FooterKey(tag), identbuf.toString())) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -51,7 +51,7 @@ class ReviewNoteHeaderFormatter {
|
||||
sb.append("Change-Id: ").append(changeKey.get()).append("\n");
|
||||
}
|
||||
|
||||
void appendApproval(ApprovalType type, short value, Account user) {
|
||||
void appendApproval(LabelType type, short value, Account user) {
|
||||
sb.append(type.getName());
|
||||
sb.append(value < 0 ? "-" : "+").append(Math.abs(value)).append(": ");
|
||||
appendUserData(user);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
@@ -49,7 +49,7 @@ public class SubmitStrategyFactory {
|
||||
private final PersonIdent myIdent;
|
||||
private final PatchSetInfoFactory patchSetInfoFactory;
|
||||
private final Provider<String> urlProvider;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final LabelTypes labelTypes;
|
||||
private final GitReferenceUpdated gitRefUpdated;
|
||||
private final RebaseChange rebaseChange;
|
||||
|
||||
@@ -59,13 +59,13 @@ public class SubmitStrategyFactory {
|
||||
@GerritPersonIdent final PersonIdent myIdent,
|
||||
final PatchSetInfoFactory patchSetInfoFactory,
|
||||
@CanonicalWebUrl @Nullable final Provider<String> urlProvider,
|
||||
final ApprovalTypes approvalTypes, final GitReferenceUpdated gitRefUpdated,
|
||||
final LabelTypes labelTypes, final GitReferenceUpdated gitRefUpdated,
|
||||
final RebaseChange rebaseChange) {
|
||||
this.identifiedUserFactory = identifiedUserFactory;
|
||||
this.myIdent = myIdent;
|
||||
this.patchSetInfoFactory = patchSetInfoFactory;
|
||||
this.urlProvider = urlProvider;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.labelTypes = labelTypes;
|
||||
this.gitRefUpdated = gitRefUpdated;
|
||||
this.rebaseChange = rebaseChange;
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class SubmitStrategyFactory {
|
||||
switch (submitType) {
|
||||
case CHERRY_PICK:
|
||||
return new CherryPick(args, patchSetInfoFactory, urlProvider,
|
||||
approvalTypes, gitRefUpdated);
|
||||
labelTypes, gitRefUpdated);
|
||||
case FAST_FORWARD_ONLY:
|
||||
return new FastForwardOnly(args);
|
||||
case MERGE_ALWAYS:
|
||||
|
||||
@@ -16,8 +16,8 @@ package com.google.gerrit.server.mail;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table;
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.LabelValue;
|
||||
import com.google.gerrit.common.errors.EmailException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -34,12 +34,12 @@ public class MergedSender extends ReplyToChangeSender {
|
||||
public MergedSender create(Change change);
|
||||
}
|
||||
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final LabelTypes labelTypes;
|
||||
|
||||
@Inject
|
||||
public MergedSender(EmailArguments ea, ApprovalTypes at, @Assisted Change c) {
|
||||
public MergedSender(EmailArguments ea, LabelTypes lt, @Assisted Change c) {
|
||||
super(ea, c, "merged");
|
||||
approvalTypes = at;
|
||||
labelTypes = lt;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,7 +63,7 @@ public class MergedSender extends ReplyToChangeSender {
|
||||
Table<Account.Id, String, PatchSetApproval> neg = HashBasedTable.create();
|
||||
for (PatchSetApproval ca : args.db.get().patchSetApprovals()
|
||||
.byPatchSet(patchSet.getId())) {
|
||||
ApprovalType lt = approvalTypes.byId(ca.getCategoryId().get());
|
||||
LabelType lt = labelTypes.byId(ca.getCategoryId().get());
|
||||
if (lt == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class MergedSender extends ReplyToChangeSender {
|
||||
txt.append(getNameFor(id));
|
||||
txt.append(": ");
|
||||
boolean first = true;
|
||||
for (ApprovalType lt : approvalTypes.getApprovalTypes()) {
|
||||
for (LabelType lt : labelTypes.getLabelTypes()) {
|
||||
PatchSetApproval ca = approvals.get(id, lt.getName());
|
||||
if (ca == null) {
|
||||
continue;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package com.google.gerrit.server.query.change;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
@@ -110,7 +110,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
final ChangeControl.GenericFactory changeControlGenericFactory;
|
||||
final AccountResolver accountResolver;
|
||||
final GroupBackend groupBackend;
|
||||
final ApprovalTypes approvalTypes;
|
||||
final LabelTypes labelTypes;
|
||||
final AllProjectsName allProjectsName;
|
||||
final PatchListCache patchListCache;
|
||||
final GitRepositoryManager repoManager;
|
||||
@@ -124,7 +124,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
ChangeControl.GenericFactory changeControlGenericFactory,
|
||||
AccountResolver accountResolver,
|
||||
GroupBackend groupBackend,
|
||||
ApprovalTypes approvalTypes,
|
||||
LabelTypes labelTypes,
|
||||
AllProjectsName allProjectsName,
|
||||
PatchListCache patchListCache,
|
||||
GitRepositoryManager repoManager,
|
||||
@@ -136,7 +136,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
this.changeControlGenericFactory = changeControlGenericFactory;
|
||||
this.accountResolver = accountResolver;
|
||||
this.groupBackend = groupBackend;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.labelTypes = labelTypes;
|
||||
this.allProjectsName = allProjectsName;
|
||||
this.patchListCache = patchListCache;
|
||||
this.repoManager = repoManager;
|
||||
@@ -302,7 +302,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
@Operator
|
||||
public Predicate<ChangeData> label(String name) {
|
||||
return new LabelPredicate(args.changeControlGenericFactory,
|
||||
args.userFactory, args.dbProvider, args.approvalTypes, name);
|
||||
args.userFactory, args.dbProvider, args.labelTypes, name);
|
||||
}
|
||||
|
||||
@Operator
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.query.change;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -57,7 +57,7 @@ class LabelPredicate extends OperatorPredicate<ChangeData> {
|
||||
abstract boolean match(int psValue, int expValue);
|
||||
}
|
||||
|
||||
private static ApprovalType type(ApprovalTypes types, String toFind) {
|
||||
private static LabelType type(LabelTypes types, String toFind) {
|
||||
if (types.byLabel(toFind) != null) {
|
||||
return types.byLabel(toFind);
|
||||
}
|
||||
@@ -66,19 +66,19 @@ class LabelPredicate extends OperatorPredicate<ChangeData> {
|
||||
return types.byId(toFind);
|
||||
}
|
||||
|
||||
for (ApprovalType at : types.getApprovalTypes()) {
|
||||
if (toFind.equalsIgnoreCase(at.getName())) {
|
||||
return at;
|
||||
for (LabelType lt : types.getLabelTypes()) {
|
||||
if (toFind.equalsIgnoreCase(lt.getName())) {
|
||||
return lt;
|
||||
}
|
||||
}
|
||||
|
||||
for (ApprovalType at : types.getApprovalTypes()) {
|
||||
if (toFind.equalsIgnoreCase(at.getAbbreviatedName())) {
|
||||
return at;
|
||||
for (LabelType lt : types.getLabelTypes()) {
|
||||
if (toFind.equalsIgnoreCase(lt.getAbbreviatedName())) {
|
||||
return lt;
|
||||
}
|
||||
}
|
||||
|
||||
return ApprovalType.withDefaultValues(toFind.substring(0, 4), toFind);
|
||||
return LabelType.withDefaultValues(toFind.substring(0, 4), toFind);
|
||||
}
|
||||
|
||||
private static Test op(String op) {
|
||||
@@ -107,13 +107,13 @@ class LabelPredicate extends OperatorPredicate<ChangeData> {
|
||||
private final IdentifiedUser.GenericFactory userFactory;
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final Test test;
|
||||
private final ApprovalType type;
|
||||
private final LabelType type;
|
||||
private final String permissionName;
|
||||
private final int expVal;
|
||||
|
||||
LabelPredicate(ChangeControl.GenericFactory ccFactory,
|
||||
IdentifiedUser.GenericFactory userFactory, Provider<ReviewDb> dbProvider,
|
||||
ApprovalTypes types, String value) {
|
||||
LabelTypes types, String value) {
|
||||
super(ChangeQueryBuilder.FIELD_LABEL, value);
|
||||
this.ccFactory = ccFactory;
|
||||
this.userFactory = userFactory;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.workflow;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.reviewdb.client.ApprovalCategory;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
|
||||
@@ -43,7 +43,7 @@ public abstract class CategoryFunction {
|
||||
* @return the function implementation; {@link NoOpFunction} if the function
|
||||
* is not known to Gerrit and thus cannot be executed.
|
||||
*/
|
||||
public static CategoryFunction forType(ApprovalType type) {
|
||||
public static CategoryFunction forType(LabelType type) {
|
||||
CategoryFunction r = all.get(type.getFunctionName());
|
||||
return r != null ? r : new NoOpFunction();
|
||||
}
|
||||
@@ -85,9 +85,9 @@ public abstract class CategoryFunction {
|
||||
* state.valid(at, !neg && pos);
|
||||
* </pre>
|
||||
*
|
||||
* @param at the cached category description to process.
|
||||
* @param lt the cached category description to process.
|
||||
* @param state state to read approvals and project rights from, and to update
|
||||
* the valid status into.
|
||||
*/
|
||||
public abstract void run(ApprovalType at, FunctionState state);
|
||||
public abstract void run(LabelType lt, FunctionState state);
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.workflow;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.ApprovalTypes;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.LabelValue;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRange;
|
||||
@@ -42,7 +42,7 @@ public class FunctionState {
|
||||
Collection<PatchSetApproval> all);
|
||||
}
|
||||
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final LabelTypes labelTypes;
|
||||
private final IdentifiedUser.GenericFactory userFactory;
|
||||
|
||||
private final Map<String, Collection<PatchSetApproval>> approvals =
|
||||
@@ -52,11 +52,11 @@ public class FunctionState {
|
||||
private final Change change;
|
||||
|
||||
@Inject
|
||||
FunctionState(final ApprovalTypes approvalTypes,
|
||||
FunctionState(final LabelTypes labelTypes,
|
||||
final IdentifiedUser.GenericFactory userFactory,
|
||||
@Assisted final ChangeControl c, @Assisted final PatchSet.Id psId,
|
||||
@Assisted final Collection<PatchSetApproval> all) {
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.labelTypes = labelTypes;
|
||||
this.userFactory = userFactory;
|
||||
|
||||
callerChangeControl = c;
|
||||
@@ -68,10 +68,10 @@ public class FunctionState {
|
||||
approvals.get(ca.getCategoryId().get());
|
||||
if (l == null) {
|
||||
l = new ArrayList<PatchSetApproval>();
|
||||
ApprovalType at = approvalTypes.byId(ca.getCategoryId().get());
|
||||
if (at != null) {
|
||||
LabelType lt = labelTypes.byId(ca.getCategoryId().get());
|
||||
if (lt != null) {
|
||||
// TODO: Support arbitrary labels
|
||||
approvals.put(at.getName(), l);
|
||||
approvals.put(lt.getName(), l);
|
||||
}
|
||||
}
|
||||
l.add(ca);
|
||||
@@ -79,20 +79,20 @@ public class FunctionState {
|
||||
}
|
||||
}
|
||||
|
||||
List<ApprovalType> getApprovalTypes() {
|
||||
return approvalTypes.getApprovalTypes();
|
||||
List<LabelType> getLabelTypes() {
|
||||
return labelTypes.getLabelTypes();
|
||||
}
|
||||
|
||||
Change getChange() {
|
||||
return change;
|
||||
}
|
||||
|
||||
public void valid(final ApprovalType at, final boolean v) {
|
||||
valid.put(id(at), v);
|
||||
public void valid(final LabelType lt, final boolean v) {
|
||||
valid.put(id(lt), v);
|
||||
}
|
||||
|
||||
public boolean isValid(final ApprovalType at) {
|
||||
return isValid(at.getName());
|
||||
public boolean isValid(final LabelType lt) {
|
||||
return isValid(lt.getName());
|
||||
}
|
||||
|
||||
public boolean isValid(final String labelName) {
|
||||
@@ -100,8 +100,8 @@ public class FunctionState {
|
||||
return b != null && b;
|
||||
}
|
||||
|
||||
public Collection<PatchSetApproval> getApprovals(final ApprovalType at) {
|
||||
return getApprovals(at.getName());
|
||||
public Collection<PatchSetApproval> getApprovals(final LabelType lt) {
|
||||
return getApprovals(lt.getName());
|
||||
}
|
||||
|
||||
public Collection<PatchSetApproval> getApprovals(final String labelName) {
|
||||
@@ -114,14 +114,14 @@ public class FunctionState {
|
||||
* case the type was modified since the approval was originally granted.
|
||||
* <p>
|
||||
*/
|
||||
private void applyTypeFloor(final ApprovalType at, final PatchSetApproval a) {
|
||||
final LabelValue atMin = at.getMin();
|
||||
private void applyTypeFloor(final LabelType lt, final PatchSetApproval a) {
|
||||
final LabelValue atMin = lt.getMin();
|
||||
|
||||
if (atMin != null && a.getValue() < atMin.getValue()) {
|
||||
a.setValue(atMin.getValue());
|
||||
}
|
||||
|
||||
final LabelValue atMax = at.getMax();
|
||||
final LabelValue atMax = lt.getMax();
|
||||
if (atMax != null && a.getValue() > atMax.getValue()) {
|
||||
a.setValue(atMax.getValue());
|
||||
}
|
||||
@@ -136,8 +136,8 @@ public class FunctionState {
|
||||
* of them is used.
|
||||
* <p>
|
||||
*/
|
||||
private void applyRightFloor(final ApprovalType at, final PatchSetApproval a) {
|
||||
final String permission = Permission.forLabel(at.getName());
|
||||
private void applyRightFloor(final LabelType lt, final PatchSetApproval a) {
|
||||
final String permission = Permission.forLabel(lt.getName());
|
||||
final IdentifiedUser user = userFactory.create(a.getAccountId());
|
||||
final PermissionRange range = controlFor(user).getRange(permission);
|
||||
a.setValue((short) range.squash(a.getValue()));
|
||||
@@ -148,12 +148,12 @@ public class FunctionState {
|
||||
}
|
||||
|
||||
/** Run <code>applyTypeFloor</code>, <code>applyRightFloor</code>. */
|
||||
public void normalize(final ApprovalType at, final PatchSetApproval ca) {
|
||||
applyTypeFloor(at, ca);
|
||||
applyRightFloor(at, ca);
|
||||
public void normalize(final LabelType lt, final PatchSetApproval ca) {
|
||||
applyTypeFloor(lt, ca);
|
||||
applyRightFloor(lt, ca);
|
||||
}
|
||||
|
||||
private static String id(final ApprovalType at) {
|
||||
return at.getId();
|
||||
private static String id(final LabelType lt) {
|
||||
return lt.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.workflow;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.reviewdb.client.ApprovalCategory;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
|
||||
@@ -33,16 +33,16 @@ public class MaxNoBlock extends CategoryFunction {
|
||||
public static String NAME = "MaxNoBlock";
|
||||
|
||||
@Override
|
||||
public void run(final ApprovalType at, final FunctionState state) {
|
||||
public void run(final LabelType lt, final FunctionState state) {
|
||||
boolean passed = false;
|
||||
for (final PatchSetApproval a : state.getApprovals(at)) {
|
||||
state.normalize(at, a);
|
||||
for (final PatchSetApproval a : state.getApprovals(lt)) {
|
||||
state.normalize(lt, a);
|
||||
|
||||
passed |= at.isMaxPositive(a);
|
||||
passed |= lt.isMaxPositive(a);
|
||||
}
|
||||
|
||||
// The type must have at least one max positive (a full accept).
|
||||
//
|
||||
state.valid(at, passed);
|
||||
state.valid(lt, passed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.workflow;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.reviewdb.client.ApprovalCategory;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
|
||||
@@ -45,19 +45,19 @@ public class MaxWithBlock extends CategoryFunction {
|
||||
public static String NAME = "MaxWithBlock";
|
||||
|
||||
@Override
|
||||
public void run(final ApprovalType at, final FunctionState state) {
|
||||
public void run(final LabelType lt, final FunctionState state) {
|
||||
boolean rejected = false;
|
||||
boolean passed = false;
|
||||
for (final PatchSetApproval a : state.getApprovals(at)) {
|
||||
state.normalize(at, a);
|
||||
for (final PatchSetApproval a : state.getApprovals(lt)) {
|
||||
state.normalize(lt, a);
|
||||
|
||||
rejected |= at.isMaxNegative(a);
|
||||
passed |= at.isMaxPositive(a);
|
||||
rejected |= lt.isMaxNegative(a);
|
||||
passed |= lt.isMaxPositive(a);
|
||||
}
|
||||
|
||||
// The type must not have had its max negative (a forceful reject)
|
||||
// and must have at least one max positive (a full accept).
|
||||
//
|
||||
state.valid(at, !rejected && passed);
|
||||
state.valid(lt, !rejected && passed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
|
||||
package com.google.gerrit.server.workflow;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
|
||||
/** A function that does nothing. */
|
||||
public class NoBlock extends CategoryFunction {
|
||||
public static String NAME = "NoBlock";
|
||||
|
||||
@Override
|
||||
public void run(final ApprovalType at, final FunctionState state) {
|
||||
state.valid(at, true);
|
||||
public void run(final LabelType lt, final FunctionState state) {
|
||||
state.valid(lt, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
|
||||
package com.google.gerrit.server.workflow;
|
||||
|
||||
import com.google.gerrit.common.data.ApprovalType;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
|
||||
/** A function that does nothing. */
|
||||
public class NoOpFunction extends CategoryFunction {
|
||||
public static String NAME = "NoOp";
|
||||
|
||||
@Override
|
||||
public void run(final ApprovalType at, final FunctionState state) {
|
||||
public void run(final LabelType lt, final FunctionState state) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user