Search in sources :

Example 1 with MetadataResult

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

the class MetadataExtensionFunctionalTestCase method getSuccessComponentDynamicMetadata.

private ComponentMetadataDescriptor<T> getSuccessComponentDynamicMetadata(MetadataKey key, BiConsumer<MetadataResult<ComponentMetadataDescriptor<T>>, MetadataKey> assertKeys) {
    MetadataResult<ComponentMetadataDescriptor<T>> componentMetadata = getComponentDynamicMetadata(key);
    String msg = componentMetadata.getFailures().stream().map(f -> "Failure: " + f.getMessage()).collect(joining(", "));
    assertThat(msg, componentMetadata.isSuccess(), is(true));
    assertKeys.accept(componentMetadata, key);
    return componentMetadata.get();
}
Also used : Arrays(java.util.Arrays) DSL_RESOLUTION(org.mule.test.module.extension.metadata.MetadataExtensionFunctionalTestCase.ResolutionType.DSL_RESOLUTION) PERSON(org.mule.test.metadata.extension.MetadataConnection.PERSON) Assert.assertThat(org.junit.Assert.assertThat) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) ExtensionsTestUtils(org.mule.test.module.extension.internal.util.ExtensionsTestUtils) Is.is(org.hamcrest.core.Is.is) ComponentMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) MetadataService(org.mule.runtime.api.metadata.MetadataService) Parameterized(org.junit.runners.Parameterized) NullMetadataKey(org.mule.runtime.extension.api.metadata.NullMetadataKey) ConnectableComponentModel(org.mule.runtime.api.meta.model.ConnectableComponentModel) Collection(java.util.Collection) Set(java.util.Set) SAN_FRANCISCO(org.mule.test.metadata.extension.resolver.TestMultiLevelKeyResolver.SAN_FRANCISCO) Message.of(org.mule.runtime.api.message.Message.of) Collectors.joining(java.util.stream.Collectors.joining) USA(org.mule.test.metadata.extension.resolver.TestMultiLevelKeyResolver.USA) METADATA_SERVICE_KEY(org.mule.runtime.api.metadata.MetadataService.METADATA_SERVICE_KEY) MetadataComponent(org.mule.runtime.api.metadata.resolving.MetadataComponent) TestMetadataResolverUtils.getMetadata(org.mule.test.metadata.extension.resolver.TestMetadataResolverUtils.getMetadata) Type(java.lang.reflect.Type) EXPLICIT_RESOLUTION(org.mule.test.module.extension.metadata.MetadataExtensionFunctionalTestCase.ResolutionType.EXPLICIT_RESOLUTION) OutputModel(org.mule.runtime.api.meta.model.OutputModel) MetadataType(org.mule.metadata.api.model.MetadataType) Matchers.containsString(org.hamcrest.Matchers.containsString) MetadataResult(org.mule.runtime.api.metadata.resolving.MetadataResult) AbstractExtensionFunctionalTestCase(org.mule.test.module.extension.AbstractExtensionFunctionalTestCase) AMERICA(org.mule.test.metadata.extension.resolver.TestMultiLevelKeyResolver.AMERICA) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) MultilevelMetadataKeyBuilder(org.mule.runtime.module.extension.api.metadata.MultilevelMetadataKeyBuilder) Location(org.mule.runtime.api.component.location.Location) BaseTypeBuilder(org.mule.metadata.api.builder.BaseTypeBuilder) Inject(javax.inject.Inject) RunnerDelegateTo(org.mule.test.runner.RunnerDelegateTo) BiConsumer(java.util.function.BiConsumer) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MetadataKeyBuilder.newKey(org.mule.runtime.api.metadata.MetadataKeyBuilder.newKey) Named(javax.inject.Named) Before(org.junit.Before) Typed(org.mule.runtime.api.meta.Typed) FailureCode(org.mule.runtime.api.metadata.resolving.FailureCode) Matchers.empty(org.hamcrest.Matchers.empty) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) CAR(org.mule.test.metadata.extension.MetadataConnection.CAR) MetadataKeysContainer(org.mule.runtime.api.metadata.MetadataKeysContainer) MetadataFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure) Matchers.containsString(org.hamcrest.Matchers.containsString) ComponentMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ComponentMetadataDescriptor)

Example 2 with MetadataResult

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

the class MetadataMediator method getMetadata.

/**
 * Resolves the {@link ComponentMetadataDescriptor} for the associated {@code context} using the component
 * {@link ParameterValueResolver} to resolve an object with the value of the {@link MetadataKey}.
 *
 * @param context current {@link MetadataContext} that will be used by the metadata resolvers.
 * @return Successful {@link MetadataResult} if the MetadataTypes are resolved without errors Failure {@link MetadataResult}
 *         when the Metadata retrieval of any element fails for any reason
 */
public MetadataResult<ComponentMetadataDescriptor<T>> getMetadata(MetadataContext context, ParameterValueResolver metadataKeyResolver, ReflectionCache reflectionCache) {
    try {
        Object keyValue;
        MetadataResult keyValueResult = getMetadataKeyObjectValue(metadataKeyResolver);
        if (!keyValueResult.isSuccess()) {
            return keyValueResult;
        }
        keyValue = keyValueResult.get();
        if (keyValue == null && !keyIdObjectResolver.isKeyLess()) {
            return failure(newFailure().withFailureCode(INVALID_METADATA_KEY).withMessage("MetadataKey resolved to null").onComponent());
        }
        MetadataAttributes.MetadataAttributesBuilder builder = MetadataAttributes.builder();
        if (!keyIdObjectResolver.isKeyLess()) {
            builder.withKey(keyIdObjectResolver.reconstructKeyFromType(keyValue, reflectionCache));
        }
        return getMetadata(context, keyValue, builder);
    } catch (MetadataResolvingException e) {
        return failure(newFailure(e).onComponent());
    }
}
Also used : MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) MetadataAttributes(org.mule.runtime.api.metadata.MetadataAttributes) MetadataResult(org.mule.runtime.api.metadata.resolving.MetadataResult)

Example 3 with MetadataResult

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

the class MetadataInputDelegate method getInputMetadataDescriptors.

/**
 * For each of the Component's {@link ParameterModel} creates the corresponding {@link TypeMetadataDescriptor} using only its
 * static {@link MetadataType} and ignoring if any parameter has a dynamic type.
 *
 * @return A {@link List} containing a {@link MetadataResult} of {@link TypeMetadataDescriptor} for each input parameter using
 * only its static {@link MetadataType} and ignoring if any parameter has a dynamic type.
 */
MetadataResult<InputMetadataDescriptor> getInputMetadataDescriptors(MetadataContext context, Object key) {
    InputMetadataDescriptor.InputMetadataDescriptorBuilder input = InputMetadataDescriptor.builder();
    List<MetadataResult<ParameterMetadataDescriptor>> results = new LinkedList<>();
    for (ParameterModel parameter : component.getAllParameterModels()) {
        MetadataResult<ParameterMetadataDescriptor> result = getParameterMetadataDescriptor(parameter, context, key);
        input.withParameter(parameter.getName(), result.get());
        results.add(result);
    }
    List<MetadataFailure> failures = results.stream().flatMap(e -> e.getFailures().stream()).collect(toList());
    return failures.isEmpty() ? success(input.build()) : failure(input.build(), failures);
}
Also used : InputMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.InputMetadataDescriptor) ParameterMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor) MetadataResult.success(org.mule.runtime.api.metadata.resolving.MetadataResult.success) MetadataResult(org.mule.runtime.api.metadata.resolving.MetadataResult) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) InputMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.InputMetadataDescriptor) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) MetadataTypeUtils.isNullType(org.mule.metadata.api.utils.MetadataTypeUtils.isNullType) TypeMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.TypeMetadataDescriptor) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) NO_DYNAMIC_TYPE_AVAILABLE(org.mule.runtime.api.metadata.resolving.FailureCode.NO_DYNAMIC_TYPE_AVAILABLE) LinkedList(java.util.LinkedList) InputTypeResolver(org.mule.runtime.api.metadata.resolving.InputTypeResolver) MetadataTypeUtils.isCollection(org.mule.metadata.api.utils.MetadataTypeUtils.isCollection) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation) String.format(java.lang.String.format) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) MetadataContext(org.mule.runtime.api.metadata.MetadataContext) Builder.newFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure.Builder.newFailure) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) ParameterMetadataDescriptorBuilder(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor.ParameterMetadataDescriptorBuilder) NamedTypeResolver(org.mule.runtime.api.metadata.resolving.NamedTypeResolver) MetadataFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure) JavaTypeUtils.getType(org.mule.metadata.java.api.utils.JavaTypeUtils.getType) MetadataResult.failure(org.mule.runtime.api.metadata.resolving.MetadataResult.failure) ParameterMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) MetadataFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure) LinkedList(java.util.LinkedList) MetadataResult(org.mule.runtime.api.metadata.resolving.MetadataResult)

Aggregations

MetadataResult (org.mule.runtime.api.metadata.resolving.MetadataResult)3 MetadataType (org.mule.metadata.api.model.MetadataType)2 ComponentModel (org.mule.runtime.api.meta.model.ComponentModel)2 MetadataKey (org.mule.runtime.api.metadata.MetadataKey)2 MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)2 MetadataFailure (org.mule.runtime.api.metadata.resolving.MetadataFailure)2 String.format (java.lang.String.format)1 Type (java.lang.reflect.Type)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 BiConsumer (java.util.function.BiConsumer)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toList (java.util.stream.Collectors.toList)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)1