Question

Download service - Choice (Multiple) published parameter with Tester


I'm trying to create a server app that allows users to select one (or more) values from a list in order to filter / select data for download as a CSV.

My workspace is a slightly more complex version of

Reader (Web Feature Service) ------> Tester (based on Published Parameter) --------> Writer (CSV)

And is designed to be run as a Server App where users can define the value(s) from a list to filter the data for download.

The Published Parameter is configured as "Choice (Multiple)"

I would expect the Tester to be able to work with the list provided from the User Parameter. However, Tester (using the "In" operator) requires values to be comma separated whereas "Choice (Multiple)" provides a whitespace separated list.

So I can't think of a way to offer users multiple choice values for downloading filtered data.

I've found some fairly old topics covering this, but I don't think the provided solutions will work adequately for a Server App. The ability to define the characters used as a separator when configuring the Tester or the User Parameter would make sense.

Any help gratefully received!

Gruff

For Reference:

 

https://knowledge.safe.com/questions/3754/settings-user-parameters-and-testing-with-multiple.html

10 replies

Userlevel 1
Badge +21

Is it an option to switch the test round? If the options were say, "United States" "United Kingdom" "France" this would work

Badge +2

Hi @gruffowenwcp,

Another option would be to bring the parameter value into an attribute where you can then replace the space with a comma and then you can leave the Tester as is. You could do this either using a StringReplacer or using the ReplaceString function in the Text Editor, please see example workspace attached.

choicereplace.fmw

 

Hi @gruffowenwcp,

Another option would be to bring the parameter value into an attribute where you can then replace the space with a comma and then you can leave the Tester as is. You could do this either using a StringReplacer or using the ReplaceString function in the Text Editor, please see example workspace attached.

choicereplace.fmw

 

Thanks Holly, and apologies for the delay in responding.

This approach looks promising, but unfortunately some of the values in the list include spaces as well. So the resulting string in the parameter fetcher looks like this:

 

 

"Isle of Anglesey" "Brecon NPA" Cardiff Denbighshire

Any suggestions much appreciated!

Is it an option to switch the test round? If the options were say, "United States" "United Kingdom" "France" this would work

Thanks ebygomm,

This does appear to work! Though, could you clarify whether this would be reliant on use of the Contains operator? And whether this could lead to false positives if I had two values containing the same string sequence?

e.g. If Parameter = "Isle of Anglesey" and I have two possible attributes values of "Isle of Anglesey" OR "Isle of Dogs", could the test pass both?

My initial testing suggests not, and would be happy to accept yours as the answer if you could confirm :)

Many thanks,

Tester_switch.fmw

Userlevel 1
Badge +21

Thanks ebygomm,

This does appear to work! Though, could you clarify whether this would be reliant on use of the Contains operator? And whether this could lead to false positives if I had two values containing the same string sequence?

e.g. If Parameter = "Isle of Anglesey" and I have two possible attributes values of "Isle of Anglesey" OR "Isle of Dogs", could the test pass both?

My initial testing suggests not, and would be happy to accept yours as the answer if you could confirm :)

Many thanks,

Tester_switch.fmw

It should only ever pass one or the other in that scenario, it would only be an issue if one value completely contained all another value, e.g. if you had values like

Bulldog

French Bulldog

German Shepherd

If the user chose the parameters French Bulldog and German Shepherd, the values that have just Bulldog would also be returned (hope that makes sense)

Userlevel 1
Badge +21

Thanks Holly, and apologies for the delay in responding.

This approach looks promising, but unfortunately some of the values in the list include spaces as well. So the resulting string in the parameter fetcher looks like this:

 

 

"Isle of Anglesey" "Brecon NPA" Cardiff Denbighshire

Any suggestions much appreciated!

If you wanted to go down this route, you could use the following regex in a stringreplacer to only replace spaces that fall outside of quotes

\s+(?=([^"]*"[^"]*")*[^"]*$)

It should only ever pass one or the other in that scenario, it would only be an issue if one value completely contained all another value, e.g. if you had values like

Bulldog

French Bulldog

German Shepherd

If the user chose the parameters French Bulldog and German Shepherd, the values that have just Bulldog would also be returned (hope that makes sense)

Thanks ebygomm. With that small caveat I'll accept the answer as it works in my use case. Though for others searching for the solution here, it may still remain a problem.

 

 

In the long run, it would be great if Safe could consider a more permanent solution :)

All the best,

Gruff

Userlevel 1
Badge +21

Thanks ebygomm. With that small caveat I'll accept the answer as it works in my use case. Though for others searching for the solution here, it may still remain a problem.

 

 

In the long run, it would be great if Safe could consider a more permanent solution :)

All the best,

Gruff

My other answer perhaps provides a more robust solution, I agree it would be nicer if it was more straightforward however. Have you suggested it as an idea?

If you wanted to go down this route, you could use the following regex in a stringreplacer to only replace spaces that fall outside of quotes

\s+(?=([^"]*"[^"]*")*[^"]*$)

ebygomm, just seen this after accepting your initial answer.

I don't have the time to test that this afternoon, but it looks like the most foolproof answer to me?

My other answer perhaps provides a more robust solution, I agree it would be nicer if it was more straightforward however. Have you suggested it as an idea?

Ok, thanks! Will check that out when I get more time behind the laptop (should be plenty of time for the next 6 months!!)

 

I'll take a look at suggesting it as an idea. Didn't want to assume that there wasn't a user solution before doing so.

 

 

For tidyness' sake, would it be worth editting your original (and accepted) answer to refer to Holly's answer and your more robust regex solution?

Reply