Operator use "Connection" parameter to populate other parameters
Hello!
I have an extension operator that takes a "Connection" parameter. Once the user selects the connection, I'd like to make a call to that connection and use the results to populate a second parameter's drop-down menu choices. Is this possible? It seems that all the parameter choices are initialized at once in getParameterTypes().
Best Answer
-
ey1 Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, RMResearcher, Member Posts: 21 RM Research
Hi @klin
You can certainly populate a parameter list by invoking a call to an API using the connection object selected by the user.
For this, you need to create a parameter of type ParameterTypeSuggestion and pass it an implementation of SuggestionProvider interface. In your implementation class, override the getSuggestions method. In this method, grab an instance of your connection's Configurable instance. You can do this by calling the ConfigurationManager.getInstance().lookup() method with your Configurable type_id and connection name.
Once you have the reference, you can invoke any API call your connection handling offers and return the results as List of Strings. In your case, that would be a list of languages (English, Spanish etc. whichever is supported). I would also suggest to maintain all client side calls in a separate connection class to keep Configurable class clean. In a similar fashion, you can get a handle on the connection object in your doWork() method to make any other calls on your API when the operator is executed. For all this to work, you will of course also need to register your Configurable in the PluginInit class of your extension, using ConfigurationManager.getInstance().register(new YourConfiguratorClass()) and your YourConfiguratorClass must override the getConfigurableClass() and getTypeId() methods. Please note that the TypeId must be a valid XML tag identifier and file name (use underscore, no spaces).
Hope that answers your question.
Best Regards,
Edwin
4
Answers
Hi @klin,
As far as I know this is not easily possible. As a workaround, you can create for each item in the collection of the "connection" parameter one new parameter and use:
to only show the parameter for the currently selected specific item. Of course depending on the length of your value list of the "connection" parameter, this may get a bit messy in the code (and in the documentation).
Hopes this helps,
Best regards,
Fabian
Hello @tftemme, thank you for the reply.
I am not sure how the workaround would function in my case. Specifically, once the connection is set up and selected, I need to send an API call to the specified URL which will return a list of languages that the operator supports (English, Spanish, German, etc.). Then, I'd like to populate a drop-down box for "Source language" using that list. Since the connection names are determined by the user, and I need to make a call rather than just taking its value, I don't think I can just use the dependency condition. Is there no way to trigger some action when the user selects the Connection?
You are right, I just misunderstood your setup, so my proposed workaround does not fit for your problem.
But @ey did something similar in one of our Research projects. So I tag him here, so that he can help you.
Best regards,
Fabian
Thank you again, Fabian. @ey, I would be most grateful for any insight you can give me.
Hi @klin,
you can add an Observer to your operator's Parameters instance.
I did this once in a bit of a hacky way, specifically I did this:
In Combination with an observer on the getParameters() object, you can then update this list. It might look something like this:
It is important then that you initialize everything that you need to create your ParameterTypes, otherwise there might be some NPEs flying around. I hope this helps!
Jan
That's so much better than my suggestion! ( ) Thanks, @ey!
Thanks to you both, @jczogalla and @ey! The ParameterTypeSuggestion was exactly what I needed. I'm now able to create all the functionality I need. I very much appreciate the help!
Karin