Search in sources :

Example 1 with MetadataKeyBuilder

use of org.mule.runtime.api.metadata.MetadataKeyBuilder in project mule by mulesoft.

the class InvokeKeysResolver method buildServiceKey.

private MetadataKey buildServiceKey(ForwardingSoapClient connection, WebServiceDefinition ws) {
    String serviceId = ws.getServiceId();
    SoapMetadataResolver resolver = connection.getSoapClient(serviceId).getMetadataResolver();
    MetadataKeyBuilder key = newKey(serviceId).withDisplayName(ws.getFriendlyName());
    List<String> excludedOperations = ws.getExcludedOperations();
    resolver.getAvailableOperations().stream().filter(ope -> !excludedOperations.contains(ope)).forEach(ope -> key.withChild(newKey(ope).withDisplayName(NameUtils.titleize(ope))));
    return key.build();
}
Also used : MultilevelMetadataKeyBuilder.newKey(org.mule.runtime.module.extension.api.metadata.MultilevelMetadataKeyBuilder.newKey) ImmutableSet(com.google.common.collect.ImmutableSet) NameUtils(org.mule.runtime.extension.api.util.NameUtils) Set(java.util.Set) WebServiceDefinition(org.mule.runtime.extension.api.soap.WebServiceDefinition) MetadataKeyBuilder(org.mule.runtime.api.metadata.MetadataKeyBuilder) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) List(java.util.List) ConnectionException(org.mule.runtime.api.connection.ConnectionException) MetadataContext(org.mule.runtime.api.metadata.MetadataContext) ForwardingSoapClient(org.mule.runtime.module.extension.soap.internal.runtime.connection.ForwardingSoapClient) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) TypeKeysResolver(org.mule.runtime.api.metadata.resolving.TypeKeysResolver) SoapMetadataResolver(org.mule.runtime.soap.api.client.metadata.SoapMetadataResolver) MetadataKeyBuilder(org.mule.runtime.api.metadata.MetadataKeyBuilder) SoapMetadataResolver(org.mule.runtime.soap.api.client.metadata.SoapMetadataResolver)

Example 2 with MetadataKeyBuilder

use of org.mule.runtime.api.metadata.MetadataKeyBuilder in project mule by mulesoft.

the class MetadataKeyIdObjectResolver method reconstructKeyFromType.

/**
 * Given a {@link Object} representing the resolved value for a {@link MetadataKey}, generates the {@link MetadataKey} object.
 *
 * @param resolvedKey
 * @return {@link MetadataKey} reconstructed from the resolved object key
 * @throws MetadataResolvingException
 */
MetadataKey reconstructKeyFromType(Object resolvedKey, ReflectionCache reflectionCache) throws MetadataResolvingException {
    if (isKeyLess() || resolvedKey == null) {
        return new NullMetadataKey();
    }
    if (keyParts.size() == 1) {
        return newKey(valueOf(resolvedKey)).build();
    }
    MetadataKeyBuilder rootBuilder = null;
    MetadataKeyBuilder childBuilder = null;
    for (ParameterModel p : keyParts) {
        try {
            if (p.getModelProperty(DeclaringMemberModelProperty.class).isPresent()) {
                MetadataKeyBuilder fieldBuilder = getKeyFromField(resolvedKey, p.getModelProperty(DeclaringMemberModelProperty.class).get(), reflectionCache);
                if (rootBuilder == null) {
                    rootBuilder = fieldBuilder;
                    childBuilder = rootBuilder;
                } else {
                    childBuilder.withChild(fieldBuilder);
                    childBuilder = fieldBuilder;
                }
            }
        } catch (Exception e) {
            throw new MetadataResolvingException("Could not construct Metadata Key part for parameter " + p.getName(), FailureCode.INVALID_METADATA_KEY, e);
        }
    }
    return rootBuilder != null ? rootBuilder.build() : new NullMetadataKey();
}
Also used : DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) MetadataKeyBuilder(org.mule.runtime.api.metadata.MetadataKeyBuilder) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException)

Example 3 with MetadataKeyBuilder

use of org.mule.runtime.api.metadata.MetadataKeyBuilder in project mule by mulesoft.

the class MetadataKeysDelegate method cloneAndEnrichMetadataKey.

/**
 * Given a {@link MetadataKey}, this is navigated recursively cloning each {@link MetadataKey} of the tree structure creating a
 * {@link MultilevelMetadataKeyBuilder} and adding the partName of each {@link MetadataKey} found.
 *
 * @param key              {@link MetadataKey} to be cloned and enriched
 * @param partOrderMapping {@link Map} that contains the mapping of the name of each part of the {@link MetadataKey}
 * @param level            the current level of the part of the {@link MetadataKey} to be cloned and enriched
 * @return a {@link MetadataKeyBuilder} with the cloned and enriched keys
 */
private MetadataKeyBuilder cloneAndEnrichMetadataKey(MetadataKey key, Map<Integer, ParameterModel> partOrderMapping, int level) {
    final MetadataKeyBuilder keyBuilder = newKey(key.getId(), partOrderMapping.get(level).getName()).withDisplayName(key.getDisplayName());
    key.getProperties().forEach(keyBuilder::withProperty);
    key.getChilds().forEach(childKey -> keyBuilder.withChild(cloneAndEnrichMetadataKey(childKey, partOrderMapping, level + 1)));
    return keyBuilder;
}
Also used : MultilevelMetadataKeyBuilder(org.mule.runtime.module.extension.api.metadata.MultilevelMetadataKeyBuilder) MetadataKeyBuilder(org.mule.runtime.api.metadata.MetadataKeyBuilder)

Aggregations

MetadataKeyBuilder (org.mule.runtime.api.metadata.MetadataKeyBuilder)3 MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 List (java.util.List)1 Set (java.util.Set)1 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)1 MetadataContext (org.mule.runtime.api.metadata.MetadataContext)1 MetadataKey (org.mule.runtime.api.metadata.MetadataKey)1 TypeKeysResolver (org.mule.runtime.api.metadata.resolving.TypeKeysResolver)1 NullMetadataKey (org.mule.runtime.extension.api.metadata.NullMetadataKey)1 WebServiceDefinition (org.mule.runtime.extension.api.soap.WebServiceDefinition)1 NameUtils (org.mule.runtime.extension.api.util.NameUtils)1 MultilevelMetadataKeyBuilder (org.mule.runtime.module.extension.api.metadata.MultilevelMetadataKeyBuilder)1 MultilevelMetadataKeyBuilder.newKey (org.mule.runtime.module.extension.api.metadata.MultilevelMetadataKeyBuilder.newKey)1 DeclaringMemberModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty)1 ForwardingSoapClient (org.mule.runtime.module.extension.soap.internal.runtime.connection.ForwardingSoapClient)1 SoapMetadataResolver (org.mule.runtime.soap.api.client.metadata.SoapMetadataResolver)1