use of org.finos.legend.pure.generated.Root_meta_pure_metamodel_relationship_Generalization_Impl in project legend-engine by finos.
the class HelperMappingBuilder method buildMappingClassOutOfLocalProperties.
public static void buildMappingClassOutOfLocalProperties(SetImplementation setImplementation, RichIterable<? extends org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping> propertyMappings, CompileContext context) {
if (setImplementation instanceof InstanceSetImplementation && propertyMappings != null) {
List<? extends org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping> localPropertyMappings = ListIterate.select(propertyMappings.toList(), x -> x._localMappingProperty() != null && x._localMappingProperty());
if (!localPropertyMappings.isEmpty()) {
String mappingClassName = setImplementation._class().getName() + "_" + setImplementation._parent().getName() + "_" + setImplementation._id();
final MappingClass mappingClass = new Root_meta_pure_mapping_MappingClass_Impl<>(mappingClassName);
mappingClass._name(mappingClassName);
GenericType classifierGenericType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::metamodel::type::Class"))._typeArguments(Lists.fixedSize.of(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(mappingClass)));
mappingClass._classifierGenericType(classifierGenericType);
GenericType superType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(setImplementation._class());
Generalization newGeneralization = new Root_meta_pure_metamodel_relationship_Generalization_Impl("")._specific(mappingClass)._general(superType);
mappingClass._generalizations(Lists.immutable.with(newGeneralization));
setImplementation._class()._specializationsAdd(newGeneralization);
mappingClass._properties(ListIterate.collect(localPropertyMappings, pm -> {
Property property = pm._property();
property._owner(mappingClass);
property._classifierGenericType()._typeArguments().toList().get(0)._rawType(mappingClass);
return property;
}));
((InstanceSetImplementation) setImplementation)._mappingClass(mappingClass);
}
}
}
use of org.finos.legend.pure.generated.Root_meta_pure_metamodel_relationship_Generalization_Impl in project legend-engine by finos.
the class PackageableElementSecondPassBuilder method visit.
@Override
public PackageableElement visit(Class srcClass) {
String fullPath = this.context.pureModel.buildPackageString(srcClass._package, srcClass.name);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class _class = this.context.pureModel.getClass(fullPath, srcClass.sourceInformation);
final GenericType _classGenericType = this.context.resolveGenericType(fullPath, srcClass.sourceInformation);
Set<String> uniqueSuperTypes = new HashSet<>();
MutableList<Generalization> generalization = ListIterate.collect(srcClass.superTypes, superType -> {
// validate no duplicated class supertype
if (!uniqueSuperTypes.add(superType)) {
throw new EngineException("Duplicated super type '" + superType + "' in class '" + this.context.pureModel.buildPackageString(srcClass._package, srcClass.name) + "'", srcClass.sourceInformation, EngineErrorType.COMPILATION);
}
Generalization g = new Root_meta_pure_metamodel_relationship_Generalization_Impl("")._general(this.context.resolveGenericType(superType, srcClass.sourceInformation))._specific(_class);
if (!this.context.pureModel.isImmutable(superType)) {
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?> superTypeClass;
Type type = this.context.resolveType(superType, srcClass.sourceInformation);
try {
superTypeClass = (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?>) type;
} catch (ClassCastException e) {
throw new EngineException("Invalid supertype: '" + srcClass.name + "' cannot extend '" + superType + "' as it is not a class.", srcClass.sourceInformation, EngineErrorType.COMPILATION);
}
superTypeClass._specializationsAdd(g);
}
return g;
});
MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property<?, ?>> properties = ListIterate.collect(srcClass.properties, HelperModelBuilder.processProperty(this.context, _classGenericType, _class));
MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property<?, ?>> withMilestoningProperties = properties.withAll(Milestoning.generateMilestoningProperties(_class, this.context));
ProcessingContext ctx = new ProcessingContext("Class '" + this.context.pureModel.buildPackageString(srcClass._package, srcClass.name) + "' Second Pass");
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification thisVariable = HelperModelBuilder.createThisVariableForClass(this.context, this.context.pureModel.buildPackageString(srcClass._package, srcClass.name));
ctx.addInferredVariables("this", thisVariable);
RichIterable<QualifiedProperty<?>> qualifiedProperties = ListIterate.collect(srcClass.qualifiedProperties, HelperModelBuilder.processQualifiedPropertyFirstPass(this.context, _class, this.context.pureModel.buildPackageString(srcClass._package, srcClass.name), ctx));
_class._originalMilestonedProperties(ListIterate.collect(srcClass.originalMilestonedProperties, HelperModelBuilder.processProperty(this.context, _classGenericType, _class)))._generalizations(generalization)._qualifiedProperties(qualifiedProperties)._properties(withMilestoningProperties);
ctx.flushVariable("this");
return _class;
}
use of org.finos.legend.pure.generated.Root_meta_pure_metamodel_relationship_Generalization_Impl in project legend-engine by finos.
the class HelperMappingBuilder method processMappingClass.
public static Root_meta_pure_mapping_MappingClass_Impl processMappingClass(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.MappingClass mappingclass, CompileContext context, Mapping parent) {
Root_meta_pure_mapping_MappingClass_Impl mappingClass = new Root_meta_pure_mapping_MappingClass_Impl<>(" ");
mappingClass._name(mappingclass.name);
MutableList<Generalization> generalizations = ListIterate.collect(mappingclass.superTypes, (superType) -> {
Generalization generalization = new Root_meta_pure_metamodel_relationship_Generalization_Impl("")._general(context.resolveGenericType(superType))._specific(mappingClass);
context.resolveType(superType)._specializationsAdd(generalization);
return generalization;
});
mappingClass._generalizations(generalizations);
if (mappingclass.setImplementation != null) {
mappingClass._setImplementation(mappingclass.setImplementation.accept(new ClassMappingFirstPassBuilder(context, parent)).getOne());
}
if (mappingclass.rootClass != null) {
mappingClass._class((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) mappingclass.rootClass.accept(new PackageableElementThirdPassBuilder(context)));
}
return mappingClass;
}
use of org.finos.legend.pure.generated.Root_meta_pure_metamodel_relationship_Generalization_Impl in project legend-engine by finos.
the class PackageableElementFourthPassBuilder method visit.
@Override
public PackageableElement visit(Class srcClass) {
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?> targetClass = this.context.pureModel.getClass(this.context.pureModel.buildPackageString(srcClass._package, srcClass.name), srcClass.sourceInformation);
ProcessingContext ctx = new ProcessingContext("Class '" + this.context.pureModel.buildPackageString(srcClass._package, srcClass.name) + "' Fourth Pass");
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification thisVariable = HelperModelBuilder.createThisVariableForClass(this.context, this.context.pureModel.buildPackageString(srcClass._package, srcClass.name));
ListIterate.collect(srcClass.qualifiedProperties, property -> {
ctx.push("Qualified Property " + property.name);
ctx.addInferredVariables("this", thisVariable);
MutableList<ValueSpecification> body;
try {
property.parameters.forEach(p -> p.accept(new ValueSpecificationBuilder(this.context, Lists.mutable.empty(), ctx)));
body = ListIterate.collect(property.body, expression -> expression.accept(new ValueSpecificationBuilder(this.context, Lists.mutable.empty(), ctx)));
} catch (Exception e) {
LOGGER.warn(new LogInfo(null, LoggingEventType.GRAPH_EXPRESSION_ERROR, "Can't build derived property '" + property.name + " of class '" + this.context.pureModel.buildPackageString(srcClass._package, srcClass.name) + "' - stack: " + ctx.getStack()).toString());
if (e instanceof EngineException) {
throw e;
}
throw new EngineException(e.getMessage(), property.sourceInformation, EngineErrorType.COMPILATION);
}
ctx.flushVariable("this");
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty<?> prop = targetClass._qualifiedProperties().select(o -> HelperModelBuilder.isCompatibleDerivedProperty(o, property)).getFirst();
HelperModelBuilder.checkCompatibility(this.context, body.getLast()._genericType()._rawType(), body.getLast()._multiplicity(), prop._genericType()._rawType(), prop._multiplicity(), "Error in derived property '" + srcClass.name + "." + property.name + "'", property.body.get(property.body.size() - 1).sourceInformation);
ctx.pop();
return prop._expressionSequence(body);
});
HelperModelBuilder.processClassConstraints(srcClass, this.context, targetClass, ctx, thisVariable);
if (targetClass._generalizations().isEmpty()) {
Generalization g = new Root_meta_pure_metamodel_relationship_Generalization_Impl("")._general(this.context.pureModel.getGenericType("meta::pure::metamodel::type::Any"))._specific(targetClass);
targetClass._generalizationsAdd(g);
}
return targetClass;
}
use of org.finos.legend.pure.generated.Root_meta_pure_metamodel_relationship_Generalization_Impl in project legend-engine by finos.
the class HelperRelationalBuilder method processRelationalClassMapping.
public static SetImplementation processRelationalClassMapping(RelationalClassMapping relationalClassMapping, CompileContext context, RelationalInstanceSetImplementation base, RootRelationalInstanceSetImplementation topParent, Mapping parent, MutableList<org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation> embeddedRelationalPropertyMappings, RichIterable<org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping<Object>> enumerationMappings, MutableMap<String, TableAlias> aliasMap) {
final org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class pureClass = relationalClassMapping._class != null ? context.resolveClass(relationalClassMapping._class, relationalClassMapping.classSourceInformation) : base._class();
RichIterable<org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement> primaryKey = ListIterate.collect(relationalClassMapping.primaryKey, p -> processRelationalOperationElement(p, context, UnifiedMap.newMap(), FastList.newList()));
MutableList<org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.PropertyMapping> localMappingProperties = ListIterate.select(relationalClassMapping.propertyMappings, p -> p.localMappingProperty != null);
if (localMappingProperties.notEmpty()) {
MappingClass mappingClass = new Root_meta_pure_mapping_MappingClass_Impl<>("");
mappingClass._name(pureClass._name() + "_" + parent._name() + "_" + base._id());
GenericType gType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::mapping::MappingClass"))._typeArguments(Lists.mutable.with(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(mappingClass)));
mappingClass._classifierGenericType(gType);
Generalization g = new Root_meta_pure_metamodel_relationship_Generalization_Impl("")._specific(mappingClass)._general(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(pureClass));
mappingClass._generalizations(Lists.mutable.with(g));
mappingClass._properties(localMappingProperties.collect((Function<org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.PropertyMapping, Property>) propertyMapping -> {
GenericType returnGenericType = context.resolveGenericType(propertyMapping.localMappingProperty.type, propertyMapping.localMappingProperty.sourceInformation);
return new Root_meta_pure_metamodel_function_property_Property_Impl<>(propertyMapping.property.property)._name(propertyMapping.property.property)._classifierGenericType(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::metamodel::function::property::Property"))._typeArguments(Lists.fixedSize.of(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(mappingClass), returnGenericType)))._genericType(returnGenericType)._multiplicity(context.pureModel.getMultiplicity(propertyMapping.localMappingProperty.multiplicity))._owner(mappingClass);
}));
base._mappingClass(mappingClass);
}
base._class(pureClass)._primaryKey(primaryKey)._propertyMappings(ListIterate.collect(relationalClassMapping.propertyMappings, propertyMapping -> processAbstractRelationalPropertyMapping(propertyMapping, context, base, topParent, embeddedRelationalPropertyMappings, enumerationMappings, aliasMap)))._parent(parent);
return base;
}
Aggregations