Search in sources :

Example 1 with IntegerTerm

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

the class PRED_commit_stats_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();
    PatchList pl = StoredValues.PATCH_LIST.get(engine);
    // Account for magic files
    if (!a1.unify(new IntegerTerm(pl.getPatches().size() - countMagicFiles(pl.getPatches())), engine.trail)) {
        return engine.fail();
    }
    if (!a2.unify(new IntegerTerm(pl.getInsertions()), engine.trail)) {
        return engine.fail();
    }
    if (!a3.unify(new IntegerTerm(pl.getDeletions()), engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) PatchList(com.google.gerrit.server.patch.PatchList) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm)

Example 2 with IntegerTerm

use of com.googlecode.prolog_cafe.lang.IntegerTerm 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)

Example 3 with IntegerTerm

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

the class PRED_get_legacy_label_types_1 method export.

static Term export(LabelType type) {
    LabelValue min = type.getMin();
    LabelValue max = type.getMax();
    return new StructureTerm(symLabelType, SymbolTerm.intern(type.getName()), SymbolTerm.intern(type.getFunctionName()), min != null ? new IntegerTerm(min.getValue()) : NONE, max != null ? new IntegerTerm(max.getValue()) : NONE);
}
Also used : IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) LabelValue(com.google.gerrit.common.data.LabelValue) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm)

Example 4 with IntegerTerm

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

the class PRED_unresolved_comments_count_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    try {
        Integer count = StoredValues.CHANGE_DATA.get(engine).unresolvedCommentCount();
        if (!a1.unify(new IntegerTerm(count != null ? count : 0), engine.trail)) {
            return engine.fail();
        }
    } catch (OrmException err) {
        throw new JavaException(this, 1, err);
    }
    return cont;
}
Also used : IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) JavaException(com.googlecode.prolog_cafe.exceptions.JavaException) OrmException(com.google.gwtorm.server.OrmException) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm)

Example 5 with IntegerTerm

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

the class PRED_uploader_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    PatchSet patchSet = StoredValues.getPatchSet(engine);
    if (patchSet == null) {
        log.error("Failed to load current patch set of change " + StoredValues.getChange(engine).getChangeId());
        return engine.fail();
    }
    Account.Id uploaderId = patchSet.getUploader();
    if (!a1.unify(new StructureTerm(user, new IntegerTerm(uploaderId.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) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) 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)

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