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()));
}
}
}
}
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;
}
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());
}
}
}
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);
}
}
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);
}
}
Aggregations