Search in sources :

Example 11 with IntegerTerm

use of com.googlecode.prolog_cafe.lang.IntegerTerm in project gerrit by GerritCodeReview.

the class PRED_current_user_2 method createUser.

public Term createUser(Prolog engine, Term key) {
    if (!(key instanceof StructureTerm) || key.arity() != 1 || !((StructureTerm) key).functor().equals(user)) {
        throw new IllegalTypeException(this, 1, "user(int)", key);
    }
    Term idTerm = key.arg(0);
    CurrentUser user;
    if (idTerm instanceof IntegerTerm) {
        Map<Account.Id, IdentifiedUser> cache = StoredValues.USERS.get(engine);
        Account.Id accountId = new Account.Id(((IntegerTerm) idTerm).intValue());
        user = cache.get(accountId);
        if (user == null) {
            IdentifiedUser.GenericFactory userFactory = userFactory(engine);
            IdentifiedUser who = userFactory.create(accountId);
            cache.put(accountId, who);
            user = who;
        }
    } else if (idTerm.equals(anonymous)) {
        user = StoredValues.ANONYMOUS_USER.get(engine);
    } else {
        throw new IllegalTypeException(this, 1, "user(int)", key);
    }
    return new JavaObjectTerm(user);
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) IllegalTypeException(com.googlecode.prolog_cafe.exceptions.IllegalTypeException) CurrentUser(com.google.gerrit.server.CurrentUser) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) IdentifiedUser(com.google.gerrit.server.IdentifiedUser)

Aggregations

IntegerTerm (com.googlecode.prolog_cafe.lang.IntegerTerm)11 Term (com.googlecode.prolog_cafe.lang.Term)10 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)8 StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)7 Account (com.google.gerrit.reviewdb.client.Account)5 CurrentUser (com.google.gerrit.server.CurrentUser)4 OrmException (com.google.gwtorm.server.OrmException)4 JavaException (com.googlecode.prolog_cafe.exceptions.JavaException)4 LabelType (com.google.gerrit.common.data.LabelType)3 ChangeData (com.google.gerrit.server.query.change.ChangeData)3 IllegalTypeException (com.googlecode.prolog_cafe.exceptions.IllegalTypeException)3 JavaObjectTerm (com.googlecode.prolog_cafe.lang.JavaObjectTerm)3 VariableTerm (com.googlecode.prolog_cafe.lang.VariableTerm)3 LabelPermission (com.google.gerrit.server.permissions.LabelPermission)2 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)2 PInstantiationException (com.googlecode.prolog_cafe.exceptions.PInstantiationException)2 SystemException (com.googlecode.prolog_cafe.exceptions.SystemException)2 LabelTypes (com.google.gerrit.common.data.LabelTypes)1 LabelValue (com.google.gerrit.common.data.LabelValue)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1