Search in sources :

Example 6 with IntegerTerm

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

the class AbstractCommitUserIdentityPredicate method exec.

protected Operation exec(Prolog engine, UserIdentity 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;
    Account.Id id = userId.getAccount();
    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.getEmail();
    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.reviewdb.client.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm)

Example 7 with IntegerTerm

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

the class PRED__check_user_label_3 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    Term a2 = arg2.dereference();
    Term a3 = arg3.dereference();
    if (a1 instanceof VariableTerm) {
        throw new PInstantiationException(this, 1);
    }
    if (!(a1 instanceof SymbolTerm)) {
        throw new IllegalTypeException(this, 1, "atom", a1);
    }
    String label = a1.name();
    if (a2 instanceof VariableTerm) {
        throw new PInstantiationException(this, 2);
    }
    if (!(a2 instanceof JavaObjectTerm) || !a2.convertible(CurrentUser.class)) {
        throw new IllegalTypeException(this, 2, "CurrentUser)", a2);
    }
    CurrentUser user = (CurrentUser) ((JavaObjectTerm) a2).object();
    if (a3 instanceof VariableTerm) {
        throw new PInstantiationException(this, 3);
    }
    if (!(a3 instanceof IntegerTerm)) {
        throw new IllegalTypeException(this, 3, "integer", a3);
    }
    short val = (short) ((IntegerTerm) a3).intValue();
    try {
        ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
        LabelType type = cd.getLabelTypes().byLabel(label);
        if (type == null) {
            return engine.fail();
        }
        StoredValues.PERMISSION_BACKEND.get(engine).user(user).change(cd).check(new LabelPermission.WithValue(type, val));
        return cont;
    } catch (OrmException err) {
        throw new JavaException(this, 1, err);
    } catch (AuthException err) {
        return engine.fail();
    } catch (PermissionBackendException err) {
        SystemException se = new SystemException(err.getMessage());
        se.initCause(err);
        throw se;
    }
}
Also used : IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) JavaException(com.googlecode.prolog_cafe.exceptions.JavaException) IllegalTypeException(com.googlecode.prolog_cafe.exceptions.IllegalTypeException) CurrentUser(com.google.gerrit.server.CurrentUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) ChangeData(com.google.gerrit.server.query.change.ChangeData) PInstantiationException(com.googlecode.prolog_cafe.exceptions.PInstantiationException) SystemException(com.googlecode.prolog_cafe.exceptions.SystemException) OrmException(com.google.gwtorm.server.OrmException) LabelType(com.google.gerrit.common.data.LabelType) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) LabelPermission(com.google.gerrit.server.permissions.LabelPermission)

Example 8 with IntegerTerm

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

the class PRED__user_label_range_4 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    Term a2 = arg2.dereference();
    Term a3 = arg3.dereference();
    Term a4 = arg4.dereference();
    if (a1 instanceof VariableTerm) {
        throw new PInstantiationException(this, 1);
    }
    if (!(a1 instanceof SymbolTerm)) {
        throw new IllegalTypeException(this, 1, "atom", a1);
    }
    String label = a1.name();
    if (a2 instanceof VariableTerm) {
        throw new PInstantiationException(this, 2);
    }
    if (!(a2 instanceof JavaObjectTerm) || !a2.convertible(CurrentUser.class)) {
        throw new IllegalTypeException(this, 2, "CurrentUser)", a2);
    }
    CurrentUser user = (CurrentUser) ((JavaObjectTerm) a2).object();
    Set<LabelPermission.WithValue> can;
    try {
        ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
        LabelType type = cd.getLabelTypes().byLabel(label);
        if (type == null) {
            return engine.fail();
        }
        can = StoredValues.PERMISSION_BACKEND.get(engine).user(user).change(cd).test(type);
    } catch (OrmException err) {
        throw new JavaException(this, 1, err);
    } catch (PermissionBackendException err) {
        SystemException se = new SystemException(err.getMessage());
        se.initCause(err);
        throw se;
    }
    int min = 0;
    int max = 0;
    for (LabelPermission.WithValue v : can) {
        min = Math.min(min, v.value());
        max = Math.max(max, v.value());
    }
    if (!a3.unify(new IntegerTerm(min), engine.trail)) {
        return engine.fail();
    }
    if (!a4.unify(new IntegerTerm(max), engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : JavaException(com.googlecode.prolog_cafe.exceptions.JavaException) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) IllegalTypeException(com.googlecode.prolog_cafe.exceptions.IllegalTypeException) CurrentUser(com.google.gerrit.server.CurrentUser) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) ChangeData(com.google.gerrit.server.query.change.ChangeData) PInstantiationException(com.googlecode.prolog_cafe.exceptions.PInstantiationException) SystemException(com.googlecode.prolog_cafe.exceptions.SystemException) OrmException(com.google.gwtorm.server.OrmException) LabelType(com.google.gerrit.common.data.LabelType) JavaObjectTerm(com.googlecode.prolog_cafe.lang.JavaObjectTerm) VariableTerm(com.googlecode.prolog_cafe.lang.VariableTerm) LabelPermission(com.google.gerrit.server.permissions.LabelPermission)

Example 9 with IntegerTerm

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

the class PRED_change_owner_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    Account.Id ownerId = StoredValues.getChange(engine).getOwner();
    if (!a1.unify(new StructureTerm(user, new IntegerTerm(ownerId.get())), engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm)

Example 10 with IntegerTerm

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

the class PRED__load_commit_labels_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    Term listHead = Prolog.Nil;
    try {
        ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
        LabelTypes types = cd.getLabelTypes();
        for (PatchSetApproval a : cd.currentApprovals()) {
            LabelType t = types.byLabel(a.getLabelId());
            if (t == null) {
                continue;
            }
            StructureTerm labelTerm = new StructureTerm(sym_label, SymbolTerm.intern(t.getName()), new IntegerTerm(a.getValue()));
            StructureTerm userTerm = new StructureTerm(sym_user, new IntegerTerm(a.getAccountId().get()));
            listHead = new ListTerm(new StructureTerm(sym_commit_label, labelTerm, userTerm), listHead);
        }
    } catch (OrmException err) {
        throw new JavaException(this, 1, err);
    }
    if (!a1.unify(listHead, engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : LabelTypes(com.google.gerrit.common.data.LabelTypes) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) JavaException(com.googlecode.prolog_cafe.exceptions.JavaException) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) ListTerm(com.googlecode.prolog_cafe.lang.ListTerm) OrmException(com.google.gwtorm.server.OrmException) LabelType(com.google.gerrit.common.data.LabelType) 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) ListTerm(com.googlecode.prolog_cafe.lang.ListTerm) ChangeData(com.google.gerrit.server.query.change.ChangeData) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

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