All Downloads are FREE. Search and download functionalities are using the official Maven repository.

core.pure.runtime.runtimeExtension.pure Maven / Gradle / Ivy

There is a newer version: 4.57.1
Show newest version
// Copyright 2020 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import meta::core::runtime::*;
import meta::pure::store::*;
import meta::pure::mapping::*;
import meta::external::store::model::*;

Class meta::core::runtime::EngineRuntime extends Runtime
{
  mappings: Mapping[*];
// NOTE: we don't need to process the rest of engine runtime for now
}

Class meta::pure::runtime::PackageableRuntime extends PackageableElement
{
   runtimeValue: meta::core::runtime::EngineRuntime[1];
}

Class meta::pure::runtime::PackageableConnection extends PackageableElement
{

}


Class meta::core::runtime::ExtendedExecutionContext extends meta::pure::runtime::ExecutionContext
{
   constraintsManager : Function<{Any[1]->Any[1]}>[0..1];
}


function meta::core::runtime::runtimeEquality(a:Runtime[0..1], b:Runtime[0..1], extensions : meta::pure::extension::Extension[*]):Boolean[1]
{
   if($a->isEmpty() && $b->isEmpty(),
       |true,
       |if($a->isNotEmpty() && $b->isNotEmpty(),
           | let r = $a.connectionStores->removeAll($b.connectionStores, { connA,connB | $connA.element==$connB.element && connectionEquality($connA.connection, $connB.connection, $extensions)});
             let r2 = $a.connectionStores->removeAll($r, { connA,connB | $connA.element==$connB.element && connectionEquality($connA.connection, $connB.connection, $extensions)});
             $r2->size() == $a.connectionStores->size();,
           |false));
}

function meta::core::runtime::connectionEquality(a:Connection[1], b:Connection[1], extensions : meta::pure::extension::Extension[*]):Boolean[1]
{
   //TODO  post processors are currently ignored in the equality

   if( $a->type() == $b->type(),
      |$a->match(
            $extensions.routerExtensions().connectionEquality->map(e | $e->eval($b))->concatenate([
                a:Connection[1]  | true
            ])->toOneMany()
       ),
      |false
   );
}

function meta::core::runtime::getConstraintsManager(exeCtx:meta::pure::runtime::ExecutionContext[1]):Function<{Any[1]->Any[1]}>[0..1]
{
   if ($exeCtx.enableConstraints->isNotEmpty() && $exeCtx.enableConstraints == false,
       |meta::pure::constraints::functions::noOpConstraintHandler_Any_1__Any_1_,
       |if ($exeCtx->instanceOf(ExtendedExecutionContext) && $exeCtx->cast(@ExtendedExecutionContext).constraintsManager->isNotEmpty(),
          |$exeCtx->cast(@ExtendedExecutionContext).constraintsManager->toOne(),
          |[]
       )
   );
}

function meta::core::runtime::connectionByElement(runtime:Runtime[1], store:Store[1]):Connection[1]
{
   assert($runtime.connectionStores->size() >= 1, | 'No connections were found in runtime.');

   if ($store->instanceOf(ModelStore),
       |let connections = $runtime.connectionStores->filter(c|$c.element->instanceOf(ModelStore)).connection;
        $connections->toOne($connections->size()->toString()+' connection(s) for "ModelStore" were found in the runtime. Expected 1 connection.');,
       |let connections = $runtime.connectionStores->filter(c|$c.element == $store).connection;
        //meta::pure::functions::asserts::assertSize($connection, 1, |$connection->size()->toString()+' connection(s) for store "'+$store.name->toOne()+'" were found in the runtime');
        if ($connections->size() == 0,
            | $runtime.connectionStores.connection->at(0),
            | $connections->toOne($connections->size()->toString()+' connection(s) for store "'+$store.name->toOne()+'" were found in the runtime. Expected 1 connection.')
        );
   );
}

function meta::core::runtime::connectionByElementFailSafe(runtime:Runtime[1], store:Store[1]):Connection[*]
{
  if ($store->instanceOf(ModelStore),
       |let connections = $runtime.connectionStores->filter(c|$c.element->instanceOf(ModelStore)).connection;,
       |let connections = $runtime.connectionStores->filter(c|$c.element == $store).connection;
   );
}

function meta::core::runtime::getMappingsFromRuntime(runtime:Runtime[0..1]):Mapping[*]
{
   if($runtime->isNotEmpty(),|$runtime.connectionStores->filter(c | $c.connection->instanceOf(ModelChainConnection)).connection->cast(@ModelChainConnection).mappings,|[]);
}

function meta::core::runtime::getRuntimeWithModelConnection(sourceClass:Class[1], inputs:Any[*]):Runtime[1]
{
   ^Runtime(
                            connectionStores = ^ConnectionStore(
                              element=^ModelStore(),
                              connection= ^ModelConnection(instances=newMap(pair($sourceClass, list($inputs))))));
}

function meta::core::runtime::getRuntimeWithModelQueryConnection(sourceClass:Class[1], binding:meta::external::format::shared::binding::Binding[1], input:Byte[*]):Runtime[1]
{
  ^Runtime(connectionStores = ^ConnectionStore(
                              element=^ModelStore(),
                              connection= ^ModelQueryConnection(instancesProvider=newMap(pair($sourceClass, {tree:meta::pure::graphFetch::RootGraphFetchTree[1] | $sourceClass->meta::external::format::shared::functions::internalize($binding, $input)->meta::pure::graphFetch::execution::graphFetch($tree)})))));
}

function meta::core::runtime::getRuntimeWithModelQueryConnection(sourceClass:Class[1], binding:meta::external::format::shared::binding::Binding[1], input:String[1]):Runtime[1]
{
  ^Runtime(connectionStores = ^ConnectionStore(
                              element=^ModelStore(),
                              connection= ^ModelQueryConnection(instancesProvider=newMap(pair($sourceClass, {tree:meta::pure::graphFetch::RootGraphFetchTree[1] | $sourceClass->meta::external::format::shared::functions::internalize($binding, $input)->meta::pure::graphFetch::execution::graphFetch($tree)})))));
}

function meta::core::runtime::getRuntimeWithModelQueryConnection(sourceClass:Class[1], contentType:String[1], input:Byte[*]):Runtime[1]
{
  ^Runtime(connectionStores = ^ConnectionStore(
                              element=^ModelStore(),
                              connection= ^ModelQueryConnection(instancesProvider=newMap(pair($sourceClass, {tree:meta::pure::graphFetch::RootGraphFetchTree[1] | $sourceClass->meta::external::format::shared::functions::internalize($contentType, $input)->meta::pure::graphFetch::execution::graphFetch($tree)})))));
}

function meta::core::runtime::getRuntimeWithModelQueryConnection(sourceClass:Class[1], contentType:String[1], input:String[1]):Runtime[1]
{
  ^Runtime(connectionStores = ^ConnectionStore(
                              element=^ModelStore(),
                              connection= ^ModelQueryConnection(instancesProvider=newMap(pair($sourceClass, {tree:meta::pure::graphFetch::RootGraphFetchTree[1] | $sourceClass->meta::external::format::shared::functions::internalize($contentType, $input)->meta::pure::graphFetch::execution::graphFetch($tree)})))));
}

// Function signature takes Any to incorporate both Runtime & PackageableRuntime
function meta::core::runtime::mergeRuntimes(runtimes:Any[1..*]):Runtime[1]
{
  $runtimes->forAll(r | $r->instanceOf(meta::pure::runtime::PackageableRuntime) || $r->instanceOf(Runtime));
  let updatedRuntimes = $runtimes->filter(r | $r->instanceOf(Runtime))->concatenate($runtimes->filter(r | $r->instanceOf(meta::pure::runtime::PackageableRuntime))->cast(@meta::pure::runtime::PackageableRuntime).runtimeValue)->cast(@Runtime);
  ^Runtime(connectionStores = $updatedRuntimes.connectionStores);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy