Search in sources :

Example 1 with EvaluationException

use of com.googlecode.prolog_cafe.exceptions.EvaluationException in project gerrit by GerritCodeReview.

the class PRED_current_user_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    CurrentUser curUser = StoredValues.CURRENT_USER.getOrNull(engine);
    if (curUser == null) {
        throw new EvaluationException("Current user not available in this rule type");
    }
    Term resultTerm;
    if (curUser.isIdentifiedUser()) {
        Account.Id id = curUser.getAccountId();
        resultTerm = new IntegerTerm(id.get());
    } else if (curUser instanceof AnonymousUser) {
        resultTerm = anonymous;
    } else if (curUser instanceof PeerDaemonUser) {
        resultTerm = peerDaemon;
    } else {
        throw new EvaluationException("Unknown user type");
    }
    if (!a1.unify(new StructureTerm(user, resultTerm), engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) CurrentUser(com.google.gerrit.server.CurrentUser) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) AnonymousUser(com.google.gerrit.server.AnonymousUser) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) EvaluationException(com.googlecode.prolog_cafe.exceptions.EvaluationException) PeerDaemonUser(com.google.gerrit.server.PeerDaemonUser)

Aggregations

Account (com.google.gerrit.reviewdb.client.Account)1 AnonymousUser (com.google.gerrit.server.AnonymousUser)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 PeerDaemonUser (com.google.gerrit.server.PeerDaemonUser)1 EvaluationException (com.googlecode.prolog_cafe.exceptions.EvaluationException)1 IntegerTerm (com.googlecode.prolog_cafe.lang.IntegerTerm)1 StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)1 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)1 Term (com.googlecode.prolog_cafe.lang.Term)1