Remove most remaining references to ApprovalCategory(Value)

These classes should only be used in code directly interfacing with
the ReviewDb layer. For things like map keys, use label names or IDs
as appropriate (and document it to avoid confusion).

Change-Id: I1471725220eda63b4668d5c623ff7b984fd0a46b
This commit is contained in:
Dave Borowitz
2013-02-18 16:14:52 -08:00
parent 95ea146fc9
commit b323e616bd
12 changed files with 80 additions and 92 deletions

View File

@@ -17,35 +17,30 @@ package com.google.gerrit.client;
import com.google.gwt.resources.client.CssResource;
public interface GerritCss extends CssResource {
String greenCheckClass();
String accountContactOnFile();
String accountContactPrivacyDetails();
String accountDashboard();
String accountInfoBlock();
String accountName();
String accountUsername();
String accountPassword();
String accountUsername();
String activeRow();
String fileCommentBorder();
String addBranch();
String addMemberTextBox();
String addReviewer();
String removeReviewer();
String removeReviewerCell();
String addBranch();
String addSshKeyPanel();
String addWatchPanel();
String approvalCategoryList();
String approvalTable();
String approvalhint();
String approvalrole();
String approvalscore();
String notVotable();
String blockHeader();
String bottomheader();
String cAPPROVAL();
String cLastUpdate();
String cSUBJECT();
String cOWNER();
String cSUBJECT();
String cellsNextToFileComment();
String changeComments();
String changeInfoBlock();
String changeInfoTopicPanel();
@@ -57,25 +52,24 @@ public interface GerritCss extends CssResource {
String changeTypeCell();
String changeid();
String closedstate();
String cellsNextToFileComment();
String commentedActionDialog();
String commentedActionMessage();
String commentCell();
String commentEditorPanel();
String commentHolder();
String commentHolderLeftmost();
String commentPanel();
String commentPanelBorder();
String commentPanelAuthorCell();
String commentPanelBorder();
String commentPanelButtons();
String commentPanelContent();
String commentPanelDateCell();
String commentPanelHeader();
String commentPanelLast();
String commentPanelMessage();
String commentPanelMenuBar();
String commentPanelMessage();
String commentPanelSummary();
String commentPanelSummaryCell();
String commentedActionDialog();
String commentedActionMessage();
String complexHeader();
String content();
String contributorAgreementAlreadySubmitted();
@@ -89,29 +83,30 @@ public interface GerritCss extends CssResource {
String dataHeader();
String diffLinkCell();
String diffText();
String diffTextForBinaryInSideBySide();
String diffTextCONTEXT();
String diffTextDELETE();
String diffTextFileHeader();
String diffTextForBinaryInSideBySide();
String diffTextHunkHeader();
String diffTextINSERT();
String diffTextNoLF();
String downloadLink();
String downloadLink_Active();
String downloadLinkListCell();
String downloadLinkCopyLabel();
String downloadLinkHeader();
String downloadLinkHeaderGap();
String downloadLinkList();
String downloadLinkListCell();
String downloadLink_Active();
String drafts();
String emptySection();
String errorDialog();
String errorDialogGlass();
String errorDialogTitle();
String errorDialogButtons();
String errorDialogErrorType();
String errorDialogGlass();
String errorDialogText();
String errorDialogTitle();
String fileColumnHeader();
String fileCommentBorder();
String fileLine();
String fileLineCONTEXT();
String fileLineDELETE();
@@ -119,8 +114,9 @@ public interface GerritCss extends CssResource {
String fileLineMode();
String fileLineNone();
String filePathCell();
String gerritTopMenu();
String gerritBody();
String gerritTopMenu();
String greenCheckClass();
String groupDescriptionPanel();
String groupExternalNameFilterTextBox();
String groupIncludesTable();
@@ -143,6 +139,7 @@ public interface GerritCss extends CssResource {
String infoTable();
String inputFieldTypeHint();
String keyhelp();
String labelList();
String leftMostCell();
String lineHeader();
String lineNumber();
@@ -162,17 +159,18 @@ public interface GerritCss extends CssResource {
String negscore();
String noLineLineNumber();
String noborder();
String notVotable();
String outdated();
String parentsTable();
String patchBrowserPopup();
String patchBrowserPopupBody();
String patchCellReverseDiff();
String patchComments();
String patchContentTable();
String patchHistoryTable();
String patchHistoryTablePatchSetHeader();
String patchNoDifference();
String patchScreenDisplayControls();
String reviewedPanelBottom();
String patchSetActions();
String patchSetInfoBlock();
String patchSetLink();
@@ -181,15 +179,19 @@ public interface GerritCss extends CssResource {
String patchSizeCell();
String pluginsTable();
String posscore();
String projectAdminApprovalCategoryRangeLine();
String projectAdminApprovalCategoryValue();
String projectAdminLabelRangeLine();
String projectAdminLabelValue();
String projectFilterLabel();
String projectFilterPanel();
String publishCommentsScreen();
String registerScreenExplain();
String registerScreenNextLinks();
String registerScreenSection();
String rightmost();
String removeReviewer();
String removeReviewerCell();
String reviewedPanelBottom();
String rightBorder();
String sideBySideTableBinaryHeader();
String rightmost();
String rpcStatus();
String rpcStatusLoading();
String rpcStatusPanel();
@@ -198,10 +200,10 @@ public interface GerritCss extends CssResource {
String screenNoHeader();
String searchPanel();
String sectionHeader();
String selectPatchSetOldVersion();
String sideBySideScreenLinkTable();
String sideBySideScreenSideBySideTable();
String unifiedTable();
String unifiedTableHeader();
String sideBySideTableBinaryHeader();
String singleLine();
String skipLine();
String smallHeading();
@@ -214,20 +216,18 @@ public interface GerritCss extends CssResource {
String sshHostKeyPanelKnownHostEntry();
String sshKeyPanelEncodedKey();
String sshKeyPanelInvalid();
String topMostCell();
String topmenu();
String topmenuMenuLeft();
String topmenuMenuRight();
String topmenuTDglue();
String topmenuTDmenu();
String topmost();
String topMostCell();
String useridentity();
String unifiedTable();
String unifiedTableHeader();
String userInfoPopup();
String useridentity();
String usernameField();
String version();
String watchedProjectFilter();
String selectPatchSetOldVersion();
String patchCellReverseDiff();
String projectFilterPanel();
String projectFilterLabel();
}

View File

@@ -263,7 +263,7 @@ public class PublishCommentScreen extends AccountScreen implements
body.add(new SmallHeading(label.name() + ":"));
VerticalPanel vp = new VerticalPanel();
vp.setStyleName(Gerrit.RESOURCES.css().approvalCategoryList());
vp.setStyleName(Gerrit.RESOURCES.css().labelList());
Short prior = null;
if (label.all() != null) {

View File

@@ -1344,10 +1344,10 @@ a:hover.downloadLink {
width: 45em;
}
.projectAdminApprovalCategoryRangeLine {
.projectAdminLabelRangeLine {
white-space: nowrap;
}
.projectAdminApprovalCategoryValue {
.projectAdminLabelValue {
font-family: mono-font;
font-size: small;
}
@@ -1359,7 +1359,7 @@ a:hover.downloadLink {
font-weight: bold;
white-space: nowrap;
}
.publishCommentsScreen .approvalCategoryList {
.publishCommentsScreen .labelList {
margin-bottom: 10px;
margin-left: 10px;
background: trimColor;
@@ -1375,7 +1375,7 @@ a:hover.downloadLink {
.publishCommentsScreen .coverMessage textarea {
font-size: small;
}
.publishCommentsScreen .approvalCategoryList .gwt-RadioButton {
.publishCommentsScreen .labelList .gwt-RadioButton {
font-size: smaller;
}
.publishCommentsScreen .patchComments {

View File

@@ -21,8 +21,11 @@ import com.google.gwtorm.client.StringKey;
/** Types of approvals that can be associated with a {@link Change}. */
public final class ApprovalCategory {
/** Id of the special "Submit" action (and category). */
public static final ApprovalCategory.Id SUBMIT =
new ApprovalCategory.Id("SUBM");
public static final String SUBMIT_ID = "SUBM";
public static boolean isSubmit(PatchSetApproval a) {
return SUBMIT_ID.equals(a.getCategoryId().get());
}
public static class Id extends StringKey<Key<?>> {
private static final long serialVersionUID = 1L;

View File

@@ -14,15 +14,13 @@
package com.google.gerrit.common;
import com.google.gerrit.common.data.ContributorAgreement;
import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.common.data.LabelTypes;
import com.google.gerrit.common.data.ContributorAgreement;
import com.google.gerrit.extensions.events.LifecycleListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.ApprovalCategory;
import com.google.gerrit.reviewdb.client.ApprovalCategoryValue;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
@@ -385,8 +383,8 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
}
public void doCommentAddedHook(final Change change, final Account account,
final PatchSet patchSet, final String comment, final Map<ApprovalCategory.Id,
ApprovalCategoryValue.Id> approvals, final ReviewDb db) throws OrmException {
final PatchSet patchSet, final String comment, final Map<String, Short> approvals,
final ReviewDb db) throws OrmException {
final CommentAddedEvent event = new CommentAddedEvent();
event.change = eventFactory.asChangeAttribute(change);
@@ -398,7 +396,7 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
if (approvals.size() > 0) {
event.approvals = new ApprovalAttribute[approvals.size()];
int i = 0;
for (Map.Entry<ApprovalCategory.Id, ApprovalCategoryValue.Id> approval : approvals.entrySet()) {
for (Map.Entry<String, Short> approval : approvals.entrySet()) {
event.approvals[i++] = getApprovalAttribute(labelTypes, approval);
}
}
@@ -415,8 +413,11 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
addArg(args, "--author", getDisplayName(account));
addArg(args, "--commit", event.patchSet.revision);
addArg(args, "--comment", comment == null ? "" : comment);
for (Map.Entry<ApprovalCategory.Id, ApprovalCategoryValue.Id> approval : approvals.entrySet()) {
addArg(args, "--" + approval.getKey().get(), Short.toString(approval.getValue().get()));
for (Map.Entry<String, Short> approval : approvals.entrySet()) {
LabelType lt = labelTypes.byLabel(approval.getKey());
if (lt != null) {
addArg(args, "--" + lt.getId(), Short.toString(approval.getValue()));
}
}
runHook(change.getProject(), commentAddedHook, args);
@@ -614,14 +615,14 @@ public class ChangeHookRunner implements ChangeHooks, LifecycleListener {
* @return object suitable for serialization to JSON
*/
private ApprovalAttribute getApprovalAttribute(LabelTypes labelTypes,
Entry<ApprovalCategory.Id, ApprovalCategoryValue.Id> approval) {
Entry<String, Short> approval) {
ApprovalAttribute a = new ApprovalAttribute();
a.type = approval.getKey().get();
LabelType lt = labelTypes.byId(approval.getKey().get());
a.type = approval.getKey();
LabelType lt = labelTypes.byLabel(approval.getKey());
if (lt != null) {
a.description = lt.getName();
}
a.value = Short.toString(approval.getValue().get());
a.value = Short.toString(approval.getValue());
return a;
}

View File

@@ -17,13 +17,11 @@ package com.google.gerrit.common;
import com.google.gerrit.common.ChangeHookRunner.HookResult;
import com.google.gerrit.common.data.ContributorAgreement;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.ApprovalCategory;
import com.google.gerrit.reviewdb.client.ApprovalCategoryValue;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gwtorm.server.OrmException;
@@ -65,12 +63,12 @@ public interface ChangeHooks {
* @param patchSet The patchset this comment is related to.
* @param account The gerrit user who added the comment.
* @param comment The comment given.
* @param approvals Map of Approval Categories and Scores
* @param approvals Map of label IDs to scores
* @throws OrmException
*/
public void doCommentAddedHook(Change change, Account account,
PatchSet patchSet, String comment,
Map<ApprovalCategory.Id, ApprovalCategoryValue.Id> approvals, ReviewDb db)
Map<String, Short> approvals, ReviewDb db)
throws OrmException;
/**

View File

@@ -17,11 +17,9 @@ package com.google.gerrit.common;
import com.google.gerrit.common.ChangeHookRunner.HookResult;
import com.google.gerrit.common.data.ContributorAgreement;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.ApprovalCategory;
import com.google.gerrit.reviewdb.client.ApprovalCategoryValue;
import com.google.gerrit.reviewdb.client.Branch.NameKey;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Branch.NameKey;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
@@ -64,7 +62,7 @@ public final class DisabledChangeHooks implements ChangeHooks {
@Override
public void doCommentAddedHook(Change change, Account account,
PatchSet patchSet, String comment,
Map<ApprovalCategory.Id, ApprovalCategoryValue.Id> approvals, ReviewDb db) {
Map<String, Short> approvals, ReviewDb db) {
}
@Override

View File

@@ -86,15 +86,12 @@ public class ApprovalsUtil {
List<PatchSetApproval> patchSetApprovals =
db.patchSetApprovals().byChange(dest.getParentKey()).toList();
for (PatchSetApproval a : patchSetApprovals) {
// ApprovalCategory.SUBMIT is still in db but not relevant in git-store
if (!ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
final LabelType type = labelTypes.byId(a.getCategoryId().get());
if (a.getPatchSetId().equals(source) &&
type.isCopyMinScore() &&
type.isMaxNegative(a)) {
db.patchSetApprovals().insert(
Collections.singleton(new PatchSetApproval(dest, a)));
}
LabelType type = labelTypes.byId(a.getCategoryId().get());
if (type != null && a.getPatchSetId().equals(source) &&
type.isCopyMinScore() &&
type.isMaxNegative(a)) {
db.patchSetApprovals().insert(
Collections.singleton(new PatchSetApproval(dest, a)));
}
}
return patchSetApprovals;

View File

@@ -29,7 +29,6 @@ import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.restapi.Url;
import com.google.gerrit.reviewdb.client.ApprovalCategory;
import com.google.gerrit.reviewdb.client.ApprovalCategoryValue;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.Patch;
@@ -110,8 +109,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
private Timestamp timestamp;
private List<PatchLineComment> comments = Lists.newArrayList();
private List<String> labelDelta = Lists.newArrayList();
@Deprecated private Map<ApprovalCategory.Id, ApprovalCategoryValue.Id> categories
= Maps.newHashMap();
private Map<String, Short> categories = Maps.newHashMap();
@Inject
PostReview(ReviewDb db,
@@ -366,9 +364,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
c.cache(change);
upd.add(c);
labelDelta.add(format(name, c.getValue()));
categories.put(
lt.getApprovalCategoryId(),
lt.getApprovalCategoryValueId(c.getValue()));
categories.put(name, c.getValue());
} else if (c != null && c.getValue() == ent.getValue()) {
current.put(name, c);
} else if (c == null) {
@@ -381,9 +377,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
c.cache(change);
ins.add(c);
labelDelta.add(format(name, c.getValue()));
categories.put(
lt.getApprovalCategoryId(),
lt.getApprovalCategoryValueId(c.getValue()));
categories.put(name, c.getValue());
}
}
@@ -430,7 +424,7 @@ public class PostReview implements RestModifyView<RevisionResource, Input> {
Map<String, PatchSetApproval> current = Maps.newHashMap();
for (PatchSetApproval a : db.patchSetApprovals().byPatchSetUser(
rsrc.getPatchSet().getId(), rsrc.getAccountId())) {
if (ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
if (ApprovalCategory.SUBMIT_ID.equals(a.getCategoryId().get())) {
continue;
}

View File

@@ -187,7 +187,7 @@ public class Submit implements RestModifyView<RevisionResource, Input> {
new Predicate<PatchSetApproval>() {
@Override
public boolean apply(PatchSetApproval input) {
return ApprovalCategory.SUBMIT.equals(input.getCategoryId());
return ApprovalCategory.SUBMIT_ID.equals(input.getCategoryId().get());
}
}), null);
if (submit == null) {
@@ -195,7 +195,7 @@ public class Submit implements RestModifyView<RevisionResource, Input> {
new PatchSetApproval.Key(
rev.getId(),
caller.getAccountId(),
ApprovalCategory.SUBMIT),
new ApprovalCategory.Id(ApprovalCategory.SUBMIT_ID)),
(short) 1);
}
submit.setValue((short) 1);

View File

@@ -939,7 +939,7 @@ public class MergeOp {
}
for (PatchSetApproval a : approvals) {
if (a.getValue() > 0
&& ApprovalCategory.SUBMIT.equals(a.getCategoryId())
&& ApprovalCategory.SUBMIT_ID.equals(a.getCategoryId().get())
&& a.getPatchSetId().equals(merged)) {
if (submitter == null
|| a.getGranted().compareTo(submitter.getGranted()) > 0) {

View File

@@ -82,10 +82,8 @@ public class MergeUtil {
private static final String R_HEADS_MASTER =
Constants.R_HEADS + Constants.MASTER;
private static final ApprovalCategory.Id CRVW = //
new ApprovalCategory.Id("CRVW");
private static final ApprovalCategory.Id VRIF = //
new ApprovalCategory.Id("VRIF");
private static final String CRVW = "CRVW";
private static final String VRIF = "VRIF";
private static final FooterKey REVIEWED_ON = new FooterKey("Reviewed-on");
private static final FooterKey CHANGE_ID = new FooterKey("Change-Id");
@@ -173,8 +171,7 @@ public class MergeUtil {
final List<PatchSetApproval> approvals =
reviewDb.patchSetApprovals().byPatchSet(c).toList();
for (PatchSetApproval a : approvals) {
if (a.getValue() > 0
&& ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
if (a.getValue() > 0 && ApprovalCategory.isSubmit(a)) {
if (submitter == null
|| a.getGranted().compareTo(submitter.getGranted()) > 0) {
submitter = a;
@@ -260,7 +257,7 @@ public class MergeUtil {
continue;
}
if (ApprovalCategory.SUBMIT.equals(a.getCategoryId())) {
if (ApprovalCategory.isSubmit(a)) {
// Submit is treated specially, below (becomes committer)
//
if (submitAudit == null
@@ -297,9 +294,9 @@ public class MergeUtil {
}
final String tag;
if (CRVW.equals(a.getCategoryId())) {
if (CRVW.equals(a.getCategoryId().get())) {
tag = "Reviewed-by";
} else if (VRIF.equals(a.getCategoryId())) {
} else if (VRIF.equals(a.getCategoryId().get())) {
tag = "Tested-by";
} else {
final LabelType lt =