Use Prolog Cafe for ChangeControl.canSubmit()

Re-implement the canSubmit() logic in Prolog, removing one of the
last uses of FunctionState.  This is a simple re-implementation
that does not provide any new functionality.

PatchSetApproval objects are exposed into Prolog on demand by
loading them from the database if the submit predicate needs
them. These get indexed in a temporary HashMap by their label name
(aka ApprovalCategory), making access faster during evaluation of
the rule.

ApprovalTypes are loaded into Prolog on demand from the Guice
Injector.  This will eventually go away when we get rid of the
global declaration of ApprovalCategories in the web UI.

CurrentUser instances are loaded and cached within the Prolog
environment as needed to consider PatchSetApproval objects and if
the user has the necessary permission to make that assertion.

Bug: 971
Change-Id: I7e261948db08b7c3180e590e81f492ff3e6f237e
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2011-06-06 13:49:06 -07:00
parent 7b8c92b5a5
commit 9f2535231b
20 changed files with 1376 additions and 34 deletions

View File

@@ -20,6 +20,7 @@ import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.reviewdb.AccountGroup;
import com.google.gerrit.reviewdb.Project;
import com.google.gerrit.rules.PrologEnvironment;
import com.google.gerrit.server.AnonymousUser;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.config.WildProjectName;
@@ -49,6 +50,7 @@ public class ProjectState {
private final Project.NameKey wildProject;
private final ProjectCache projectCache;
private final ProjectControl.AssistedFactory projectControlFactory;
private final PrologEnvironment.Factory envFactory;
private final GitRepositoryManager gitMgr;
private final ProjectConfig config;
@@ -62,12 +64,14 @@ public class ProjectState {
final ProjectCache projectCache,
@WildProjectName final Project.NameKey wildProject,
final ProjectControl.AssistedFactory projectControlFactory,
final PrologEnvironment.Factory envFactory,
final GitRepositoryManager gitMgr,
@Assisted final ProjectConfig config) {
this.anonymousUser = anonymousUser;
this.projectCache = projectCache;
this.wildProject = wildProject;
this.projectControlFactory = projectControlFactory;
this.envFactory = envFactory;
this.gitMgr = gitMgr;
this.config = config;
this.lastCheckTime = System.currentTimeMillis();
@@ -116,6 +120,12 @@ public class ProjectState {
}
}
/** @return Construct a new PrologEnvironment for the calling thread. */
public PrologEnvironment newPrologEnvironment() {
// TODO Replace this with a per-project ClassLoader to isolate rules.
return envFactory.create(getClass().getClassLoader());
}
public Project getProject() {
return getConfig().getProject();
}