DPB
DPB

Reputation: 23

In a Mule custom connector, is it possible to use a value provider within the elements in a list parameter?

I'm currently developing a custom connector for use in Mule api flows. One of the operations of this custom connector, "chooseMembers2", has a parameter called "members" which is a "List<String>"; in Anypoint Studio, the UI for this connector renders like this:

Choose members 2 UI

The "Teamid" field is a drop-down that uses a value provider

When I add a member, the UI for it is a pop-up that looks like this:

Member UI pop-up

Is it possible to link a value provider to the "Memberid" field so a drop-down can be used to choose that field for each member added to the "Members" list?

EDIT

Here is the code from the "Choose Members 2" operation:

@MediaType(MediaType.APPLICATION_PLAIN)
    public String chooseMembers2(@Config WUITTeamsMessagesConfiguration configuration, 
                                @Connection WUITTeamsMessagesConnection connection,
                                @OfValues(WUITTeamsMessagesTeamsValueProvider.class)
                                String teamid,
                                List<String> members)
    {
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < members.size(); i++)
        {
            sb.append(members.get(i) + "\n");
        }
        
        return sb.toString();
    }

The "teamid" parameter uses a value provider, "WUITTeamsMessagesTeamsValueProvider", so it renders as a drop-down.

Here is that value provider:

public class WUITTeamsMessagesTeamsValueProvider implements ValueProvider {

    @Connection
    WUITTeamsMessagesConnection connection;
    
    @Config
    WUITTeamsMessagesConfiguration config;
    
    @Override
    public Set<Value> resolve() throws ValueResolvingException {

        String teams = connection.callWebHook(config.getWebHookURL() + "&operation=get_teams", "");
        JSONArray jArr = new JSONArray(teams);
        
        int count = jArr.length();
        
        Map<String, String> valueMap = new HashMap<>();
        for(int i = 0; i < count; i++)
        {
            JSONObject item = (JSONObject) jArr.get(i);
            valueMap.put(item.getString("ID"), item.getString("Name"));
        }
        
        return ValueBuilder.getValuesFor(valueMap);
        
    }

}

I also have a value provider that receives the "teamid" from the teams provider and returns a list of members associated with that team:

public class WUITTeamsMessagesTeamMembersValueProvider implements ValueProvider {

    @Parameter
    String teamid;
    
    @Connection
    WUITTeamsMessagesConnection connection;
    
    @Config
    WUITTeamsMessagesConfiguration config;
    
    @Override
    public Set<Value> resolve() throws ValueResolvingException {

        String channels = connection.callWebHook(config.getWebHookURL() + "&operation=get_team_members&TeamID=" + teamid, "");
        JSONArray jArr = new JSONArray(channels);
        
        int count = jArr.length();
        
        Map<String, String> valueMap = new HashMap<>();
        for(int i = 0; i < count; i++)
        {
            JSONObject item = (JSONObject) jArr.get(i);
            valueMap.put(item.getString("ID"), item.getString("FullName"));
        }
        
        return ValueBuilder.getValuesFor(valueMap);
        
    }

}

If my operation were to use a "String" for the members parameter, and use the @OfValues annotation to link it to the members provider, the runtime successfully links the teamid to the member provider and the UI populates the member drop-down with members associated with the team. The problem is, that set-up would only allow the user to select one member per instance of the connector; if possible, I want the user to be able to select multiple members, but still get the value-provided dropdown each time they add a member to the connector's list.

Upvotes: 0

Views: 88

Answers (0)

Related Questions