Search in sources :

Example 1 with PrimitiveType

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType in project legend-pure by finos.

the class ClassProjectionProcessor method validateDerivedProperties.

private static void validateDerivedProperties(RootRouteNode projectionSpec, ProcessorSupport processorSupport) {
    // we can only support derived properties which flatten relations to a primitive type. Qualified Properties are not supported.
    for (PropertyRouteNode derivedProperty : projectionSpec._children()) {
        if (derivedProperty instanceof ExistingPropertyRouteNode) {
            throw new PureCompilationException(derivedProperty.getSourceInformation(), String.format("Invalid projection specification. Found complex property '%s', only simple properties are allowed in a class projection.", derivedProperty._propertyName()));
        }
        CoreInstance derivedPropertyType = derivedProperty._type() == null ? null : ImportStub.withImportStubByPass(derivedProperty._type()._rawTypeCoreInstance(), processorSupport);
        if (!(derivedPropertyType instanceof DataType)) {
            throw new PureCompilationException(derivedProperty.getSourceInformation(), String.format("Invalid projection specification. Derived property '%s' should be of PrimitiveType.", derivedProperty._propertyName()));
        }
        ListIterable<? extends ValueSpecification> valueSpecifications = derivedProperty instanceof NewPropertyRouteNode ? ((NewPropertyRouteNode) derivedProperty)._specifications().toList() : Lists.immutable.<ValueSpecification>empty();
        if (valueSpecifications.size() != 1) {
            throw new PureCompilationException(derivedProperty.getSourceInformation(), "Invalid projection specification: derived property '" + derivedProperty._propertyName() + "' should have exactly 1 value specification, found " + valueSpecifications.size());
        }
        if (valueSpecifications.getFirst() instanceof FunctionExpression) {
            CoreInstance func = ImportStub.withImportStubByPass(((FunctionExpression) valueSpecifications.getFirst())._funcCoreInstance(), processorSupport);
            if (func != null && !(func instanceof Property) && Automap.getAutoMapExpressionSequence(valueSpecifications.getFirst()) == null) {
                throw new PureCompilationException(derivedProperty.getSourceInformation(), String.format("Invalid projection specification. Derived property '%s' should be a simple property.", derivedProperty._propertyName()));
            }
        }
    }
}
Also used : NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) PropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.PropertyRouteNode) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) ExistingPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.ExistingPropertyRouteNode) FunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) DataType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.DataType) NewPropertyRouteNode(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.treepath.NewPropertyRouteNode) AbstractProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.AbstractProperty) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 2 with PrimitiveType

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType in project legend-pure by finos.

the class JsonGenericAndAnyTypeSerialization method apply.

@Override
public Object apply(T pureObject, ConversionContext context) {
    JsonSerializationContext jsonSerializationContext = (JsonSerializationContext) context;
    if (pureObject instanceof CoreInstance) {
        Type type = (Type) jsonSerializationContext.getClassifier(pureObject);
        Conversion<T, Object> concreteConversion = (Conversion<T, Object>) jsonSerializationContext.getConversionCache().getConversion(type, jsonSerializationContext);
        if (type instanceof PrimitiveType) {
            return concreteConversion.apply((T) jsonSerializationContext.extractPrimitiveValue(pureObject), jsonSerializationContext);
        }
        return concreteConversion.apply(pureObject, jsonSerializationContext);
    }
    // so we need to explicitly convert it to String ourselves before handing over to JSON library
    if (pureObject instanceof PureDate) {
        return pureObject.toString();
    }
    return pureObject;
}
Also used : PrimitiveType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) PureDate(org.finos.legend.pure.m4.coreinstance.primitive.date.PureDate) PrimitiveType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType) Conversion(org.finos.legend.pure.runtime.java.extension.external.shared.conversion.Conversion)

Example 3 with PrimitiveType

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType in project legend-pure by finos.

the class TypeValidator method validatePrimitiveTypeGeneralizations.

private void validatePrimitiveTypeGeneralizations(PrimitiveType type, RichIterable<? extends Generalization> generalizations, ProcessorSupport processorSupport) throws PureCompilationException {
    Any anyClass = (Any) processorSupport.package_getByUserPath(M3Paths.Any);
    for (Generalization generalization : generalizations) {
        GenericType general = generalization._general();
        CoreInstance generalRawType = ImportStub.withImportStubByPass(general._rawTypeCoreInstance(), processorSupport);
        if ((generalRawType != anyClass) && !(generalRawType instanceof PrimitiveType)) {
            StringBuilder builder = new StringBuilder("Invalid generalization: ");
            PackageableElement.writeUserPathForPackageableElement(builder, type);
            builder.append(" cannot extend ");
            org.finos.legend.pure.m3.navigation.generictype.GenericType.print(builder, general, true, processorSupport);
            builder.append(" as it is not a PrimitiveType or Any");
            throw new PureCompilationException(type.getSourceInformation(), builder.toString());
        }
    }
}
Also used : GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) PrimitiveType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType) Generalization(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization) Any(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Any) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 4 with PrimitiveType

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType in project legend-engine by finos.

the class HelperServiceStoreClassMappingBuilder method validateTransformWithServiceParameterType.

private static boolean validateTransformWithServiceParameterType(Root_meta_external_store_service_metamodel_mapping_ServiceParameterMapping serviceParameterMapping, CompileContext context, SourceInformation sourceInformation) {
    Root_meta_external_store_service_metamodel_TypeReference typeReference = serviceParameterMapping._serviceParameter()._type();
    Type rawtype = serviceParameterMapping._transform()._expressionSequence().getLast()._genericType()._rawType();
    org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity multiplicity = serviceParameterMapping._transform()._expressionSequence().getLast()._multiplicity();
    org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity parameterMultiplicty;
    if (typeReference._list()) {
        parameterMultiplicty = context.pureModel.getMultiplicity("zeromany");
    } else {
        parameterMultiplicty = context.pureModel.getMultiplicity("one");
    }
    if (!org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.subsumes(parameterMultiplicty, multiplicity)) {
        throw new EngineException("Parameter multiplicity is not compatible with transform multiplicity - Multiplicity error: " + org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(parameterMultiplicty) + " doesn't subsumes " + org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(multiplicity), sourceInformation, EngineErrorType.COMPILATION);
    }
    if (typeReference instanceof Root_meta_external_store_service_metamodel_StringTypeReference) {
        return (rawtype instanceof PrimitiveType) && "String".equals(rawtype._name());
    } else if (typeReference instanceof Root_meta_external_store_service_metamodel_IntegerTypeReference) {
        return (rawtype instanceof PrimitiveType) && "Integer".equals(rawtype._name());
    } else if (typeReference instanceof Root_meta_external_store_service_metamodel_FloatTypeReference) {
        return (rawtype instanceof PrimitiveType) && "Float".equals(rawtype._name());
    } else if (typeReference instanceof Root_meta_external_store_service_metamodel_BooleanTypeReference) {
        return (rawtype instanceof PrimitiveType) && "Boolean".equals(rawtype._name());
    } else if (typeReference instanceof Root_meta_external_store_service_metamodel_ComplexTypeReference) {
        HelperModelBuilder.checkTypeCompatibility(context, ((Root_meta_external_store_service_metamodel_ComplexTypeReference) typeReference)._type(), rawtype, "Parameter Type is not compatible with transform type", sourceInformation);
        return true;
    } else {
        throw new EngineException("Unable to infer type for service parameter : " + serviceParameterMapping._serviceParameter()._name(), sourceInformation, EngineErrorType.COMPILATION);
    }
}
Also used : EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) PrimitiveType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType) 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) PrimitiveType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType)

Example 5 with PrimitiveType

use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType in project legend-pure by finos.

the class TestFunctionExecutionStart method testStartWithNotEnoughArguments.

@Test
public void testStartWithNotEnoughArguments() {
    compileTestSource("fromString.pure", "function testFn(s1:String[1], s2:String[1]):String[1] { $s1 + $s2 }");
    CoreInstance func = this.runtime.getFunction("testFn(String[1], String[1]):String[1]");
    Assert.assertNotNull(func);
    try {
        this.functionExecution.start(func, Lists.immutable.<CoreInstance>with());
    } catch (Exception e) {
        assertPureException(PureExecutionException.class, "Error executing the function:testFn(String[1], String[1]):String[1]. Mismatch between the number of function parameters (2) and the number of supplied arguments (0)\n", e);
    }
    try {
        this.functionExecution.start(func, Lists.immutable.with(ValueSpecificationBootstrap.newStringLiteral(this.repository, "string", this.processorSupport)));
    } catch (Exception e) {
        assertPureException(PureExecutionException.class, "Error executing the function:testFn(String[1], String[1]):String[1]. Mismatch between the number of function parameters (2) and the number of supplied arguments (1)\n" + "Anonymous_StripedId instance InstanceValue\n" + "    genericType(Property):\n" + "        Anonymous_StripedId instance GenericType\n" + "            rawType(Property):\n" + "                String instance PrimitiveType\n" + "    multiplicity(Property):\n" + "        PureOne instance PackageableMultiplicity\n" + "    values(Property):\n" + "        string instance String", e);
    }
}
Also used : PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) Test(org.junit.Test)

Aggregations

PrimitiveType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.PrimitiveType)9 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)9 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)4 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)4 Conversion (org.finos.legend.pure.runtime.java.extension.external.shared.conversion.Conversion)4 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)3 Map (java.util.Map)2 UnifiedMap (org.eclipse.collections.impl.map.mutable.UnifiedMap)2 Multiplicity (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity)2 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)2 Enumeration (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration)2 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)2 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)2 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)2 PureMap (org.finos.legend.pure.runtime.java.compiled.generation.processors.support.map.PureMap)2 MapConversion (org.finos.legend.pure.runtime.java.extension.external.shared.conversion.MapConversion)2 Test (org.junit.Test)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Objects (java.util.Objects)1