use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime in project legend-engine by finos.
the class RelationalGraphFetchUtils method subTreeValidForCaching.
static boolean subTreeValidForCaching(GraphFetchTree graphFetchTree) {
boolean currentValidity = true;
if (graphFetchTree instanceof PropertyGraphFetchTree) {
PropertyGraphFetchTree propertyGraphFetchTree = (PropertyGraphFetchTree) graphFetchTree;
if (propertyGraphFetchTree.parameters != null && !propertyGraphFetchTree.parameters.isEmpty()) {
currentValidity = propertyGraphFetchTree.parameters.stream().allMatch(param -> param instanceof CBoolean || param instanceof CInteger || param instanceof CFloat || param instanceof CDecimal || param instanceof CString || param instanceof CStrictDate || param instanceof CDateTime || param instanceof EnumValue || (param instanceof Collection && ((Collection) param).values.stream().allMatch(x -> x instanceof EnumValue)));
}
}
boolean childrenValidity = graphFetchTree.subTrees == null || graphFetchTree.subTrees.isEmpty() || graphFetchTree.subTrees.stream().allMatch(RelationalGraphFetchUtils::subTreeValidForCaching);
return currentValidity && childrenValidity;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime in project legend-engine by finos.
the class MilestoningParseTreeWalker method visitDate.
private static CDate visitDate(String val, SourceInformation sourceInformation) {
Pattern strictDatePattern = Pattern.compile("%([0-9]{4})-([0-9]{2})-([0-9]{2})");
Matcher strictDateMatcher = strictDatePattern.matcher(val);
CDate date = strictDateMatcher.matches() ? visitStrictDate(new CStrictDate(), val) : visitDateTime(new CDateTime(), val);
date.sourceInformation = sourceInformation;
date.multiplicity = new Multiplicity();
date.multiplicity.lowerBound = 1;
date.multiplicity.setUpperBound(1);
return date;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime in project legend-engine by finos.
the class GraphFetchTreeParseTreeWalker method instanceLiteralToken.
private ValueSpecification instanceLiteralToken(GraphFetchTreeParserGrammar.InstanceLiteralTokenContext ctx) {
ValueSpecification result;
try {
Multiplicity m = this.getPureOne();
if (ctx.STRING() != null) {
List<String> values = new ArrayList<>();
values.add(PureGrammarParserUtility.fromGrammarString(ctx.getText(), true));
CString instance = new CString();
instance.multiplicity = m;
instance.values = values;
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
result = instance;
} else if (ctx.INTEGER() != null) {
List<Long> values = new ArrayList<>();
values.add(Long.parseLong(ctx.getText()));
CInteger instance = new CInteger();
instance.multiplicity = m;
instance.values = values;
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
result = instance;
} else if (ctx.FLOAT() != null) {
List<Double> values = new ArrayList<>();
values.add(Double.parseDouble(ctx.getText()));
CFloat instance = new CFloat();
instance.multiplicity = m;
instance.values = values;
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
result = instance;
} else if (ctx.DATE() != null) {
List<String> values = new ArrayList<>();
// Likely wrong
values.add(ctx.getText());
CDateTime instance = new CDateTime();
instance.multiplicity = this.getPureOne();
instance.values = values.stream().map(value -> value.substring(value.lastIndexOf('%') + 1)).collect(Collectors.toList());
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
result = instance;
} else if (ctx.BOOLEAN() != null) {
List<Boolean> values = new ArrayList<>();
values.add(Boolean.parseBoolean(ctx.getText()));
CBoolean instance = new CBoolean();
instance.multiplicity = m;
instance.values = values;
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
result = instance;
} else {
// TODO
throw new UnsupportedOperationException();
}
} catch (Exception e) {
throw new UnsupportedOperationException(ctx.getText());
}
return result;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime in project legend-engine by finos.
the class NavigationParseTreeWalker method visitAtomicExpression.
private ValueSpecification visitAtomicExpression(NavigationParserGrammar.AtomicContext ctx) {
if (ctx.BOOLEAN() != null) {
CBoolean instance = new CBoolean();
List<Boolean> values = new ArrayList<>();
values.add(Boolean.parseBoolean(ctx.getText()));
instance.multiplicity = this.getMultiplicityOneOne();
instance.values = values;
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
return instance;
} else if (ctx.STRING() != null) {
CString instance = getInstanceString(ctx.getText());
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
return instance;
} else if (ctx.INTEGER() != null) {
CInteger instance = getInstanceInteger(ctx.getText());
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
return instance;
} else if (ctx.FLOAT() != null) {
CFloat instance = new CFloat();
instance.multiplicity = this.getMultiplicityOneOne();
instance.values = Lists.mutable.with(Double.parseDouble(ctx.getText()));
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
return instance;
} else if (ctx.DATE() != null) {
CDateTime instance = new CDateTime();
instance.multiplicity = this.getMultiplicityOneOne();
String var = ctx.getText();
instance.values = Lists.mutable.with(var.substring(var.lastIndexOf('%') + 1));
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
return instance;
} else if (ctx.LATEST_DATE() != null) {
CLatestDate instance = new CLatestDate();
instance.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
instance.multiplicity = getMultiplicityOneOne();
return instance;
}
throw new EngineException("Unsupported scalar expression for property path: " + ctx.getText());
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CDateTime in project legend-engine by finos.
the class DateParseTreeWalker method createDateTime.
private CDateTime createDateTime(String values) {
CDateTime cDateTime = new CDateTime();
cDateTime.multiplicity = ParserTreeWalkerUtility.getMultiplicityOneOne();
cDateTime.values = Lists.mutable.with(values);
cDateTime.sourceInformation = walkerSourceInformation.getSourceInformation(this.dateToken.getSymbol());
return cDateTime;
}
Aggregations