From 16ee9a3ad2ac2b960048f223bd35e154812dd207 Mon Sep 17 00:00:00 2001 From: kelly-thai <89568879+kelly-thai@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:00:00 -0500 Subject: [PATCH] stereotype and filter mapping projects (#826) --- .../Stereotypes/code.pure | 21 +++ .../Stereotypes/info.md | 12 +- .../Mapping/Joins/Filter Mapping/code.pure | 124 ++++++++++++++++++ .../Mapping/Joins/Filter Mapping/info.md | 7 + 4 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 showcases/data/Store/Relational Store/Mapping/Joins/Filter Mapping/code.pure create mode 100644 showcases/data/Store/Relational Store/Mapping/Joins/Filter Mapping/info.md diff --git a/showcases/data/Model/Leverage profiles in your model/Stereotypes/code.pure b/showcases/data/Model/Leverage profiles in your model/Stereotypes/code.pure index e69de29bb..cfd8fd7e5 100644 --- a/showcases/data/Model/Leverage profiles in your model/Stereotypes/code.pure +++ b/showcases/data/Model/Leverage profiles in your model/Stereotypes/code.pure @@ -0,0 +1,21 @@ +###Text +Text showcase::model::README +{ + type: markdown; + content: '---\ntitle: Leverage profiles in your model > Stereotypes\ndescription: This an example that shows how to use stereotypes in your data model\n---\n\nThis showcase show how stereotypes can be used in the data model. Stereotypes can be defined at both class level and property level. Stereotypes are used to add additional metadata to your models.\nYou can choose from the various types of stereotypes based on your use case. In this example, \'doc\' stereotype is used to mark the class as deprecated. In addition, the \'integerType\' stereotype is used on the \'age\' field to specify that it expects an Interger and not Long. \nFor more details, refer https://enghub.gs.com/alloy-platform/alloy-studio/docs/tutorials/create-foundational-data-model-elements#stereotypes. \n\nFor more custom use cases, you can create your own profile with custom stereotypes. Here we have create the Profile `showcase::model::CustomProfile` with a stereotype of `custom`.\nWe use this custom profile in the `introduction` derived property of Animal. '; +} + + +###Pure +Profile showcase::model::CustomProfile +{ + stereotypes: [custom]; +} + +Class <> showcase::model::Animal +{ + name: String[1]; + sound: String[1]; + <> age: Integer[1]; + <> introduction() {'Hi my name is ' + $this.name}: String[1]; +} diff --git a/showcases/data/Model/Leverage profiles in your model/Stereotypes/info.md b/showcases/data/Model/Leverage profiles in your model/Stereotypes/info.md index a13548811..2a5a02ffa 100644 --- a/showcases/data/Model/Leverage profiles in your model/Stereotypes/info.md +++ b/showcases/data/Model/Leverage profiles in your model/Stereotypes/info.md @@ -1,7 +1,11 @@ --- -title: Stereotypes -description: -development: true +title: Leverage profiles in your model > Stereotypes +description: This an example that shows how to use stereotypes in your data model --- -TODO: Some dummy description \ No newline at end of file +This showcase show how stereotypes can be used in the data model. Stereotypes can be defined at both class level and property level. Stereotypes are used to add additional metadata to your models. +You can choose from the various types of stereotypes based on your use case. In this example, 'doc' stereotype is used to mark the class as deprecated. In addition, the 'integerType' stereotype is used on the 'age' field to specify that it expects an Interger and not Long. +For more details, refer https://legend.finos.org/docs/tutorials/studio-profile#stereotype. + +For more custom use cases, you can create your own profile with custom stereotypes. Here we have create the Profile `showcase::model::CustomProfile` with a stereotype of `custom`. +We use this custom profile in the `introduction` derived property of Animal. \ No newline at end of file diff --git a/showcases/data/Store/Relational Store/Mapping/Joins/Filter Mapping/code.pure b/showcases/data/Store/Relational Store/Mapping/Joins/Filter Mapping/code.pure new file mode 100644 index 000000000..d79be312d --- /dev/null +++ b/showcases/data/Store/Relational Store/Mapping/Joins/Filter Mapping/code.pure @@ -0,0 +1,124 @@ +###Relational +Database showcase::stores::SimpleDB +( + Schema SimpleDBSchema + ( + Table Pets + ( + id INTEGER PRIMARY KEY, + pet_type VARCHAR(50), + pet_name VARCHAR(50) + ) + Table People + ( + id INTEGER PRIMARY KEY, + person_name VARCHAR(200), + pet_id INTEGER + ) + ) + + Join PersonPet(SimpleDBSchema.Pets.id = SimpleDBSchema.People.pet_id) + + Filter petDogFilter(SimpleDBSchema.Pets.pet_type = 'Dog') +) + + +###Text +Text showcase::README +{ + type: markdown; + content: '---\ntitle: Relational Mapping with Join and Filter showcase\ndescription: Showcase displaying a relational mapping with a join and a filter\n---\n\nIn this showcase, two tables (Pets and People) are joined and a filter condition is applied. A test case explaining the use case is added.\n\n'; +} + + +###Pure +Class showcase::models::Pet +{ + pet_name: String[0..1]; + pet_type: String[0..1]; + person_name: String[0..1]; +} + +Class showcase::models::Person +{ + person_name: String[0..1]; +} + + +###Mapping +Mapping showcase::mapping::PetMapping +( + showcase::models::Pet: Relational + { + ~filter [showcase::stores::SimpleDB]petDogFilter + ~primaryKey + ( + [showcase::stores::SimpleDB]SimpleDBSchema.Pets.id + ) + ~mainTable [showcase::stores::SimpleDB]SimpleDBSchema.Pets + pet_name: [showcase::stores::SimpleDB]SimpleDBSchema.Pets.pet_name, + pet_type: [showcase::stores::SimpleDB]SimpleDBSchema.Pets.pet_type, + person_name: [showcase::stores::SimpleDB]@PersonPet | [showcase::stores::SimpleDB]SimpleDBSchema.People.person_name + } + + testSuites: + [ + testSuite1: + { + function: |showcase::models::Pet.all()->filter( + x|$x.pet_type == 'Dog' +)->graphFetch( + #{ + showcase::models::Pet{ + person_name, + pet_name, + pet_type + } + }# +)->serialize( + #{ + showcase::models::Pet{ + person_name, + pet_name, + pet_type + } + }# +); + tests: + [ + test1: + { + data: + [ + showcase::stores::SimpleDB: + Relational + #{ + SimpleDBSchema.Pets: + 'id,pet_name,pet_type\n'+ + '1,Coco,Dog\n'+ + '2,Jojo,Cat\n'; + + SimpleDBSchema.People: + 'id,person_name,pet_id\n'+ + '1,Tom,1\n'+ + '2,Jim,2\n'; + }# + ]; + asserts: + [ + expectedAssertion: + EqualToJson + #{ + expected: + ExternalFormat + #{ + contentType: 'application/json'; + data: '{\n "person_name": "Tom",\n "pet_name": "Coco",\n "pet_type": "Dog"\n}'; + }#; + }# + ]; + } + ]; + } + ] +) diff --git a/showcases/data/Store/Relational Store/Mapping/Joins/Filter Mapping/info.md b/showcases/data/Store/Relational Store/Mapping/Joins/Filter Mapping/info.md new file mode 100644 index 000000000..f9ec130de --- /dev/null +++ b/showcases/data/Store/Relational Store/Mapping/Joins/Filter Mapping/info.md @@ -0,0 +1,7 @@ +--- +title: Relational Mapping with Join and Filter showcase +description: Showcase displaying a relational mapping with a join and a filter +--- + +In this showcase, two tables (Pets and People) are joined and a filter condition is applied. A test case explaining the use case is added. +