Search in sources :

Example 1 with PropertyMapping

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);
        }
    }
}
Also used : RelationalPropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping) OtherwiseEmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.OtherwiseEmbeddedRelationalInstanceSetImplementation) RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) RelationalPropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping) PropertyMappingsImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMappingsImplementation)

Example 2 with PropertyMapping

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);
        }
    }
}
Also used : OtherwiseEmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.OtherwiseEmbeddedRelationalInstanceSetImplementation) EmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation) OtherwiseEmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.OtherwiseEmbeddedRelationalInstanceSetImplementation) RelationalPropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping) RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) RelationalPropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping)

Example 3 with PropertyMapping

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;
}
Also used : Association(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) PureInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PureInstanceSetImplementation) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 4 with PropertyMapping

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.");
                }
            }
        }
    }
}
Also used : PureInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PureInstanceSetImplementation) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 5 with PropertyMapping

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());
// }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) PureInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PureInstanceSetImplementation) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) PurePropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) RichIterable(org.eclipse.collections.api.RichIterable) DataType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) Multiplicity(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity) PropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping) PurePropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) DataType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) PurePropertyMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PurePropertyMapping) PureInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PureInstanceSetImplementation) SetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Aggregations

PropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping)25 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)16 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)13 Mapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping)12 SetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)12 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)12 RelationalOperationElement (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement)11 PropertyMappingsImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMappingsImplementation)10 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)10 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)9 InstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.InstanceSetImplementation)8 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)8 RichIterable (org.eclipse.collections.api.RichIterable)7 EmbeddedRelationalInstanceSetImplementation (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation)7 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)6 MappingClass (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.MappingClass)6 RelationalPropertyMapping (org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalPropertyMapping)6 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)5 AggregationAwarePropertyMapping (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.AggregationAwarePropertyMapping)5 Root_meta_pure_metamodel_type_generics_GenericType_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl)5