Author Topic: Labels using if and nvl  (Read 550 times)

nfigay

  • Newbie
  • *
  • Posts: 9
Labels using if and nvl
« on: September 05, 2021, 23:12:22 PM »
Hello,
I'm looking exemples for usage of if and nvl as mentioned for Archi 4.9.
Available somewhere?
BR
Nicolas

Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: Labels using if and nvl
« Reply #1 on: September 06, 2021, 09:05:44 AM »
Hi Nicolas,

I updated the wiki with some information on this - https://github.com/archimatetool/archi/wiki/Label-Expressions

This is something that JB very cleverly implemented. A good use case is to display an object's specialization name surrounded by angle brackets if it has one, else display nothing:

Code: [Select]
${if:${specialization}:<<${specialization}>>}
Regards,

Phil
« Last Edit: September 07, 2021, 09:18:16 AM by Phil Beauvoir »
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

nfigay

  • Newbie
  • *
  • Posts: 9
Re: Labels using if and nvl
« Reply #2 on: September 06, 2021, 11:11:22 AM »
Thank you very much, Phil.
It is effectively a very useful features, thanks to Jean Sebastien Baptiste for having implemented it :)
« Last Edit: September 08, 2021, 13:44:57 PM by Jean-Baptiste Sarrodie »

rchevallier

  • Active Member
  • ***
  • Posts: 76
Re: Labels using if and nvl
« Reply #3 on: September 08, 2021, 13:28:50 PM »
Very interesting and useful indeed

However because 4.9 incompatibility with coArchi conflicts (as far I understood), we may have a longer time before adopting 4.9 (waiting then for coArchi v2)
Would it be possible to mark the 4.9 new features in the documentation with a tag or notice (eg: "@since 4.9") ?
« Last Edit: September 08, 2021, 13:37:39 PM by Phil Beauvoir »

Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: Labels using if and nvl
« Reply #4 on: September 08, 2021, 13:38:26 PM »
Very interesting and useful indeed

However because 4.9 incompatibility with coArchi conflicts (as far I understood), we may have a longer time before adopting 4.9 (waiting then for coArchi v2)
Would it be possible to mark the 4.9 new features in the documentation with a tag or notice (eg: "@since 4.9") ?

Yes, I've added "(Since 4.9)" for the three new label expressions in the wiki.

Archi 4.9 will still work with coArchi, but you won't be able to see the difference when merging if Specializations are used.

(I accidentally edited your message instead of quoting it. I've put it back to how it was  :D)
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

rchevallier

  • Active Member
  • ***
  • Posts: 76
Re: Labels using if and nvl
« Reply #5 on: September 08, 2021, 15:07:56 PM »
Thanks Phil et again great product !

kimh

  • Newbie
  • *
  • Posts: 2
Re: Labels using if and nvl
« Reply #6 on: September 13, 2021, 22:29:40 PM »
Using Archi 4.8.1
I have tried for a while to use there 'if' expression but had no luck. The wiki defines a 'condition' but unsure of its syntax.
I have the following label:

${name}
${property:legacy}
${if: ${property:legacy}: (legacy)}

I want to display '(legacy)' if this property is set to 'true', otherwise it is missing. Or could be set to false.

With the above I get the following displayed:

Parts Service
true
${if: true: (legacy)}

Note the second line is only there to debug the value of the property. What I want is:

Parts Service
  (legacy)

Unclear if the syntax is correct, and then it would be good to test for property:legacy = false.

Thanks
Kim



Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: Labels using if and nvl
« Reply #7 on: September 13, 2021, 22:33:39 PM »
Hi Kim,

the "if" expression is implemented in Archi 4.9 which is in beta at the moment.

The wiki does mention "Since 4.9" for this expression.

The condition is not true/false but whether the evaluated expression is an empty string or not.

Regards,

Phil
« Last Edit: September 13, 2021, 22:36:07 PM by Phil Beauvoir »
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Alberto

  • Active Member
  • ***
  • Posts: 64
  • Twitter: @albertodmendoza
Re: Labels using if and nvl
« Reply #8 on: September 14, 2021, 14:21:20 PM »
Quote
The condition is not true/false but whether the evaluated expression is an empty string or not.

I'm no programmer or philosopher, but wouldn't then "ifEmpty" or "isEmpty" be a more appropriate term for this function? 

At least it would be consistent with other languages that do have different functions for evaluating for empty/undefined/null vs logic. 

Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: Labels using if and nvl
« Reply #9 on: September 14, 2021, 14:38:14 PM »
Quote
The condition is not true/false but whether the evaluated expression is an empty string or not.

I'm no programmer or philosopher, but wouldn't then "ifEmpty" or "isEmpty" be a more appropriate term for this function? 

At least it would be consistent with other languages that do have different functions for evaluating for empty/undefined/null vs logic.

It would have to be "ifNotEmpty", but that seems rather long-winded.
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Jean-Baptiste Sarrodie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 716
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: Labels using if and nvl
« Reply #10 on: September 14, 2021, 14:49:25 PM »
Hi,

Jumping in...

It would have to be "ifNotEmpty", but that seems rather long-winded.

Yes, that's the main reason.

The condition is not true/false but whether the evaluated expression is an empty string or not.

It shouldn't be complicated to also make it consider "0" and "false" as false value. BTW, that's how StringTemplate works (primarily based on string being null/empty, but for the same reasons decided to also accept 0/false). In such case a string with only spaces should also be seen as empty.

@Phil: I can submit a patch if you want.

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: Labels using if and nvl
« Reply #11 on: September 14, 2021, 14:56:03 PM »
> @Phil: I can submit a patch if you want.

OK, but I think it would be easy to check for 0 and "false" so I might look at it. But...doesn't this negate the true meaning of "empty value"? Suppose someone sets 0 or false and wants the existing behaviour?
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Jean-Baptiste Sarrodie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 716
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: Labels using if and nvl
« Reply #12 on: September 14, 2021, 16:07:43 PM »
Hi,

But...doesn't this negate the true meaning of "empty value"? Suppose someone sets 0 or false and wants the existing behaviour?

Well, until we publish Archi 4.9, there's no "existing behavior" :-)

TBH, while first thinking about this "if" expression, I thought it would be useful to also check for 0/false but simply didn't implement it.

I don't see much real life use-cases where someone would have "0" or "false" value somewhere and really want to know if this is empty or not (and "nvl" might still be helpful in this context). But I do see real life use-cases where someone has some "boolean" properties and want to adjust the label based on them.

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: Labels using if and nvl
« Reply #13 on: September 14, 2021, 16:12:04 PM »
But I do see real life use-cases where someone has some "boolean" properties and want to adjust the label based on them.


Then they could leave the property blank?
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Jean-Baptiste Sarrodie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 716
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: Labels using if and nvl
« Reply #14 on: September 14, 2021, 19:27:45 PM »
Hi,

Then they could leave the property blank?

That's not user friendly. For example, if I have a "Is Critical?" property on Application Components, then when publishing my model in HTML so that non architects can have access to it, seing such property name with no value is not an option as people expect to read yes/no or true/false.

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate