Move workflow function access to CategoryFunction class

This permits us to later move the workflow code into the server side,
moving it off the client.  We're not likely to ever support running
the project's workflow rules on the client in JavaScript.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-07-27 15:35:55 -07:00
parent 96954f8f08
commit 379c2ed026
5 changed files with 22 additions and 14 deletions

View File

@@ -25,6 +25,7 @@ import com.google.gerrit.client.reviewdb.PatchSetAncestor;
import com.google.gerrit.client.reviewdb.RevId;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.workflow.CategoryFunction;
import com.google.gerrit.client.workflow.FunctionState;
import com.google.gwtorm.client.OrmException;
@@ -82,13 +83,13 @@ public class ChangeDetail {
missingApprovals = new HashSet<ApprovalCategory.Id>();
currentActions = new HashSet<ApprovalCategory.Id>();
for (final ApprovalType at : Common.getGerritConfig().getApprovalTypes()) {
at.getCategory().getFunction().run(at, fs);
CategoryFunction.forCategory(at.getCategory()).run(at, fs);
if (!fs.isValid(at)) {
missingApprovals.add(at.getCategory().getId());
}
}
for (final ApprovalType at : Common.getGerritConfig().getActionTypes()) {
if (at.getCategory().getFunction().isValid(me, at, fs)) {
if (CategoryFunction.forCategory(at.getCategory()).isValid(me, at, fs)) {
currentActions.add(at.getCategory().getId());
}
}

View File

@@ -14,9 +14,6 @@
package com.google.gerrit.client.reviewdb;
import com.google.gerrit.client.workflow.CategoryFunction;
import com.google.gerrit.client.workflow.MaxWithBlock;
import com.google.gerrit.client.workflow.NoOpFunction;
import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.Key;
import com.google.gwtorm.client.StringKey;
@@ -112,7 +109,7 @@ public final class ApprovalCategory {
public ApprovalCategory(final ApprovalCategory.Id id, final String name) {
this.categoryId = id;
this.name = name;
this.functionName = MaxWithBlock.NAME;
this.functionName = "MaxWithBlock";
}
public ApprovalCategory.Id getId() {
@@ -146,9 +143,4 @@ public final class ApprovalCategory {
public void setFunctionName(final String name) {
functionName = name;
}
public CategoryFunction getFunction() {
final CategoryFunction r = CategoryFunction.forName(functionName);
return r != null ? r : new NoOpFunction();
}
}

View File

@@ -33,6 +33,18 @@ public abstract class CategoryFunction {
all.put(NoOpFunction.NAME, new NoOpFunction());
}
/**
* Locate a function by category.
*
* @param category the category the function is for.
* @return the function implementation; {@link NoOpFunction} if the function
* is not known to Gerrit and thus cannot be executed.
*/
public static CategoryFunction forCategory(final ApprovalCategory category) {
final CategoryFunction r = forName(category.getFunctionName());
return r != null ? r : new NoOpFunction();
}
/**
* Locate a function by name.
*

View File

@@ -26,6 +26,7 @@ import com.google.gerrit.client.reviewdb.PatchSet;
import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.workflow.CategoryFunction;
import com.google.gerrit.client.workflow.FunctionState;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.GerritServer;
@@ -879,7 +880,7 @@ public class MergeOp {
schema.changeApprovals().byChange(c.getId()).toList();
final FunctionState fs = new FunctionState(c, approvals);
for (ApprovalType at : Common.getGerritConfig().getApprovalTypes()) {
at.getCategory().getFunction().run(at, fs);
CategoryFunction.forCategory(at.getCategory()).run(at, fs);
}
for (ChangeApproval a : approvals) {
if (a.getValue() > 0

View File

@@ -25,6 +25,7 @@ import com.google.gerrit.client.reviewdb.PatchSet;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.rpc.NoSuchEntityException;
import com.google.gerrit.client.workflow.CategoryFunction;
import com.google.gerrit.client.workflow.FunctionState;
import com.google.gerrit.git.MergeQueue;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -90,9 +91,10 @@ public class ChangeManageServiceImpl extends BaseServiceImplementation
final FunctionState fs = new FunctionState(change, allApprovals);
for (ApprovalType c : Common.getGerritConfig().getApprovalTypes()) {
c.getCategory().getFunction().run(c, fs);
CategoryFunction.forCategory(c.getCategory()).run(c, fs);
}
if (!actionType.getCategory().getFunction().isValid(me, actionType, fs)) {
if (!CategoryFunction.forCategory(actionType.getCategory()).isValid(me,
actionType, fs)) {
throw new Failure(new IllegalStateException(actionType.getCategory()
.getName()
+ " not permitted"));