use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue 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.EnumValue in project legend-engine by finos.
the class ClassMappingSecondPassBuilder method visit.
@Override
public SetImplementation visit(PureInstanceClassMapping classMapping) {
PureInstanceSetImplementation s = (PureInstanceSetImplementation) parentMapping._classMappings().select(c -> c._id().equals(HelperMappingBuilder.getClassMappingId(classMapping, this.context))).getFirst();
s._propertyMappings().forEachWithIndex((ObjectIntProcedure<org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping>) ((p, i) -> {
org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping pm = (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) p;
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property<?, ?> property = pm._property();
SourceInformation pSourceInformation = SourceInformationHelper.fromM3SourceInformation(p.getSourceInformation());
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification last = pm._transform()._expressionSequence().getLast();
List<Type> typesToCheck;
if (property._genericType()._rawType()._classifierGenericType()._rawType()._name().equals("Class")) {
SetImplementation setImplementation;
if (p._targetSetImplementationId() != null && !p._targetSetImplementationId().equals("")) {
setImplementation = parentMapping._classMappingByIdRecursive(Lists.fixedSize.with(p._targetSetImplementationId()), this.context.pureModel.getExecutionSupport()).getFirst();
Assert.assertTrue(setImplementation != null, () -> "Can't find class mapping '" + p._targetSetImplementationId() + "'", pSourceInformation, EngineErrorType.COMPILATION);
} else {
setImplementation = parentMapping.classMappingByClass((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<Object>) property._genericType()._rawType(), this.context.pureModel.getExecutionSupport()).getFirst();
Assert.assertTrue(setImplementation != null, () -> "Can't find class mapping for '" + HelperModelBuilder.getElementFullPath(property._genericType()._rawType(), this.context.pureModel.getExecutionSupport()) + "'", pSourceInformation, EngineErrorType.COMPILATION);
}
List<? extends InstanceSetImplementation> setImpls = core_pure_router_router_routing.Root_meta_pure_router_routing_resolveOperation_SetImplementation_MANY__Mapping_1__InstanceSetImplementation_MANY_(Lists.immutable.of(setImplementation), parentMapping, this.context.pureModel.getExecutionSupport()).toList();
typesToCheck = setImpls.stream().map(setImpl -> ((PureInstanceSetImplementation) setImpl)._srcClass()).collect(Collectors.toList());
} else if (((org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) p)._transformer() != null) {
EnumerationMapping<Object> m = ((EnumerationMapping<Object>) ((org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) p)._transformer());
Object val = m._enumValueMappings().getFirst()._sourceValues().getFirst();
if (val instanceof String) {
typesToCheck = Collections.singletonList(this.context.pureModel.getType("String"));
} else if (val instanceof Long) {
typesToCheck = Collections.singletonList(this.context.pureModel.getType("Integer"));
} else if (val instanceof EnumValue) {
typesToCheck = Collections.singletonList(this.context.resolveEnumeration(((EnumValue) val).fullPath, pSourceInformation));
} else if (val instanceof Enum) {
GenericType genericType = ((Enum) val)._classifierGenericType();
typesToCheck = genericType != null ? Collections.singletonList(this.context.resolveEnumeration(PackageableElement.getUserPathForPackageableElement(genericType._rawType()), pSourceInformation)) : Collections.emptyList();
} else {
typesToCheck = Collections.emptyList();
}
} else {
typesToCheck = Collections.singletonList(property._genericType()._rawType());
}
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity multiplicityToCheck = pm._explodeProperty() != null && pm._explodeProperty() ? this.context.pureModel.getMultiplicity("zeromany") : property._multiplicity();
List<ValueSpecification> lines = ((PurePropertyMapping) classMapping.propertyMappings.get(i)).transform.body;
typesToCheck.stream().filter(Objects::nonNull).forEach(t -> HelperModelBuilder.checkTypeCompatibility(this.context, last._genericType()._rawType(), t, "Error in class mapping '" + HelperModelBuilder.getElementFullPath(parentMapping, this.context.pureModel.getExecutionSupport()) + "' for property '" + pm._property()._name() + "'", lines.get(lines.size() - 1).sourceInformation));
HelperModelBuilder.checkMultiplicityCompatibility(last._multiplicity(), multiplicityToCheck, "Error in class mapping '" + HelperModelBuilder.getElementFullPath(parentMapping, this.context.pureModel.getExecutionSupport()) + "' for property '" + pm._property()._name() + "'", lines.get(lines.size() - 1).sourceInformation);
}));
return s;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue in project legend-engine by finos.
the class GraphFetchTreeParseTreeWalker method visitScalarParameterContext.
private ValueSpecification visitScalarParameterContext(GraphFetchTreeParserGrammar.ScalarParameterContext scalarParameterContext) {
if (scalarParameterContext.enumReference() != null) {
EnumValue result = new EnumValue();
result.sourceInformation = walkerSourceInformation.getSourceInformation(scalarParameterContext.enumReference());
result.fullPath = PureGrammarParserUtility.fromQualifiedName(scalarParameterContext.enumReference().qualifiedName().packagePath() == null ? Collections.emptyList() : scalarParameterContext.enumReference().qualifiedName().packagePath().identifier(), scalarParameterContext.enumReference().qualifiedName().identifier());
result.value = PureGrammarParserUtility.fromIdentifier(scalarParameterContext.enumReference().identifier());
return result;
}
if (scalarParameterContext.variable() != null) {
Variable ve = new Variable();
ve.sourceInformation = walkerSourceInformation.getSourceInformation(scalarParameterContext.variable().identifier());
ve.name = PureGrammarParserUtility.fromIdentifier(scalarParameterContext.variable().identifier());
return ve;
}
return instanceLiteralToken(scalarParameterContext.instanceLiteral().instanceLiteralToken());
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue in project legend-engine by finos.
the class DomainParseTreeWalker method visitEnumValue.
private EnumValue visitEnumValue(DomainParserGrammar.EnumValueContext ctx) {
EnumValue enumValue = new EnumValue();
enumValue.value = PureGrammarParserUtility.fromIdentifier(ctx.identifier());
enumValue.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
enumValue.stereotypes = ctx.stereotypes() == null ? Lists.mutable.empty() : this.visitStereotypes(ctx.stereotypes());
enumValue.taggedValues = ctx.taggedValues() == null ? Lists.mutable.empty() : this.visitTaggedValues(ctx.taggedValues());
return enumValue;
}
use of org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.EnumValue in project legend-engine by finos.
the class HelperValueSpecificationBuilder method processProperty.
public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification processProperty(CompileContext context, MutableList<String> openVariables, ProcessingContext processingContext, List<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification> parameters, String property, SourceInformation sourceInformation) {
// for X.property. X is the first parameter
processingContext.push("Processing property " + property);
org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification firstArgument = parameters.get(0);
MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification> processedParameters = ListIterate.collect(parameters, p -> p.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)));
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType genericType;
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity multiplicity;
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification inferredVariable;
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification result;
if (// Only for backward compatibility!
firstArgument instanceof org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Enum || (processedParameters.get(0)._genericType()._rawType().equals(context.pureModel.getType("meta::pure::metamodel::type::Enumeration")))) {
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity m = new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity();
m.lowerBound = 1;
m.setUpperBound(1);
CString enumValue = new CString();
enumValue.values = Lists.mutable.of(property);
enumValue.multiplicity = m;
// validation to make sure the enum value can be found
context.resolveEnumValue(((PackageableElementPtr) firstArgument).fullPath, enumValue.values.get(0), firstArgument.sourceInformation, sourceInformation);
AppliedFunction extractEnum = new AppliedFunction();
extractEnum.function = "extractEnumValue";
extractEnum.parameters = Lists.mutable.of(firstArgument, enumValue);
result = extractEnum.accept(new ValueSpecificationBuilder(context, openVariables, processingContext));
} else {
if (firstArgument instanceof Variable) {
inferredVariable = processingContext.getInferredVariable(((Variable) firstArgument).name);
} else {
inferredVariable = processedParameters.get(0);
}
Type inferredType = inferredVariable._genericType()._rawType();
if (// is an enum
!(inferredType instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)) {
inferredType = context.pureModel.getType("meta::pure::metamodel::type::Enum");
}
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty<?> foundProperty = findProperty(context, (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?>) inferredType, parameters, property, sourceInformation);
if (foundProperty instanceof Property) {
genericType = (foundProperty._classifierGenericType()._typeArguments()).getLast();
multiplicity = foundProperty._multiplicity();
} else if (foundProperty instanceof QualifiedProperty) {
FunctionType fType = (FunctionType) foundProperty._classifierGenericType()._typeArguments().getFirst()._rawType();
genericType = fType._returnType();
multiplicity = fType._returnMultiplicity();
} else {
throw new UnsupportedOperationException("Unhandled property: " + foundProperty);
}
if (// autoMap
!inferredVariable._multiplicity().getName().equals("PureOne")) {
processingContext.push("Building Automap for " + property);
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity m = new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity();
m.lowerBound = 1;
m.setUpperBound(1);
List<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification> localParameters = Lists.mutable.ofAll(parameters);
final String automapName = "v_automap";
Lambda automapLambda = new Lambda();
AppliedProperty appliedProperty = new AppliedProperty();
appliedProperty.property = property;
Variable automapvar = new Variable();
Variable automaLambdaparam = new Variable();
automapvar.name = automapName;
appliedProperty.parameters = Lists.mutable.of(automapvar);
if (!localParameters.isEmpty()) {
localParameters.remove(0);
}
appliedProperty.parameters.addAll(localParameters);
automaLambdaparam.name = automapName;
automaLambdaparam._class = HelperModelBuilder.getElementFullPath(inferredVariable._genericType()._rawType(), context.pureModel.getExecutionSupport());
automaLambdaparam.multiplicity = m;
automapLambda.body = Lists.mutable.of(appliedProperty);
List<Variable> lambdaParams = new FastList<>();
lambdaParams.add(automaLambdaparam);
automapLambda.parameters = lambdaParams;
List<org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification> newParams = Lists.mutable.of(parameters.get(0), automapLambda);
result = context.buildFunctionExpression("map", null, newParams, openVariables, null, processingContext).getOne();
processingContext.pop();
} else {
result = new Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl("")._func(foundProperty)._propertyName(new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("")._values(Lists.fixedSize.of(foundProperty.getName())))._genericType(genericType)._multiplicity(multiplicity)._parametersValues(processedParameters);
}
}
processingContext.pop();
return result;
}
Aggregations