use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping in project legend-pure by finos.
the class RelationalPropertyMappingProcessor method collectJoinTreeNodes.
private static void collectJoinTreeNodes(Collection<? super JoinTreeNode> targetCollection, PropertyMapping propertyMapping) {
if (propertyMapping instanceof RelationalPropertyMapping) {
RelationalOperationElement relationalOperationElement = ((RelationalPropertyMapping) propertyMapping)._relationalOperationElement();
RelationalOperationElementProcessor.collectJoinTreeNodes(targetCollection, relationalOperationElement);
}
if (propertyMapping instanceof OtherwiseEmbeddedRelationalInstanceSetImplementation) {
PropertyMapping relationalOperationElement = ((OtherwiseEmbeddedRelationalInstanceSetImplementation) propertyMapping)._otherwisePropertyMapping();
collectJoinTreeNodes(targetCollection, relationalOperationElement);
}
if (propertyMapping instanceof PropertyMappingsImplementation) {
RichIterable<? extends PropertyMapping> propertyMappings = ((PropertyMappingsImplementation) propertyMapping)._propertyMappings();
for (PropertyMapping subMapping : propertyMappings) {
collectJoinTreeNodes(targetCollection, subMapping);
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping in project legend-pure by finos.
the class RelationalPropertyMappingProcessor method populateReferenceUsagesForRelationalPropertyMapping.
static void populateReferenceUsagesForRelationalPropertyMapping(PropertyMapping propertyMapping, ModelRepository repository, ProcessorSupport processorSupport) {
if (propertyMapping instanceof EmbeddedRelationalInstanceSetImplementation) {
EmbeddedRelationalInstanceSetImplementation embeddedRelationalInstanceSetImplementation = (EmbeddedRelationalInstanceSetImplementation) propertyMapping;
RichIterable<? extends PropertyMapping> embeddedPropertyMappings = embeddedRelationalInstanceSetImplementation._propertyMappings();
populateReferenceUsagesForRelationalPropertyMappings(embeddedPropertyMappings, repository, processorSupport);
RelationalInstanceSetImplementationProcessor.populateReferenceUsagesForUserDefinedPrimaryKey(propertyMapping, repository, processorSupport);
if (propertyMapping instanceof OtherwiseEmbeddedRelationalInstanceSetImplementation) {
OtherwiseEmbeddedRelationalInstanceSetImplementation otherwiseEmbeddedRelationalInstanceSetImplementation = (OtherwiseEmbeddedRelationalInstanceSetImplementation) embeddedRelationalInstanceSetImplementation;
PropertyMapping otherwiseEmbeddedPropertyMappings = otherwiseEmbeddedRelationalInstanceSetImplementation._otherwisePropertyMapping();
populateReferenceUsagesForRelationalPropertyMapping(otherwiseEmbeddedPropertyMappings, repository, processorSupport);
}
} else {
if (propertyMapping instanceof RelationalPropertyMapping) {
RelationalOperationElement columnExpression = ((RelationalPropertyMapping) propertyMapping)._relationalOperationElement();
RelationalOperationElementProcessor.populateColumnExpressionReferenceUsages(columnExpression, repository, processorSupport);
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping in project legend-pure by finos.
the class MappingValidator method validateId.
public static SetImplementation validateId(AssociationImplementation associationMapping, PropertyMapping propertyMapping, MapIterable<String, ? extends SetImplementation> classMappingIndex, String setImplementationId, String sourceOrTarget, ProcessorSupport processorSupport) {
SetImplementation setImplementation = classMappingIndex.get(setImplementationId);
Property property = (Property) ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport);
if ("target".equals(sourceOrTarget)) {
// Target, so need to find the property on the other end
Association association = (Association) ImportStub.withImportStubByPass(associationMapping._associationCoreInstance(), processorSupport);
property = association._properties().select(Predicates.notEqual(property)).getFirst();
}
if (setImplementation == null) {
throw new PureCompilationException(propertyMapping.getSourceInformation(), "Unable to find " + sourceOrTarget + " class mapping (id:" + setImplementationId + ") for property \'" + propertyMapping._propertyCoreInstance().getName() + "\' in Association mapping \'" + ImportStub.withImportStubByPass(associationMapping._associationCoreInstance(), processorSupport).getName() + "\'. Make sure that you have specified a valid Class mapping id as the source id and target id, using the syntax \'property[sourceId, targetId]: ...\'.");
}
Class _class = (Class) ImportStub.withImportStubByPass(setImplementation._classCoreInstance(), processorSupport);
String propertyName = property.getName();
if (processorSupport.class_findPropertyUsingGeneralization(_class, propertyName) == null) {
throw new PureCompilationException(propertyMapping.getSourceInformation(), "Association mapping property \'" + propertyName + "\' in Association mapping \'" + ImportStub.withImportStubByPass(associationMapping._associationCoreInstance(), processorSupport).getName() + "\' is not a property of source class \'" + _class.getName() + "\'. Make sure that you have specified a valid source id.");
}
return setImplementation;
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping in project legend-pure by finos.
the class MappingValidator method validateAssociationMappings.
private static void validateAssociationMappings(Mapping mapping, final ProcessorSupport processorSupport) {
RichIterable<? extends AssociationImplementation> associationMappings = mapping._associationMappings();
if (!associationMappings.isEmpty()) {
MapIterable<String, ? extends SetImplementation> classMappingIndex = org.finos.legend.pure.m2.dsl.mapping.Mapping.getClassMappingsByIdIncludeEmbedded(mapping, processorSupport);
// Add association mappings to Class mappings
for (AssociationImplementation associationMapping : associationMappings) {
for (PropertyMapping propertyMapping : associationMapping._propertyMappings()) {
Property property = (Property) ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport);
final String propertyName = property.getName();
SetImplementation sourceClassMapping = validateId(associationMapping, propertyMapping, classMappingIndex, propertyMapping._sourceSetImplementationId(), "source", processorSupport);
String targetId = propertyMapping._targetSetImplementationId();
SetImplementation targetClassMapping = validateId(associationMapping, propertyMapping, classMappingIndex, propertyMapping._targetSetImplementationId(), "target", processorSupport);
if (targetClassMapping instanceof EmbeddedSetImplementation) {
throw new PureCompilationException(propertyMapping.getSourceInformation(), "Invalid target class mapping for property \'" + propertyName + "\' in Association mapping \'" + ImportStub.withImportStubByPass(associationMapping._associationCoreInstance(), processorSupport).getName() + "\'. Target \'" + targetId + "\' is an embedded class mapping, embedded mappings are only allowed to be the source in an Association Mapping.");
}
ListIterable<? extends PropertyMapping> sourcePropertyMappings = ((InstanceSetImplementation) sourceClassMapping)._propertyMappings().toList();
PropertyMapping alreadyMapped = sourcePropertyMappings.detect(new Predicate<PropertyMapping>() {
@Override
public boolean accept(PropertyMapping propertyMapping) {
return propertyName.equals(ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport).getName());
}
});
if (alreadyMapped != null) {
throw new PureCompilationException(propertyMapping.getSourceInformation(), "Property \'" + propertyName + "\' is mapped twice, once in Association mapping \'" + ImportStub.withImportStubByPass(associationMapping._associationCoreInstance(), processorSupport).getName() + "\' and once in Class mapping \'" + ((Class) ImportStub.withImportStubByPass(targetClassMapping._classCoreInstance(), processorSupport))._name() + "\'. Only one mapping is allowed.");
}
}
}
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping in project legend-pure by finos.
the class PureInstanceSetImplementationValidator method run.
@Override
public void run(PureInstanceSetImplementation classMapping, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
ProcessorSupport processorSupport = state.getProcessorSupport();
Class mappedClass = (Class) ImportStub.withImportStubByPass(classMapping._classCoreInstance(), processorSupport);
LambdaFunction filter = classMapping._filter();
if (filter != null) {
Validator.validate(filter, (ValidatorState) state, matcher, processorSupport);
Type booleanType = (Type) processorSupport.package_getByUserPath(M3Paths.Boolean);
GenericType filterReturnType = ((FunctionType) processorSupport.function_getFunctionType(filter))._returnType();
if (filterReturnType._rawTypeCoreInstance() != booleanType) {
throw new PureCompilationException(((RichIterable<ValueSpecification>) filter._expressionSequence()).toList().get(0).getSourceInformation(), "A filter should be a Boolean expression");
}
}
MutableSet<String> requiredProperties = getRequiredProperties(mappedClass, processorSupport);
for (PropertyMapping propertyMapping : classMapping._propertyMappings()) {
Property property = (Property) ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport);
requiredProperties.remove(org.finos.legend.pure.m3.navigation.property.Property.getPropertyName(property));
LambdaFunction transform = ((PurePropertyMapping) propertyMapping)._transform();
FunctionType fType = (FunctionType) processorSupport.function_getFunctionType(transform);
Validator.validate(transform, (ValidatorState) state, matcher, processorSupport);
GenericType expressionGenericType = fType._returnType();
GenericType propertyGenericType = ((Property) ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport))._genericType();
Multiplicity expressionMultiplicity = fType._returnMultiplicity();
Multiplicity propertyMultiplicity = ((Property) ImportStub.withImportStubByPass(propertyMapping._propertyCoreInstance(), processorSupport))._multiplicity();
if (((PurePropertyMapping) propertyMapping)._transformerCoreInstance() != null) {
CoreInstance propertyRawType = ImportStub.withImportStubByPass(propertyGenericType._rawTypeCoreInstance(), processorSupport);
EnumerationMapping transformer = (EnumerationMapping) ImportStub.withImportStubByPass(((PurePropertyMapping) propertyMapping)._transformerCoreInstance(), processorSupport);
if (!propertyRawType.equals(transformer._enumeration())) {
throw new PureCompilationException(propertyMapping.getSourceInformation(), "Property : [" + property._name() + "] is of type : [" + PackageableElement.getUserPathForPackageableElement(propertyRawType) + "] but enumeration mapping : [" + transformer._name() + "] is defined on enumeration : [" + PackageableElement.getUserPathForPackageableElement(transformer._enumeration()) + "].");
}
} else if (ImportStub.withImportStubByPass(propertyGenericType._rawTypeCoreInstance(), processorSupport) instanceof DataType) {
if (!org.finos.legend.pure.m3.navigation.generictype.GenericType.isGenericCompatibleWith(expressionGenericType, propertyGenericType, processorSupport)) {
String valTypeString = org.finos.legend.pure.m3.navigation.generictype.GenericType.print(expressionGenericType, false, processorSupport);
String propertyTypeString = org.finos.legend.pure.m3.navigation.generictype.GenericType.print(propertyGenericType, false, processorSupport);
if (valTypeString.equals(propertyTypeString)) {
valTypeString = org.finos.legend.pure.m3.navigation.generictype.GenericType.print(expressionGenericType, true, processorSupport);
propertyTypeString = org.finos.legend.pure.m3.navigation.generictype.GenericType.print(propertyGenericType, true, processorSupport);
}
throw new PureCompilationException(((RichIterable<ValueSpecification>) ((PurePropertyMapping) propertyMapping)._transform()._expressionSequence()).toList().get(0).getSourceInformation(), "Type Error: '" + valTypeString + "' not a subtype of '" + propertyTypeString + "'");
}
} else {
Mapping mapping = (Mapping) ImportStub.withImportStubByPass(classMapping._parentCoreInstance(), processorSupport);
SetImplementation setImplementation = org.finos.legend.pure.m2.dsl.mapping.Mapping.getClassMappingById(mapping, propertyMapping._targetSetImplementationId(), processorSupport);
if (setImplementation == null) {
throw new PureCompilationException(propertyMapping.getSourceInformation(), "The set implementation '" + propertyMapping._targetSetImplementationId() + "' is unknown in the mapping '" + mapping.getName() + "'");
}
Type srcClass = setImplementation instanceof PureInstanceSetImplementation ? (Type) ImportStub.withImportStubByPass(((PureInstanceSetImplementation) setImplementation)._srcClassCoreInstance(), processorSupport) : null;
Type expRawType = (Type) ImportStub.withImportStubByPass(expressionGenericType._rawTypeCoreInstance(), processorSupport);
if (srcClass != null && srcClass != expRawType) {
throw new PureCompilationException(((RichIterable<ValueSpecification>) ((PurePropertyMapping) propertyMapping)._transform()._expressionSequence()).toList().get(0).getSourceInformation(), "Type Error: '" + PackageableElement.getUserPathForPackageableElement(srcClass) + "' is not '" + PackageableElement.getUserPathForPackageableElement(expRawType) + "'");
}
}
if (!((PurePropertyMapping) propertyMapping)._explodeProperty() && !org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.subsumes(propertyMultiplicity, expressionMultiplicity)) {
throw new PureCompilationException(((RichIterable<ValueSpecification>) transform._expressionSequence()).toList().get(0).getSourceInformation(), "Multiplicity Error ' The property '" + org.finos.legend.pure.m3.navigation.property.Property.getPropertyName(propertyMapping._propertyCoreInstance()) + "' has a multiplicity range of " + org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(propertyMultiplicity) + " when the given expression has a multiplicity range of " + org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(expressionMultiplicity));
}
}
// TODO add this validation once violations have been removed
// if (requiredProperties.notEmpty())
// {
// StringBuilder message = new StringBuilder("The following required properties for ");
// _Class.print(message, mappedClass, true);
// message.append(" are not mapped: ");
// requiredProperties.toSortedList().appendString(message, ", ");
// throw new PureCompilationException(classMapping.getSourceInformation(), message.toString());
// }
}
Aggregations