Make SubmitRecord.Label's fields @Columns
We want to serialize these label values into the secondary index so we can avoid database lookups and submit rule evaluation when rendering change tables. The easiest way to do this is to use Gerrit's protobuf support to convert them to protos to store in the index. This is built around @Column annotations, so use that. Move to the reviewdb package to pick up the necessary gwtorm dependency. Change-Id: I02b4a14404a8d8d72452fea68f0c25f3cbb377f8
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
// Copyright (C) 2011 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.reviewdb.client;
|
||||
|
||||
import com.google.gwtorm.client.Column;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Describes the state required to submit a change.
|
||||
*/
|
||||
public class SubmitRecord {
|
||||
public static enum Status {
|
||||
/** The change is ready for submission. */
|
||||
OK,
|
||||
|
||||
/** The change is missing a required label. */
|
||||
NOT_READY,
|
||||
|
||||
/** The change has been closed. */
|
||||
CLOSED,
|
||||
|
||||
/**
|
||||
* An internal server error occurred preventing computation.
|
||||
* <p>
|
||||
* Additional detail may be available in {@link SubmitRecord#errorMessage}.
|
||||
*/
|
||||
RULE_ERROR;
|
||||
}
|
||||
|
||||
public Status status;
|
||||
public List<Label> labels;
|
||||
public String errorMessage;
|
||||
|
||||
public static class Label {
|
||||
public static enum Status {
|
||||
// NOTE: These enum values are stored in the secondary index; reordering
|
||||
// or removing values requires incrementing the index schema version.
|
||||
|
||||
/**
|
||||
* This label provides what is necessary for submission.
|
||||
* <p>
|
||||
* If provided, {@link Label#appliedBy} describes the user account
|
||||
* that applied this label to the change.
|
||||
*/
|
||||
OK,
|
||||
|
||||
/**
|
||||
* This label prevents the change from being submitted.
|
||||
* <p>
|
||||
* If provided, {@link Label#appliedBy} describes the user account
|
||||
* that applied this label to the change.
|
||||
*/
|
||||
REJECT,
|
||||
|
||||
/**
|
||||
* The label is required for submission, but has not been satisfied.
|
||||
*/
|
||||
NEED,
|
||||
|
||||
/**
|
||||
* The label may be set, but it's neither necessary for submission
|
||||
* nor does it block submission if set.
|
||||
*/
|
||||
MAY,
|
||||
|
||||
/**
|
||||
* The label is required for submission, but is impossible to complete.
|
||||
* The likely cause is access has not been granted correctly by the
|
||||
* project owner or site administrator.
|
||||
*/
|
||||
IMPOSSIBLE;
|
||||
}
|
||||
|
||||
@Column(id = 1)
|
||||
public String label;
|
||||
|
||||
@Column(id = 2)
|
||||
public Status status;
|
||||
|
||||
@Column(id = 3)
|
||||
public Account.Id appliedBy;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(label).append(": ").append(status);
|
||||
if (appliedBy != null) {
|
||||
sb.append(" by ").append(appliedBy);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(status);
|
||||
if (status == Status.RULE_ERROR && errorMessage != null) {
|
||||
sb.append('(').append(errorMessage).append(')');
|
||||
}
|
||||
sb.append('[');
|
||||
if (labels != null) {
|
||||
String delimiter = "";
|
||||
for (Label label : labels) {
|
||||
sb.append(delimiter).append(label);
|
||||
delimiter = ", ";
|
||||
}
|
||||
}
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user