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));
}
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;
}
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");
}
}
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));
}
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);
}
Aggregations