Operator use "Connection" parameter to populate other parameters

klinklin Member Posts: 9 Contributor I
edited November 2018 in Help

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

  • eyey Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, RMResearcher, Member Posts: 21 RM Research
    Solution Accepted

    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

Answers

  • tftemmetftemme Administrator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, RMResearcher, Member Posts: 164 RM Research

    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:

     

    ParameterType type = new ParameterTypeCategory(<PARAMETER_SPECIFIC_ITEM_LIST>,"",<list_for_specific_item>,0,false);
    type.registerDependencyCondition(new EqualStringCondition(this, <PARAMETER_CONNECTION>, false, <specific_item>));
    types.add(type)

    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

  • klinklin Member Posts: 9 Contributor I

    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?

  • tftemmetftemme Administrator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, RMResearcher, Member Posts: 164 RM Research

    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

  • klinklin Member Posts: 9 Contributor I

    Thank you again, Fabian. @ey, I would be most grateful for any insight you can give me.

  • jczogallajczogalla Employee, Member Posts: 144 RM Engineering

    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:

    // single table dropdown
    type = new ParameterTypeAttribute(PARAMETER_TABLE_SELECTION, "The table that should be read", mdProvider, true) {

    @Override
    public Vector<String> getAttributeNames() {
    return tableNames;
    }
    };

    In Combination with an observer on the getParameters() object, you can then update this list. It might look something like this:

    public YourOperator(...)
    super(...)
    ...
    getParameters().addObserver((obs, arg) -> {
    if (arg.equals("your_parameter_key") {
    return;
    }
    updateParameterList(getParameter("your_parameter_key"));
    }, false);

    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

  • jczogallajczogalla Employee, Member Posts: 144 RM Engineering

    That's so much better than my suggestion! ( ;) ) Thanks, @ey!

  • klinklin Member Posts: 9 Contributor I

    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

Sign In or Register to comment.