flogo icon indicating copy to clipboard operation
flogo copied to clipboard

check for 'undefined' in mapping and condition expressions

Open ecarlier-tibco opened this issue 6 years ago • 15 comments

I'm submitting a ... (check one with "x")

[] bug report => search github for a similar issue or PR before submitting
[x] feature request
[] support request
[] general question

Expected behavior: In Object structure, some attributes may not be present and mapping or condition logic may defer depending on the presence or not of those attributes. This goes in pair with ability to have if ... then ... else statement in conditions and mapping expressions

What is the motivation / use case for changing the behavior? Some application require this especially as soon as you have payloads with optional parameters.

ecarlier-tibco avatar Jun 12 '18 13:06 ecarlier-tibco

@ecarlier-tibco We already have this feature implemented. to check if the field undefine or empty please use $xxxx.attribute == nil. try ternary expression if you want if .. then.

Such as: $activity[rest2].body.field1 != nil ? "field1 not empty " : "field1 empty"

lixingwang avatar Jun 13 '18 19:06 lixingwang

@ecarlier-tibco did this work for you?

mellistibco avatar Jun 27 '18 14:06 mellistibco

sorry had not the time to test it yet will do asap

Eric

On Wed, Jun 27, 2018 at 4:13 PM, Matt Ellis [email protected] wrote:

@ecarlier-tibco https://github.com/ecarlier-tibco did this work for you?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TIBCOSoftware/flogo/issues/295#issuecomment-400686632, or mute the thread https://github.com/notifications/unsubscribe-auth/ASzNY0mH1XZ_EWhGTOC8lLLTCRGZCknlks5uA5MGgaJpZM4UkaMS .

--

Eric Carlier, Office of the CTO, EMEA M : +33 6 10 81 44 02 O : +33 1 44 51 78 87 E : [email protected] TIBCO Software, 25 rue Balzac, 75008 Paris, FRANCE

http://goog_685059704 [image: TIBCO NOW] http://now.tibco.com/

ecarlier-tibco avatar Jun 27 '18 14:06 ecarlier-tibco

it seems to work except that the web ui does not accept this syntax but works in cli

Cheers Eric

On Wed, Jun 27, 2018 at 4:20 PM, Eric Carlier [email protected] wrote:

sorry had not the time to test it yet will do asap

Eric

On Wed, Jun 27, 2018 at 4:13 PM, Matt Ellis [email protected] wrote:

@ecarlier-tibco https://github.com/ecarlier-tibco did this work for you?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TIBCOSoftware/flogo/issues/295#issuecomment-400686632, or mute the thread https://github.com/notifications/unsubscribe-auth/ASzNY0mH1XZ_EWhGTOC8lLLTCRGZCknlks5uA5MGgaJpZM4UkaMS .

--

Eric Carlier, Office of the CTO, EMEA M : +33 6 10 81 44 02 O : +33 1 44 51 78 87 E : [email protected] TIBCO Software, 25 rue Balzac, 75008 Paris, FRANCE

http://goog_685059704 [image: TIBCO NOW] http://now.tibco.com/

--

Eric Carlier, Office of the CTO, EMEA M : +33 6 10 81 44 02 O : +33 1 44 51 78 87 E : [email protected] TIBCO Software, 25 rue Balzac, 75008 Paris, FRANCE

http://goog_685059704 [image: TIBCO NOW] http://now.tibco.com/

ecarlier-tibco avatar Jun 27 '18 14:06 ecarlier-tibco

cool, thanks. @fcastill can you take a look at the webui part?

mellistibco avatar Jun 27 '18 14:06 mellistibco

but it seems to only work with string. I tried with an array parameter, and also a number parameter, and I could not get it to work

Eric

On Wed, Jun 27, 2018 at 4:44 PM, Eric Carlier [email protected] wrote:

it seems to work except that the web ui does not accept this syntax but works in cli

Cheers Eric

On Wed, Jun 27, 2018 at 4:20 PM, Eric Carlier [email protected] wrote:

sorry had not the time to test it yet will do asap

Eric

On Wed, Jun 27, 2018 at 4:13 PM, Matt Ellis [email protected] wrote:

@ecarlier-tibco https://github.com/ecarlier-tibco did this work for you?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TIBCOSoftware/flogo/issues/295#issuecomment-400686632, or mute the thread https://github.com/notifications/unsubscribe-auth/ASzNY0mH1XZ_EWhGTOC8lLLTCRGZCknlks5uA5MGgaJpZM4UkaMS .

--

Eric Carlier, Office of the CTO, EMEA M : +33 6 10 81 44 02 O : +33 1 44 51 78 87 E : [email protected] TIBCO Software, 25 rue Balzac, 75008 Paris, FRANCE

http://goog_685059704 [image: TIBCO NOW] http://now.tibco.com/

--

Eric Carlier, Office of the CTO, EMEA M : +33 6 10 81 44 02 O : +33 1 44 51 78 87 E : [email protected] TIBCO Software, 25 rue Balzac, 75008 Paris, FRANCE

http://goog_685059704 [image: TIBCO NOW] http://now.tibco.com/

--

Eric Carlier, Office of the CTO, EMEA M : +33 6 10 81 44 02 O : +33 1 44 51 78 87 E : [email protected] TIBCO Software, 25 rue Balzac, 75008 Paris, FRANCE

http://goog_685059704 [image: TIBCO NOW] http://now.tibco.com/

ecarlier-tibco avatar Jun 27 '18 16:06 ecarlier-tibco

@ecarlier-tibco Can you share your flogo.json with number and array?

lixingwang avatar Jun 27 '18 16:06 lixingwang

Here it is flogo.json.zip

ecarlier-tibco avatar Jun 27 '18 17:06 ecarlier-tibco

@ecarlier-tibco

  1. For your array expression which is invalid. ["ddd"] not an valid literal. please correct to $.content.ParamArray2 != nil ? $.content.ParamArray2 : "[EMPTY]" or remove []
  2. For number: so far we are not support literal negtive number in expression. Could you please create GH issue?

For #2, you can change -1 to 0 ~ MAX to unblock you

lixingwang avatar Jun 27 '18 19:06 lixingwang

@lixingwang

  1. I tried both options you mentioned. It works ok if I pass an array param in my test request body. But I don't, and then get into the "EMPTY" case, then the subsequent loop for logging fails (likely as it does not recognize an array ?)
  2. Created https://github.com/TIBCOSoftware/flogo/issues/301

ecarlier-tibco avatar Jun 28 '18 08:06 ecarlier-tibco

@ecarlier-tibco Yes, for iterator, the iterate must be a number or array, it cannot iterate over a string, like "empty". It is expected behavior.

lixingwang avatar Jun 28 '18 15:06 lixingwang

Yes but my point is that my application is expecting an array. If it is not provided by the input request, I want to set an empty array, or an array with a specific value, by default, so that my app does not fail because the array is not there

Le 28 juin 2018 à 17:51, Tracy Li [email protected] a écrit :

@ecarlier-tibco Yes, for iterator, the iterate must be a number or array, it cannot iterate over a string, like "empty". It is expected behavior.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ecarlier-tibco avatar Jun 28 '18 16:06 ecarlier-tibco

@ecarlier-tibco Got you. but now you are using expression $.content.ParamArray2 != nil ? $.content.ParamArray2 : "EMPTY" it will return string "EMPTY" while $.content.ParamArray2 undefine.

we cannot have a default value because the value comes from your mapping.

You can try with this expression: $.content.ParamArray2 != nil ? $.content.ParamArray2 : "[]".

lixingwang avatar Jun 28 '18 16:06 lixingwang

Ok the empty array works fine : $.content.ParamArray2 != nil ? $.content.ParamArray2 : "[]" But the one you mentioned initially, setting a default array with at least one element, does not work : $.content.ParamArray2 != nil ? $.content.ParamArray2 : "[EMPTY]"

Thanks

ecarlier-tibco avatar Jun 29 '18 08:06 ecarlier-tibco

@ecarlier-tibco Yes. we do not support that. in the future we will provide an array function which allows the user to create an array, such as $.content.ParamArray2 != nil ? $.content.ParamArray2 : array.create("empty")

lixingwang avatar Jun 29 '18 15:06 lixingwang