template-archive icon indicating copy to clipboard operation
template-archive copied to clipboard

Conditional Ergo Expression fails when contained within a {{#with}} and {{#ulist}}

Open martinhalford opened this issue 4 years ago • 1 comments

Describe the bug

This could be user error but I think there's a bug when using a conditional Ergo expression inside a complex model.

Here is the model....

enum State {
  o ACT
  o NSW
  o NT
  o SA
  o QLD
  o TAS
  o VIC
  o WA 
}

concept VendorPerson {
  o Party party
}

concept Address {
  o String street
  o String suburb
  o String postCode
  o String lotSectionNumber optional
  o State stateTerritory
}

participant Party extends AccordParty {
  o String fullName
  o String email
  o String mobile
  o String ABN
  o Address address
}

asset MyContract extends AccordContract {
  o Party agent
  o VendorPerson[] vendorPersons
}

Here is the grammar....

#### AGENT

{{#with agent}}
{{fullName}}\
{{#with address}}{{street}}, {{suburb}}, {{stateTerritory}} {{postCode}}{{/with}}\
email: {{email}}\
mobile: {{mobile}}\
{{%
    if length(agent.ABN) > 0
    then "ABN: " ++ agent.ABN
    else ""
%}}
{{/with}}

#### VENDOR(S)  

{{#ulist vendorPersons}}
{{#with party}}
{{fullName}} (Private Individual)\
{{#with address}}{{street}}, {{suburb}}, {{stateTerritory}} {{postCode}}{{/with}}\
email: {{email}}\
mobile: {{mobile}}\
{{%
    if length(party.ABN) > 0
    then "ABN: " ++ party.ABN
    else ""
%}}
{{/with}}
{{/ulist}}

The following data.json was used as test data.

{
    "$class": "org.accordproject.ulist_party.MyContract",
    "contractId": "1faHJLoIRxQphIRoXxjpZZZsyEi",
    "agent": {
        "$class": "org.accordproject.ulist_party.Party",
        "fullName": "Peter Parker",
        "email": "[email protected]",
        "mobile": "0432 232323",
        "address": {
            "$class": "org.accordproject.ulist_party.Address",
            "street": "335-339 Camberwell Rd.",
            "suburb": "Camberwell",
            "postCode": "3142",
            "stateTerritory": "VIC"
        },
        "ABN": "",
        "partyId": "1faHNZ0ZHPdomxjge22rj6rj7MK"
    },
    "vendorPersons": [
        {
            "$class": "org.accordproject.ulist_party.VendorPerson",
            "party": {
                "fullName": "Jack Walnut",
                "partyId": "1faHQ7sXpJbyVXsKt7FVIxB1NDv",
                "email": "[email protected]",
                "mobile": "0432 123456",
                "ABN": "12 345 678 900",
                "address": {
                    "$class": "org.accordproject.ulist_party.Address",
                    "street": "335-339 Camberwell Rd.",
                    "suburb": "Camberwell",
                    "postCode": "3142",
                    "stateTerritory": "VIC"
                }
            }
        },
        {
            "$class": "org.accordproject.ulist_party.VendorPerson",
            "party": {
                "fullName": "Frank N Furter",
                "partyId": "1faHQ7sXpJbyVXsKt7FVIxB1NDv",
                "email": "[email protected]",
                "mobile": "0432 987654",
                "ABN": "",
                "address": {
                    "$class": "org.accordproject.ulist_party.Address",
                    "street": "335-339 Camberwell Rd.",
                    "suburb": "Camberwell",
                    "postCode": "3142",
                    "stateTerritory": "VIC"
                }
            }
        } 
    ]
}

All of the above were used as inputs to the following draft command. $> cicero draft --template . --data ./data.json --output ./text/sample.md --unquoteVariables

Observed behaviour

The first Ergo expression (i.e. AGENT) works fine and renders the following markdown.

#### AGENT

Peter Parker\
335-339 Camberwell Rd., Camberwell, VIC 3142\
email: [email protected]\
mobile: 0432 232323\

However, the second Ergo expression (i.e. VENDORS) throws an error...

error: Type error (at file formula_393cac54e12a308db70b7c356580f67850c5469e9085161768f68d9eba5c581e line 2 col 14). The field `party' does not exist in type `{agent: Party, contractId: String, parties: ~org.accordproject.cicero.contract.AccordParty[]?, vendorPersons: VendorPerson[] ..}'
    if length(party.ABN) > 0

Expected behavior

Expected the following markdown...

#### AGENT

Peter Parker\
335-339 Camberwell Rd., Camberwell, VIC 3142\
email: [email protected]\
mobile: 0432 232323\

#### VENDOR(S)
-  Jack Walnut (Private Individual)\
   335-339 Camberwell Rd., Camberwell, VIC 3142\
   email: [email protected]\
   mobile: 0432 123456\
   ABN: 12 345 678 900\
   
-  Frank N Furter (Private Individual)\
   335-339 Camberwell Rd., Camberwell, VIC 3142\
   email: [email protected]\
   mobile: 0432 987654\

Version

$ cicero --version
0.21.8

ZIP Archive

ulist_party.zip

martinhalford avatar Sep 29 '20 09:09 martinhalford

I am having the exact same issue Martin.

I note that it is possible to access some of the desired data by addressing a top level key (for example toString(vendorPersons) using your data above). This will spit out an string version of the object you are trying to address. However, I have not been able to access nested values within that top level object (for example toString(vendorPerson.party) does not work).

Interestingly, toString(vendorPerson[0]) does work.

All a bit above my paygrade but thought this might help.

OliverTod avatar Dec 20 '20 21:12 OliverTod