Skip to content

Commit

Permalink
use pretty render for showcase test to match studio (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari committed Nov 13, 2023
1 parent 4cc3fa6 commit a1655b3
Show file tree
Hide file tree
Showing 7 changed files with 579 additions and 55 deletions.
43 changes: 39 additions & 4 deletions showcases/data/Function/Activator - Service Jar/code.pure
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ Mapping mapping::m2m::Firm_Person
domain::Person: Pure
{
~src domain::S_Person
firstName: $src.fullName->substring(0, $src.fullName->indexOf(' ')),
lastName: $src.fullName->substring($src.fullName->indexOf(' ') + 1, $src.fullName->length())
firstName: $src.fullName->substring(
0,
$src.fullName->indexOf(' ')
),
lastName: $src.fullName->substring(
$src.fullName->indexOf(' ') + 1,
$src.fullName->length()
)
}
domain::Firm: Pure
{
Expand All @@ -105,7 +111,25 @@ Mapping mapping::m2m::Firm_Person
[
test_1
(
query: |domain::Firm.all()->graphFetch(#{domain::Firm{legalName,employees{firstName}}}#)->serialize(#{domain::Firm{legalName,employees{firstName}}}#);
query: |domain::Firm.all()->graphFetch(
#{
domain::Firm{
legalName,
employees{
firstName
}
}
}#
)->serialize(
#{
domain::Firm{
legalName,
employees{
firstName
}
}
}#
);
data:
[
<Object, JSON, domain::S_Firm, '[{"employees":[{"fullName":"Road Runner"},{"fullName":"Wile Coyote"}],"legalName":"ACME Corp."},{"employees":[{"fullName":"Jake Sullivan"},{"fullName":"Mike Wazwoski"}],"legalName":"Monsters Inc."}]'>
Expand Down Expand Up @@ -142,7 +166,18 @@ Mapping mapping::relational::Firm_Person
[
test_1
(
query: |domain::Firm.all()->project([x|$x.legalName, x|$x.employees.firstName, x|$x.employees.lastName], ['Legal Name', 'Employees/First Name', 'Employees/Last Name']);
query: |domain::Firm.all()->project(
[
x: domain::Firm[1]|$x.legalName,
x: domain::Firm[1]|$x.employees.firstName,
x: domain::Firm[1]|$x.employees.lastName
],
[
'Legal Name',
'Employees/First Name',
'Employees/Last Name'
]
);
data:
[
<Relational, SQL, database::h2,
Expand Down
180 changes: 166 additions & 14 deletions showcases/data/Model/Build a data model/code.pure
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,18 @@ Class _01_basic::Product
{
name: String[1];
classification: _01_basic::ProductClassification[0..1];
cusip() {$this.synonyms->filter(s|$s.type == _01_basic::ProductSynonymType.CUSIP)->toOne().name}: String[1];
isin() {$this.synonyms->filter(s|$s.type == _01_basic::ProductSynonymType.ISIN)->toOne().name}: String[1];
sedol() {$this.synonyms->filter(s|$s.type == _01_basic::ProductSynonymType.SEDOL)->toOne().name}: String[1];
cusip() {$this.synonyms->filter(
s: _01_basic::Synonym[1]|$s.type ==
_01_basic::ProductSynonymType.CUSIP
)->toOne().name}: String[1];
isin() {$this.synonyms->filter(
s: _01_basic::Synonym[1]|$s.type ==
_01_basic::ProductSynonymType.ISIN
)->toOne().name}: String[1];
sedol() {$this.synonyms->filter(
s: _01_basic::Synonym[1]|$s.type ==
_01_basic::ProductSynonymType.SEDOL
)->toOne().name}: String[1];
}

Class _01_basic::TradeEvent
Expand Down Expand Up @@ -235,12 +244,21 @@ Class _01_basic::Trade
product: _01_basic::Product[0..1];
account: _01_basic::Account[0..1];
events: _01_basic::TradeEvent[*];
productIdentifier() {if($this.product->isNotEmpty(), |$this.product->toOne().name, |'Unknown')}: String[1];
eventsByDate(date: Date[1]) {$this.events->filter(e|$e.eventDate == $date)}: _01_basic::TradeEvent[*];
productIdentifier() {if(
$this.product->isNotEmpty(),
|$this.product->toOne().name,
|'Unknown'
)}: String[1];
eventsByDate(date: Date[1]) {$this.events->filter(
e: _01_basic::TradeEvent[1]|$e.eventDate ==
$date
)}: _01_basic::TradeEvent[*];
tradeDateEvent() {$this.eventsByDate($this.tradeDate->toOne())->toOne()}: _01_basic::TradeEvent[1];
tradeDataEventType() {$this.tradeDateEvent.eventType}: String[1];
initiator() {$this.tradeDateEvent.initiator}: _01_basic::Trader[0..1];
latestEventDate() {$this.events->map(e|$e.eventDate)->sort()->reverse()->at(0)}: StrictDate[1];
latestEventDate() {$this.events->map(
e: _01_basic::TradeEvent[1]|$e.eventDate
)->sort()->reverse()->at(0)}: StrictDate[1];
}

Class _01_basic::Account
Expand All @@ -267,14 +285,36 @@ Class {meta::pure::profiles::doc.doc = 'must pass date for isin/cusip/sedol now.
{
name: String[1];
classification: _01_basic::ProductClassification[1];
cusip(businessDate: StrictDate[1]) {$this.synonyms($businessDate)->filter(s|$s.type == _01_basic::ProductSynonymType.CUSIP)->toOne().name}: String[1];
isin(businessDate: StrictDate[1]) {$this.synonyms($businessDate)->filter(s|$s.type == _01_basic::ProductSynonymType.ISIN)->toOne().name}: String[1];
sedol(businessDate: StrictDate[1]) {$this.synonyms($businessDate)->filter(s|$s.type == _01_basic::ProductSynonymType.SEDOL)->toOne().name}: String[1];
cusip(businessDate: StrictDate[1]) {$this.synonyms($businessDate)->filter(
s: _02_advanced::SynonymStereoTyped[1]|$s.type ==
_01_basic::ProductSynonymType.CUSIP
)->toOne().name}: String[1];
isin(businessDate: StrictDate[1]) {$this.synonyms($businessDate)->filter(
s: _02_advanced::SynonymStereoTyped[1]|$s.type ==
_01_basic::ProductSynonymType.ISIN
)->toOne().name}: String[1];
sedol(businessDate: StrictDate[1]) {$this.synonyms($businessDate)->filter(
s: _02_advanced::SynonymStereoTyped[1]|$s.type ==
_01_basic::ProductSynonymType.SEDOL
)->toOne().name}: String[1];
}

Class {meta::pure::profiles::doc.doc = 'use tags to add metadata.'} _02_advanced::AccountWithConstraints extends _01_basic::Account
[
tradesNotDoubleBooked: $this->project([a|$a.trades.id], ['tradeId'])->groupBy('tradeId', 'count'->agg(x|$x, y|$y->count()))->filter(t|$t.getInteger('count') > 1)->tdsRows()->isEmpty(),
tradesNotDoubleBooked: $this->project(
[
a: _02_advanced::AccountWithConstraints[1]|$a.trades.id
],
['tradeId']
)->groupBy(
'tradeId',
'count'->agg(
x: meta::pure::tds::TDSRow[1]|$x,
y: meta::pure::tds::TDSRow[*]|$y->count()
)
)->filter(
t: meta::pure::tds::TDSRow[1]|$t.getInteger('count') > 1
)->tdsRows()->isEmpty(),
noTradesAfterCloseDate: true
]
{
Expand Down Expand Up @@ -341,7 +381,35 @@ Mapping _03_modelToModelMapping::simpleModelToModelMapping
[
test_1
(
query: |_01_basic::Product.all()->graphFetchChecked(#{_01_basic::Product{name,classification{description,type},synonyms{type,name}}}#)->serialize(#{_01_basic::Product{name,classification{description,type},synonyms{type,name}}}#);
query: |_01_basic::Product.all()->graphFetchChecked(
#{
_01_basic::Product{
name,
classification{
description,
type
},
synonyms{
type,
name
}
}
}#
)->serialize(
#{
_01_basic::Product{
name,
classification{
description,
type
},
synonyms{
type,
name
}
}
}#
);
data:
[
<Object, JSON, _03_modelToModelMapping::S_Product, '{"name":"Product1","classification":{"type":"type1","description":"Product classification of type 1"},"synonym":[{"type":"C","name":"C1"}]}'>
Expand All @@ -350,7 +418,35 @@ Mapping _03_modelToModelMapping::simpleModelToModelMapping
),
test_2
(
query: |_01_basic::Product.all()->graphFetchChecked(#{_01_basic::Product{name,classification{type,description},synonyms{name,type}}}#)->serialize(#{_01_basic::Product{name,classification{type,description},synonyms{name,type}}}#);
query: |_01_basic::Product.all()->graphFetchChecked(
#{
_01_basic::Product{
name,
classification{
type,
description
},
synonyms{
name,
type
}
}
}#
)->serialize(
#{
_01_basic::Product{
name,
classification{
type,
description
},
synonyms{
name,
type
}
}
}#
);
data:
[
<Object, JSON, _03_modelToModelMapping::S_Product, '{"name":"Product2","classification":{"type":"type2","description":"Classification of type2"},"synonym":[{"type":"I","name":"I1"}]}'>
Expand Down Expand Up @@ -406,7 +502,35 @@ Mapping _03_modelToModelMapping::unionMapping
[
test_1
(
query: |_01_basic::Product.all()->graphFetchChecked(#{_01_basic::Product{name,synonyms{name,type},classification{type,description}}}#)->serialize(#{_01_basic::Product{name,synonyms{name,type},classification{type,description}}}#);
query: |_01_basic::Product.all()->graphFetchChecked(
#{
_01_basic::Product{
name,
synonyms{
name,
type
},
classification{
type,
description
}
}
}#
)->serialize(
#{
_01_basic::Product{
name,
synonyms{
name,
type
},
classification{
type,
description
}
}
}#
);
data:
[
<Object, JSON, _03_modelToModelMapping::S_Product, '{"name":"Product1","classification":{"type":"type1","description":"Product of type1"},"synonym":[{"type":"C","name":"C1"},{"type":"I","name":"I1"}]}'>
Expand All @@ -415,7 +539,35 @@ Mapping _03_modelToModelMapping::unionMapping
),
test_2
(
query: |_01_basic::Product.all()->graphFetchChecked(#{_01_basic::Product{name,classification{type,description},synonyms{name,type}}}#)->serialize(#{_01_basic::Product{name,classification{type,description},synonyms{name,type}}}#);
query: |_01_basic::Product.all()->graphFetchChecked(
#{
_01_basic::Product{
name,
classification{
type,
description
},
synonyms{
name,
type
}
}
}#
)->serialize(
#{
_01_basic::Product{
name,
classification{
type,
description
},
synonyms{
name,
type
}
}
}#
);
data:
[
<Object, JSON, _03_modelToModelMapping::S_Product, '{"name":"Product2","classification":{"type":"type2","description":"Product of classification type2"},"synonym":[{"type":"S","name":"S1"}]}'>
Expand Down
44 changes: 42 additions & 2 deletions showcases/data/Store/Model Store/Mapping/service/basic/code.pure
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,27 @@ Service mapping::FirmService
autoActivateUpdates: true;
execution: Single
{
query: |model::target::_Firm.all()->graphFetch(#{model::target::_Firm{myLegalName,name,employees{fullName}}}#)->serialize(#{model::target::_Firm{myLegalName,name,employees{fullName}}}#);
query: |model::target::_Firm.all()->graphFetch(
#{
model::target::_Firm{
myLegalName,
name,
employees{
fullName
}
}
}#
)->serialize(
#{
model::target::_Firm{
myLegalName,
name,
employees{
fullName
}
}
}#
);
mapping: mapping::ModelToModelMapping;
runtime: mapping::FirmRuntime;
}
Expand Down Expand Up @@ -120,7 +140,27 @@ Mapping mapping::ModelToModelMapping
[
FirmSuite:
{
function: |model::target::_Firm.all()->graphFetch(#{model::target::_Firm{employees{fullName},name,myLegalName}}#)->serialize(#{model::target::_Firm{employees{fullName},name,myLegalName}}#);
function: |model::target::_Firm.all()->graphFetch(
#{
model::target::_Firm{
employees{
fullName
},
name,
myLegalName
}
}#
)->serialize(
#{
model::target::_Firm{
employees{
fullName
},
name,
myLegalName
}
}#
);
tests:
[
AppleData:
Expand Down
Loading

0 comments on commit a1655b3

Please sign in to comment.