Search in sources :

Example 1 with StringCoreInstance

use of org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance in project legend-pure by finos.

the class RelationalOperationElementProcessor method processJoinTreeNode.

static void processJoinTreeNode(JoinTreeNode joinTreeNode, CoreInstance implementation, Matcher matcher, ProcessorState state, ModelRepository repository, ProcessorSupport processorSupport) {
    String joinName = joinTreeNode._joinName();
    Database database = (Database) ImportStub.withImportStubByPass(joinTreeNode._databaseCoreInstance(), processorSupport);
    if (database == null) {
        throw new PureCompilationException(joinTreeNode.getSourceInformation(), "The system can't figure out which database to use.");
    }
    PostProcessor.processElement(matcher, database, state, processorSupport);
    CoreInstance joinType = joinTreeNode._joinTypeCoreInstance();
    if (joinType != null) {
        StringCoreInstance joinTypeString = (StringCoreInstance) joinType;
        String type = "INNER".equals(joinTypeString.getValue()) ? "INNER" : "LEFT_OUTER";
        Enumeration joinTypeEnumeration = (Enumeration) processorSupport.package_getByUserPath(M2RelationalPaths.JoinType);
        Enum joinTypeEnumInstance = (Enum) org.finos.legend.pure.m3.navigation.enumeration.Enumeration.findEnum(joinTypeEnumeration, type);
        if (joinTypeEnumInstance == null) {
            throw new PureCompilationException(joinTreeNode.getSourceInformation(), "The enum value '" + type + "' can't be found in the enumeration " + PackageableElement.getUserPathForPackageableElement(joinTypeEnumeration, "::"));
        }
        joinTreeNode._joinTypeCoreInstance(joinTypeEnumInstance);
    }
    Join join = findJoin(joinTreeNode, database, joinName, processorSupport);
    joinTreeNode._join(join);
    PropertyMappingsImplementation owner = joinTreeNode._setMappingOwner();
    if (owner == null && implementation != null) {
        joinTreeNode._setMappingOwner((PropertyMappingsImplementation) implementation);
    }
    for (TreeNode child : joinTreeNode._childrenData()) {
        processJoinTreeNode((JoinTreeNode) child, implementation, matcher, state, repository, processorSupport);
    }
}
Also used : Enum(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum) Enumeration(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration) TreeNode(org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.TreeNode) JoinTreeNode(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode) Database(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database) StringCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Join(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.Join) RelationalOperationElementWithJoin(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElementWithJoin) StringCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance) PropertyMappingsImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMappingsImplementation) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 2 with StringCoreInstance

use of org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance in project legend-pure by finos.

the class FromJson method execute.

@Override
public CoreInstance execute(ListIterable<? extends CoreInstance> params, final Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, final Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, final VariableContext variableContext, final CoreInstance functionExpressionToUseInStack, final Profiler profiler, final InstantiationContext instantiationContext, final ExecutionSupport executionSupport, final Context context, final ProcessorSupport processorSupport) throws PureExecutionException {
    final SourceInformation si = functionExpressionToUseInStack.getSourceInformation();
    Class startingClass = (Class) Instance.getValueForMetaPropertyToOneResolved(params.get(1), M3Properties.values, processorSupport);
    CoreInstance config = Instance.getValueForMetaPropertyToOneResolved(params.get(2), M3Properties.values, processorSupport);
    String typeKeyName = ((StringCoreInstance) config.getValueForMetaPropertyToOne("typeKeyName")).getValue();
    Map<String, Class> keyLookup = new UnifiedMap<String, Class>();
    for (CoreInstance o : config.getValueForMetaPropertyToMany("typeLookup")) {
        keyLookup.put(o.getValueForMetaPropertyToOne("first").getName(), (Class) _Package.getByUserPath(o.getValueForMetaPropertyToOne("second").getName(), functionExecution.getProcessorSupport()));
    }
    Boolean failOnUnknownProperties = ((BooleanCoreInstance) config.getValueForMetaPropertyToOne("failOnUnknownProperties")).getValue();
    final ConstraintsOverride constraintsOverride = (ConstraintsOverride) config.getValueForMetaPropertyToOne("constraintsHandler");
    String jsonText = PrimitiveUtilities.getStringValue(Instance.getValueForMetaPropertyToOneResolved(params.get(0), M3Properties.values, processorSupport));
    return JsonDeserializer.fromJson(jsonText, startingClass, new JsonDeserializationContext(new JsonDeserializationCache(), si, processorSupport, typeKeyName, keyLookup, failOnUnknownProperties, new ObjectFactory() {

        @Override
        public <T extends Any> T newObject(Class<T> clazz, Map<String, RichIterable<?>> properties) {
            CoreInstance instance = FromJson.this.repository.newEphemeralAnonymousCoreInstance(functionExpressionToUseInStack.getSourceInformation(), clazz);
            for (Entry<String, RichIterable<?>> eachKeyValue : properties.entrySet()) {
                FastList<CoreInstance> values = new FastList<>();
                for (Object eachValue : eachKeyValue.getValue()) {
                    if (eachValue instanceof String) {
                        values.add(FromJson.this.repository.newStringCoreInstance((String) eachValue));
                    } else if (eachValue instanceof Boolean) {
                        values.add(FromJson.this.repository.newBooleanCoreInstance((Boolean) eachValue));
                    } else if (eachValue instanceof Integer) {
                        values.add(FromJson.this.repository.newIntegerCoreInstance((int) eachValue));
                    } else if (eachValue instanceof Long) {
                        values.add(FromJson.this.repository.newIntegerCoreInstance((long) eachValue));
                    } else if (eachValue instanceof BigDecimal) {
                        values.add(FromJson.this.repository.newDecimalCoreInstance((BigDecimal) eachValue));
                    } else if (eachValue instanceof Double || eachValue instanceof Number) {
                        values.add(FromJson.this.repository.newFloatCoreInstance(BigDecimal.valueOf((Double) eachValue)));
                    } else if (eachValue instanceof Year || eachValue instanceof YearMonth) {
                        values.add(FromJson.this.repository.newDateCoreInstance((PureDate) eachValue));
                    } else if (eachValue instanceof StrictDate) {
                        values.add(FromJson.this.repository.newStrictDateCoreInstance((PureDate) eachValue));
                    } else if (eachValue instanceof DateTime || eachValue instanceof LatestDate || eachValue instanceof PureDate) {
                        values.add(FromJson.this.repository.newDateTimeCoreInstance((PureDate) eachValue));
                    } else if (eachValue instanceof InstanceValue) {
                        InstanceValue asInstanceValue = (InstanceValue) eachValue;
                        if (Measure.isUnitOrMeasureInstance(asInstanceValue, processorSupport)) {
                            values.add(asInstanceValue);
                        } else {
                            values.add((CoreInstance) asInstanceValue._values().getFirst());
                        }
                    } else if (eachValue instanceof EnumInstance) {
                        values.add((CoreInstance) eachValue);
                    } else {
                        throw new PureExecutionException(si, "Unknown type from output of JsonDeserializer for property: " + eachKeyValue.getKey());
                    }
                }
                Instance.setValuesForProperty(instance, eachKeyValue.getKey(), values, processorSupport);
            }
            DeserializationUtils.replaceReverseProperties(instance, processorSupport, si);
            CoreInstance override = processorSupport.newAnonymousCoreInstance(si, M3Paths.ConstraintsGetterOverride);
            if (constraintsOverride != null) {
                Instance.addValueToProperty(override, M3Properties.constraintsManager, constraintsOverride._constraintsManager(), processorSupport);
                Instance.addValueToProperty(instance, M3Properties.elementOverride, override, processorSupport);
            }
            CoreInstance value = ValueSpecificationBootstrap.wrapValueSpecification(instance, true, processorSupport);
            return (T) DefaultConstraintHandler.handleConstraints(clazz, value, si, functionExecution, resolvedTypeParameters, resolvedMultiplicityParameters, variableContext, functionExpressionToUseInStack, profiler, instantiationContext, executionSupport);
        }

        public <T extends Any> T newUnitInstance(CoreInstance propertyType, String unitTypeString, Number unitValue) {
            CoreInstance retrievedUnit = processorSupport.package_getByUserPath(unitTypeString);
            if (!processorSupport.type_subTypeOf(retrievedUnit, propertyType)) {
                throw new PureExecutionException("Cannot match unit type: " + unitTypeString + " as subtype of type: " + PackageableElement.getUserPathForPackageableElement(propertyType));
            }
            FastList<CoreInstance> params = new FastList<>();
            params.add(ValueSpecificationBootstrap.wrapValueSpecification(retrievedUnit, false, processorSupport));
            params.add(NumericUtilities.toPureNumberValueExpression(unitValue, false, repository, processorSupport));
            return (T) new NewUnit(repository, functionExecution).execute(params, resolvedTypeParameters, resolvedMultiplicityParameters, variableContext, functionExpressionToUseInStack, profiler, instantiationContext, executionSupport, context, processorSupport);
        }
    }));
}
Also used : UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) ConstraintsOverride(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ConstraintsOverride) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) Any(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Any) StrictDate(org.finos.legend.pure.m4.coreinstance.primitive.date.StrictDate) DateTime(org.finos.legend.pure.m4.coreinstance.primitive.date.DateTime) NewUnit(org.finos.legend.pure.runtime.java.interpreted.natives.core.lang.NewUnit) JsonDeserializationContext(org.finos.legend.pure.runtime.java.extension.external.json.shared.JsonDeserializationContext) ObjectFactory(org.finos.legend.pure.runtime.java.extension.external.shared.conversion.ObjectFactory) EnumInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.EnumInstance) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) FastList(org.eclipse.collections.impl.list.mutable.FastList) PureDate(org.finos.legend.pure.m4.coreinstance.primitive.date.PureDate) StringCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance) LatestDate(org.finos.legend.pure.m4.coreinstance.primitive.date.LatestDate) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) BigDecimal(java.math.BigDecimal) BooleanCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.BooleanCoreInstance) RichIterable(org.eclipse.collections.api.RichIterable) JsonDeserializationCache(org.finos.legend.pure.runtime.java.extension.external.json.shared.JsonDeserializationCache) Year(org.finos.legend.pure.m4.coreinstance.primitive.date.Year) YearMonth(org.finos.legend.pure.m4.coreinstance.primitive.date.YearMonth) StringCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance) BooleanCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.BooleanCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) Map(java.util.Map) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) MutableMap(org.eclipse.collections.api.map.MutableMap) ConstraintsOverride(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ConstraintsOverride)

Example 3 with StringCoreInstance

use of org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance in project legend-pure by finos.

the class RelationalOperationElementUnbind method cleanJoinTreeNode.

public static void cleanJoinTreeNode(JoinTreeNode joinTreeNode, ModelRepository modelRepository, ProcessorSupport processorSupport) throws PureCompilationException {
    if (joinTreeNode != null) {
        Shared.cleanUpReferenceUsage(joinTreeNode._databaseCoreInstance(), joinTreeNode, processorSupport);
        Shared.cleanImportStub(joinTreeNode._databaseCoreInstance(), processorSupport);
        joinTreeNode._joinRemove();
        joinTreeNode._aliasRemove();
        CoreInstance joinTypeCoreInstance = joinTreeNode._joinTypeCoreInstance();
        if (joinTypeCoreInstance instanceof Enum) {
            Enum joinType = (Enum) joinTypeCoreInstance;
            joinTreeNode._joinTypeRemove();
            StringCoreInstance joinTypeString = modelRepository.newStringCoreInstance_cached(joinType.getName());
            joinTreeNode._joinTypeCoreInstance(joinTypeString);
        }
        for (TreeNode child : joinTreeNode._childrenData()) {
            cleanJoinTreeNode((JoinTreeNode) child, modelRepository, processorSupport);
        }
    }
}
Also used : Enum(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum) JoinTreeNode(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode) TreeNode(org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.TreeNode) StringCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) StringCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance)

Example 4 with StringCoreInstance

use of org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance in project legend-pure by finos.

the class TraceSpan method execute.

@Override
public CoreInstance execute(ListIterable<? extends CoreInstance> params, Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, VariableContext variableContext, CoreInstance functionExpressionToUseInStack, Profiler profiler, InstantiationContext instantiationContext, ExecutionSupport executionSupport, Context context, ProcessorSupport processorSupport) {
    if (Instance.instanceOf(Instance.getValueForMetaPropertyToOneResolved(params.get(0), M3Properties.values, processorSupport), M3Paths.Nil, processorSupport)) {
        throw new PureExecutionException(functionExpressionToUseInStack.getSourceInformation(), "Evaluate can't take an instance of Nil as a function");
    }
    // add check to disable tracing - use isRegistered()
    CoreInstance functionToApplyTo = Instance.getValueForMetaPropertyToOneResolved(params.get(0), M3Properties.values, processorSupport);
    String traceName = ((StringCoreInstance) Instance.getValueForMetaPropertyToManyResolved(params.get(1), M3Properties.values, processorSupport).getFirst()).getValue();
    if (!GlobalTracer.isRegistered()) {
        return this.functionExecution.executeLambda(LambdaFunctionCoreInstanceWrapper.toLambdaFunction(functionToApplyTo), Lists.mutable.<CoreInstance>empty(), resolvedTypeParameters, resolvedMultiplicityParameters, getParentOrEmptyVariableContext(variableContext), functionExpressionToUseInStack, profiler, instantiationContext, executionSupport);
    }
    return executeWithTrace(params, resolvedTypeParameters, resolvedMultiplicityParameters, variableContext, functionExpressionToUseInStack, profiler, instantiationContext, executionSupport, processorSupport, functionToApplyTo, traceName);
}
Also used : PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) StringCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance) MapCoreInstance(org.finos.legend.pure.runtime.java.interpreted.natives.core.collection.map.MapCoreInstance) BooleanCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.BooleanCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) StringCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance)

Aggregations

CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)4 StringCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance)4 TreeNode (org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.TreeNode)2 Enum (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum)2 JoinTreeNode (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.join.JoinTreeNode)2 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)2 BooleanCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.BooleanCoreInstance)2 BigDecimal (java.math.BigDecimal)1 Map (java.util.Map)1 RichIterable (org.eclipse.collections.api.RichIterable)1 MutableMap (org.eclipse.collections.api.map.MutableMap)1 FastList (org.eclipse.collections.impl.list.mutable.FastList)1 UnifiedMap (org.eclipse.collections.impl.map.mutable.UnifiedMap)1 PropertyMappingsImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMappingsImplementation)1 Any (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Any)1 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)1 ConstraintsOverride (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ConstraintsOverride)1 EnumInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.EnumInstance)1 Enumeration (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration)1 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)1