Search in sources :

Example 1 with RuleParserException

use of org.smartdata.rule.exceptions.RuleParserException in project SSM by Intel-bigdata.

the class SmartRuleVisitTranslator method parseIdParams.

private TreeNode parseIdParams(ParserRuleContext ctx, Property p, int start) {
    int paraIndex = 0;
    List<Object> paras = new ArrayList<>();
    // String a = ctx.getText();
    for (int i = start; i < ctx.getChildCount() - 1; i += 2) {
        String c = ctx.getChild(i).getText();
        TreeNode res = visit(ctx.getChild(i));
        if (res.isOperNode()) {
            throw new RuleParserException("Should be direct.");
        }
        if (res.getValueType() != p.getParamsTypes().get(paraIndex)) {
            throw new RuleParserException("Unexpected parameter type: " + ctx.getChild(i).getText());
        }
        Object value = ((ValueNode) res).eval().getValue();
        paras.add(value);
        if (p.getParamsTypes().get(paraIndex) == ValueType.TIMEINTVAL) {
            minTimeInverval = Math.min((long) value, minTimeInverval);
        }
        paraIndex++;
    }
    PropertyRealParas realParas = new PropertyRealParas(p, paras);
    realParases.add(realParas);
    return new ValueNode(new VisitResult(p.getValueType(), null, realParas));
}
Also used : RuleParserException(org.smartdata.rule.exceptions.RuleParserException) ArrayList(java.util.ArrayList) PropertyRealParas(org.smartdata.rule.objects.PropertyRealParas) SmartObject(org.smartdata.rule.objects.SmartObject)

Example 2 with RuleParserException

use of org.smartdata.rule.exceptions.RuleParserException in project SSM by Intel-bigdata.

the class SmartRuleVisitTranslator method pharseConstTimePoint.

public TreeNode pharseConstTimePoint(String str) {
    SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    TreeNode result;
    Date date;
    try {
        date = ft.parse(str);
        result = new ValueNode(new VisitResult(ValueType.TIMEPOINT, date.getTime()));
    } catch (ParseException e) {
        throw new RuleParserException("Invalid time point string '" + str + "'");
    }
    return result;
}
Also used : RuleParserException(org.smartdata.rule.exceptions.RuleParserException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with RuleParserException

use of org.smartdata.rule.exceptions.RuleParserException in project SSM by Intel-bigdata.

the class SmartRuleVisitTranslator method visitTriTimePoint.

@Override
public TreeNode visitTriTimePoint(SmartRuleParser.TriTimePointContext ctx) {
    timeBasedScheduleInfo = new TimeBasedScheduleInfo();
    TreeNode tr = visit(ctx.timepointexpr());
    try {
        long tm = (Long) (tr.eval().getValue());
        // We set it to -1 and its value will be set after the rule is triggered.
        if (ctx.timepointexpr().getStart().getText().equalsIgnoreCase("now") && ctx.timepointexpr().getStop().getText().equalsIgnoreCase("now")) {
            tm = -1L;
        }
        timeBasedScheduleInfo.setStartTime(tm);
        timeBasedScheduleInfo.setEndTime(tm);
        return null;
    } catch (IOException e) {
        throw new RuleParserException("Evaluate 'AT' expression error");
    }
}
Also used : RuleParserException(org.smartdata.rule.exceptions.RuleParserException) IOException(java.io.IOException) TimeBasedScheduleInfo(org.smartdata.model.rule.TimeBasedScheduleInfo)

Example 4 with RuleParserException

use of org.smartdata.rule.exceptions.RuleParserException in project SSM by Intel-bigdata.

the class SmartRuleVisitTranslator method visitIdAtt.

// ID
@Override
public TreeNode visitIdAtt(SmartRuleParser.IdAttContext ctx) {
    // System.out.println("Bare ID: " + ctx.getText());
    Property p = objects.get("Default").getProperty(ctx.getText());
    if (p == null) {
        throw new RuleParserException("Object " + objects.get("Default").toString() + " does not have a attribute named '" + "'" + ctx.getText());
    }
    if (p.getParamsTypes() != null) {
        throw new RuleParserException("Should have no parameter(s) for " + ctx.getText());
    }
    PropertyRealParas realParas = new PropertyRealParas(p, null);
    realParases.add(realParas);
    return new ValueNode(new VisitResult(p.getValueType(), null, realParas));
}
Also used : RuleParserException(org.smartdata.rule.exceptions.RuleParserException) PropertyRealParas(org.smartdata.rule.objects.PropertyRealParas) Property(org.smartdata.rule.objects.Property)

Example 5 with RuleParserException

use of org.smartdata.rule.exceptions.RuleParserException in project SSM by Intel-bigdata.

the class SmartRuleVisitTranslator method visitIdAttPara.

@Override
public TreeNode visitIdAttPara(SmartRuleParser.IdAttParaContext ctx) {
    SmartObject obj = createIfNotExist("Default");
    Property p = obj.getProperty(ctx.ID().getText());
    if (p == null) {
        throw new RuleParserException("Object " + obj.toString() + " does not have a attribute named '" + ctx.ID().getText() + "'");
    }
    if (p.getParamsTypes() == null) {
        throw new RuleParserException(obj.toString() + "." + ctx.ID().getText() + " does not need parameter(s)");
    }
    int numParameters = ctx.getChildCount() / 2 - 1;
    if (p.getParamsTypes().size() != numParameters) {
        throw new RuleParserException(obj.toString() + "." + ctx.ID().getText() + " needs " + p.getParamsTypes().size() + " instead of " + numParameters);
    }
    return parseIdParams(ctx, p, 2);
}
Also used : RuleParserException(org.smartdata.rule.exceptions.RuleParserException) Property(org.smartdata.rule.objects.Property) SmartObject(org.smartdata.rule.objects.SmartObject)

Aggregations

RuleParserException (org.smartdata.rule.exceptions.RuleParserException)8 Property (org.smartdata.rule.objects.Property)4 PropertyRealParas (org.smartdata.rule.objects.PropertyRealParas)3 SmartObject (org.smartdata.rule.objects.SmartObject)3 ParseException (java.text.ParseException)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Interval (org.antlr.v4.runtime.misc.Interval)1 TimeBasedScheduleInfo (org.smartdata.model.rule.TimeBasedScheduleInfo)1