use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.EnumerationMapping in project legend-engine by finos.
the class HelperRelationalBuilder method processRelationalPropertyMapping.
private static PropertyMapping processRelationalPropertyMapping(RelationalPropertyMapping propertyMapping, CompileContext context, PropertyMappingsImplementation immediateParent, InstanceSetImplementation topParent, MutableList<EmbeddedRelationalInstanceSetImplementation> embeddedRelationalPropertyMappings, RichIterable<EnumerationMapping<Object>> allEnumerationMappings, MutableMap<String, TableAlias> aliasMap) {
org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping rpm = new Root_meta_relational_mapping_RelationalPropertyMapping_Impl("");
Property property = resolvePropertyForRelationalPropertyMapping(propertyMapping, immediateParent, context);
if (propertyMapping.bindingTransformer != null) {
return buildSemiStructuredPropertyMapping(property, propertyMapping, immediateParent, (RootRelationalInstanceSetImplementation) topParent, embeddedRelationalPropertyMappings, aliasMap, context);
}
org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping res = rpm._property(property)._localMappingProperty(propertyMapping.localMappingProperty != null)._relationalOperationElement(processRelationalOperationElement(propertyMapping.relationalOperation, context, aliasMap, FastList.newList()))._sourceSetImplementationId(HelperRelationalBuilder.getPropertyMappingSourceId(propertyMapping, immediateParent, property, context))._targetSetImplementationId(HelperRelationalBuilder.getPropertyMappingTargetId(propertyMapping, immediateParent, property, context))._owner(immediateParent);
rpm.setSourceInformation(SourceInformationHelper.toM3SourceInformation(propertyMapping.sourceInformation));
if (propertyMapping.enumMappingId != null) {
EnumerationMapping<Object> eMap = allEnumerationMappings.select(e -> e._name().equals(propertyMapping.enumMappingId)).getFirst();
Assert.assertTrue(eMap != null, () -> "Can't find enumeration mapping '" + propertyMapping.enumMappingId + "'");
res = res._transformer(eMap);
}
return res;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.EnumerationMapping in project legend-engine by finos.
the class HelperMappingBuilder method processEnumMapping.
public static org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping<Object> processEnumMapping(EnumerationMapping em, Mapping pureMapping, CompileContext context) {
// validate there is no mixed protocol format for source value
List<Object> sourceValues = em.enumValueMappings.stream().flatMap(enumValueMapping -> enumValueMapping.sourceValues.stream()).collect(Collectors.toList());
if (sourceValues.stream().anyMatch(sourceValue -> !(sourceValue instanceof EnumValueMappingSourceValue)) && sourceValues.stream().anyMatch(sourceValue -> sourceValue instanceof EnumValueMappingSourceValue)) {
throw new EngineException("Mixed formats for enum value mapping source values", em.sourceInformation, EngineErrorType.COMPILATION);
}
// process enum value mappings
String id = getEnumerationMappingId(em);
return new Root_meta_pure_mapping_EnumerationMapping_Impl<>(id, SourceInformationHelper.toM3SourceInformation(em.sourceInformation), null)._classifierGenericType(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::mapping::EnumerationMapping"))._typeArguments(FastList.newListWith(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::metamodel::type::Any")))))._name(id)._parent(pureMapping)._enumeration(context.resolveEnumeration(em.enumeration, em.sourceInformation))._enumValueMappings(ListIterate.collect(em.enumValueMappings, v -> new Root_meta_pure_mapping_EnumValueMapping_Impl(null, SourceInformationHelper.toM3SourceInformation(em.sourceInformation), null)._enum(context.resolveEnumValue(em.enumeration, v.enumValue))._sourceValues(convertSourceValues(em, v.sourceValues, context))));
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.EnumerationMapping 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.packageableElement.mapping.EnumerationMapping in project legend-engine by finos.
the class MappingParseTreeWalker method visitMappingElement.
private Mapping visitMappingElement(MappingParserGrammar.MappingElementContext ctx, Mapping mapping) {
String parserName = ctx.parserName().getText();
// Construct the mapping element string (with spacing) to be dispatched to another parser
// NOTE: we want to preserve the spacing so we can correctly produce source information in the dispatched parser
StringBuilder mappingElementStringBuilder = new StringBuilder();
for (MappingParserGrammar.MappingElementBodyContentContext fragment : ctx.mappingElementBody().mappingElementBodyContent()) {
mappingElementStringBuilder.append(fragment.getText());
}
String mappingElementCode = mappingElementStringBuilder.length() > 0 ? mappingElementStringBuilder.substring(0, mappingElementStringBuilder.length() - 1) : mappingElementStringBuilder.toString();
// prepare island grammar walker source information
int startLine = ctx.mappingElementBody().BRACE_OPEN().getSymbol().getLine();
int lineOffset = walkerSourceInformation.getLineOffset() + startLine - 1;
// only add current walker source information column offset if this is the first line
int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + ctx.mappingElementBody().BRACE_OPEN().getSymbol().getCharPositionInLine() + ctx.mappingElementBody().BRACE_OPEN().getText().length();
ParseTreeWalkerSourceInformation mappingElementWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(mapping.getPath(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build();
MappingElementSourceCode mappingElementSourceCode = new MappingElementSourceCode(mappingElementCode, parserName, mappingElementWalkerSourceInformation, ctx, this.walkerSourceInformation);
MappingElementParser extraParser = this.extensions.getExtraMappingElementParser(mappingElementSourceCode.name);
if (extraParser == null) {
throw new EngineException("No parser for " + mappingElementSourceCode.name, this.walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
}
Object mappingElement = extraParser.parse(mappingElementSourceCode, this.parserContext);
if (mappingElement instanceof ClassMapping) {
mapping.classMappings.add((ClassMapping) mappingElement);
} else if (mappingElement instanceof EnumerationMapping) {
mapping.enumerationMappings.add((EnumerationMapping) mappingElement);
} else if (mappingElement instanceof AssociationMapping) {
mapping.associationMappings.add((AssociationMapping) mappingElement);
} else {
throw new EngineException("Invalid parser result for " + mappingElementSourceCode.name + ": " + mappingElement, this.walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
}
return mapping;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.EnumerationMapping in project legend-engine by finos.
the class PropertyMappingBuilder method visit.
@Override
public PropertyMapping visit(PurePropertyMapping propertyMapping) {
org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping pm = new Root_meta_pure_mapping_modelToModel_PurePropertyMapping_Impl("");
Property property = HelperMappingBuilder.getMappedProperty(propertyMapping, this.context);
pm.setSourceInformation(SourceInformationHelper.toM3SourceInformation(propertyMapping.sourceInformation));
pm._property(property)._explodeProperty(propertyMapping.explodeProperty)._sourceSetImplementationId(propertyMapping.source)._targetSetImplementationId(HelperMappingBuilder.getPropertyMappingTargetId(propertyMapping, property, context))._owner(owner);
String mappingName = owner._parent().getName();
pm._transform(HelperMappingBuilder.processPurePropertyMappingTransform(propertyMapping, propertyMapping.transform, owner, owner._srcClass(), this.context, mappingName));
if (propertyMapping.enumMappingId != null) {
EnumerationMapping<Object> eMap = allEnumerationMappings.select(e -> e._name().equals(propertyMapping.enumMappingId)).getFirst();
Assert.assertTrue(eMap != null, () -> "Can't find enumeration mapping '" + propertyMapping.enumMappingId + "'", propertyMapping.sourceInformation, EngineErrorType.COMPILATION);
pm._transformer(eMap);
}
if (propertyMapping.localMappingProperty != null) {
pm._localMappingProperty(true);
pm._localMappingPropertyType(this.context.resolveType(propertyMapping.localMappingProperty.type, propertyMapping.localMappingProperty.sourceInformation));
pm._localMappingPropertyMultiplicity(this.context.pureModel.getMultiplicity(propertyMapping.localMappingProperty.multiplicity));
}
return pm;
}
Aggregations