Search code examples
mulemule-studiomule-sdk

Mule SDK Problem - Unable to fetch keys for the metadata using @MetadataKeyId


I am using Mule SDK for developing a custom connector. I am working on fetching the necessary metadata. The following are the two snippets that i use: WeatherConnectrOperations.java:

public class WeatherConnectrOperations {

 public void select(@MetadataKeyId(RecordKeysResolver.class) String type) {
 }
}

RecordKeysResolver.java:

public class RecordKeysResolver implements TypeKeysResolver {

 @Override
 public String getCategoryName() {
     return "Records";
 }
 @Override
 public Set<MetadataKey> getKeys(MetadataContext context) throws MetadataResolvingException, ConnectionException {
     System.out.println("Hello");
     List<String> keyIds = Arrays.asList("Author_id", "BookList_id", "Book_id");
     HashSet<MetadataKey> keys = new HashSet<>();
     for (String id : keyIds) {
         MetadataKeyBuilder builder = MetadataKeyBuilder.newKey(id);
         builder.withDisplayName(StringUtils.removeEnd(id, "_id"));
         keys.add(builder.build());
     }
     return keys;
 }
}

My problem is that, the type field is not getting populated with the necessary keys

I am doing as per this document - https://docs.mulesoft.com/mule-sdk/1.1/metadata-keys


Solution

  • It's not mentioned in the documentation, but it seems that metadata keys won't get resolved unless there is a matching Input/OutputTypeResolver.

    Make sure that matching Input/OutputTypeResolver has the same CategoryName as KeyResolver and I also found that name of the variable should be the same in Operation method and Input/OutputTypeResolver.

    I guess the logic is that you don't need metadata key if you don't have metadata resolver. If you just need a dropdown list of values you can use Value Providers (https://docs.mulesoft.com/mule-sdk/1.1/value-providers)