Search in sources :

Example 1 with PrologEnvironment

use of com.google.gerrit.server.rules.PrologEnvironment in project gerrit by GerritCodeReview.

the class AbstractCommitUserIdentityPredicate method exec.

protected Operation exec(Prolog engine, PersonIdent userId) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    Term a2 = arg2.dereference();
    Term a3 = arg3.dereference();
    Term idTerm;
    Term nameTerm = Prolog.Nil;
    Term emailTerm = Prolog.Nil;
    PrologEnvironment env = (PrologEnvironment) engine.control;
    Emails emails = env.getArgs().getEmails();
    Account.Id id = null;
    try {
        ImmutableSet<Account.Id> ids = emails.getAccountForExternal(userId.getEmailAddress());
        if (ids.size() == 1) {
            id = ids.iterator().next();
        }
    } catch (IOException e) {
        throw new SystemException(e.getMessage());
    }
    if (id == null) {
        idTerm = anonymous;
    } else {
        idTerm = new IntegerTerm(id.get());
    }
    String name = userId.getName();
    if (name != null && !name.equals("")) {
        nameTerm = SymbolTerm.create(name);
    }
    String email = userId.getEmailAddress();
    if (email != null && !email.equals("")) {
        emailTerm = SymbolTerm.create(email);
    }
    if (!a1.unify(new StructureTerm(user, idTerm), engine.trail)) {
        return engine.fail();
    }
    if (!a2.unify(nameTerm, engine.trail)) {
        return engine.fail();
    }
    if (!a3.unify(emailTerm, engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : Account(com.google.gerrit.entities.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) SystemException(com.googlecode.prolog_cafe.exceptions.SystemException) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) 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) Emails(com.google.gerrit.server.account.Emails) IOException(java.io.IOException) PrologEnvironment(com.google.gerrit.server.rules.PrologEnvironment)

Aggregations

Account (com.google.gerrit.entities.Account)1 Emails (com.google.gerrit.server.account.Emails)1 PrologEnvironment (com.google.gerrit.server.rules.PrologEnvironment)1 SystemException (com.googlecode.prolog_cafe.exceptions.SystemException)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 IOException (java.io.IOException)1