Search in sources :

Example 1 with ParameterGroupDescriptor

use of org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor in project mule by mulesoft.

the class ExtensionDefinitionParser method parseInlineParameterGroup.

protected void parseInlineParameterGroup(ParameterGroupModel group) throws ConfigurationException {
    ParameterGroupDescriptor descriptor = group.getModelProperty(ParameterGroupModelProperty.class).map(ParameterGroupModelProperty::getDescriptor).orElse(null);
    DslElementSyntax dslElementSyntax = dslResolver.resolveInline(group);
    if (descriptor != null) {
        addParameter(getChildKey(getContainerName(descriptor.getContainer())), new DefaultObjectParsingDelegate().parse("", null, dslElementSyntax));
        new TypedInlineParameterGroupParser(baseDefinitionBuilder, group, descriptor, getContextClassLoader(), dslElementSyntax, dslResolver, parsingContext).parse().forEach(this::addDefinition);
    } else {
        AttributeDefinition.Builder builder = fromChildConfiguration(Map.class);
        if (dslElementSyntax.isWrapped()) {
            builder.withWrapperIdentifier(dslElementSyntax.getElementName());
        } else {
            builder.withIdentifier(dslElementSyntax.getElementName());
        }
        addParameter(getChildKey(group.getName()), builder);
        new AnonymousInlineParameterGroupParser(baseDefinitionBuilder, group, getContextClassLoader(), dslElementSyntax, dslResolver, parsingContext).parse().forEach(this::addDefinition);
    }
}
Also used : TypedInlineParameterGroupParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.TypedInlineParameterGroupParser) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) DefaultObjectParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.DefaultObjectParsingDelegate) AttributeDefinition(org.mule.runtime.dsl.api.component.AttributeDefinition) AnonymousInlineParameterGroupParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.AnonymousInlineParameterGroupParser)

Example 2 with ParameterGroupDescriptor

use of org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor in project mule by mulesoft.

the class ConfigOverrideValueResolverWrapper method getParameterValueFromFieldInGroup.

private Function<Object, Object> getParameterValueFromFieldInGroup(ConfigurationInstance config, ParameterGroupModel group, String fieldName) {
    ParameterGroupDescriptor descriptor = group.getModelProperty(ParameterGroupModelProperty.class).map(ParameterGroupModelProperty::getDescriptor).orElseThrow(() -> new IllegalArgumentException(format("The group [%s] in config [%s] doesn't provide a group descriptor. " + "Is not possible to retrieve the config parameter to override", group.getName(), config.getName())));
    Field groupField = (Field) descriptor.getContainer();
    Field parameterField = getField(descriptor.getType().getDeclaringClass().get(), fieldName, reflectionCache).orElseThrow(() -> new IllegalArgumentException("Missing field with name [" + fieldName + "] in group [" + descriptor.getName() + "] of config [" + config.getName() + "]"));
    return new ParameterValueRetrieverFromConfigGroup(groupField, parameterField);
}
Also used : IntrospectionUtils.getField(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getField) Field(java.lang.reflect.Field) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor)

Example 3 with ParameterGroupDescriptor

use of org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor in project mule by mulesoft.

the class ParameterGroupModelValidatorTestCase method skipEmptyGroupValidationInRuntimeMode.

@Test
public void skipEmptyGroupValidationInRuntimeMode() {
    when(extensionModel.getModelProperty(CompileTimeModelProperty.class)).thenReturn(empty());
    ParameterGroupDescriptor descriptor = new ParameterGroupDescriptor("name", new TypeWrapper(EmptyGroupPojo.class, typeLoader), null, mock(AnnotatedElement.class), null);
    when(groupModel.getModelProperty(ParameterGroupModelProperty.class)).thenReturn(of(new ParameterGroupModelProperty(descriptor)));
    validate(extensionModel, validator);
}
Also used : TypeWrapper(org.mule.runtime.module.extension.internal.loader.java.type.runtime.TypeWrapper) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with ParameterGroupDescriptor

use of org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor in project mule by mulesoft.

the class SoapInvokeOperationDeclarer method declareMetadataKeyParameters.

/**
 * Given the Invoke Operation Declarer declares all the parameters that the operation has.
 *
 * @param operation the invoke operation declarer.
 */
private void declareMetadataKeyParameters(OperationDeclarer operation, ClassTypeLoader loader, ReflectionCache reflectionCache) {
    TypeWrapper keyType = new TypeWrapper(WebServiceTypeKey.class, loader);
    ParameterGroupDeclarer group = operation.onParameterGroup(KEYS_GROUP).withModelProperty(new ParameterGroupModelProperty(new ParameterGroupDescriptor(KEYS_GROUP, keyType)));
    StringType stringType = TYPE_BUILDER.stringType().build();
    group.withRequiredParameter(SERVICE_PARAM).withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, SERVICE_PARAM, reflectionCache).get())).ofType(stringType).withModelProperty(new MetadataKeyPartModelProperty(1)).withLayout(getLayout(1));
    group.withRequiredParameter(OPERATION_PARAM).ofType(stringType).withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, OPERATION_PARAM, reflectionCache).get())).withModelProperty(new MetadataKeyPartModelProperty(2)).withLayout(getLayout(2));
}
Also used : DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) TypeWrapper(org.mule.runtime.module.extension.internal.loader.java.type.runtime.TypeWrapper) StringType(org.mule.metadata.api.model.StringType) WebServiceTypeKey(org.mule.runtime.extension.api.soap.WebServiceTypeKey) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) MetadataKeyPartModelProperty(org.mule.runtime.extension.api.property.MetadataKeyPartModelProperty) ParameterGroupDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer)

Example 5 with ParameterGroupDescriptor

use of org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor in project mule by mulesoft.

the class ComponentMessageProcessor method createComponentExecutor.

private ComponentExecutor<T> createComponentExecutor() {
    Map<String, Object> params = new HashMap<>();
    LazyValue<Optional<ConfigurationInstance>> staticConfiguration = new LazyValue<>(this::getStaticConfiguration);
    LazyValue<ValueResolvingContext> resolvingContext = new LazyValue<>(() -> {
        CoreEvent initialiserEvent = null;
        try {
            initialiserEvent = getInitialiserEvent();
            return from(initialiserEvent, staticConfiguration.get());
        } finally {
            if (initialiserEvent != null) {
                ((BaseEventContext) initialiserEvent.getContext()).success();
            }
        }
    });
    componentModel.getParameterGroupModels().stream().forEach(group -> {
        if (group.getName().equals(DEFAULT_GROUP_NAME)) {
            group.getParameterModels().stream().filter(p -> p.getModelProperty(FieldOperationParameterModelProperty.class).isPresent()).forEach(p -> {
                ValueResolver<?> resolver = resolverSet.getResolvers().get(p.getName());
                if (resolver != null) {
                    try {
                        params.put(getMemberName(p), resolveValue(resolver, resolvingContext.get()));
                    } catch (MuleException e) {
                        throw new MuleRuntimeException(e);
                    }
                }
            });
        } else {
            ParameterGroupDescriptor groupDescriptor = group.getModelProperty(ParameterGroupModelProperty.class).map(g -> g.getDescriptor()).orElse(null);
            if (groupDescriptor == null) {
                return;
            }
            List<ParameterModel> fieldParameters = getGroupsOfFieldParameters(group);
            if (fieldParameters.isEmpty()) {
                return;
            }
            ObjectBuilder groupBuilder = createFieldParameterGroupBuilder(groupDescriptor, fieldParameters);
            try {
                params.put(((Field) groupDescriptor.getContainer()).getName(), groupBuilder.build(resolvingContext.get()));
            } catch (MuleException e) {
                throw new MuleRuntimeException(e);
            }
        }
    });
    return getOperationExecutorFactory(componentModel).createExecutor(componentModel, params);
}
Also used : IntrospectionUtils.getMemberName(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getMemberName) FieldOperationParameterModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.FieldOperationParameterModelProperty) Optional.of(java.util.Optional.of) Mono.subscriberContext(reactor.core.publisher.Mono.subscriberContext) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ResolverUtils.resolveValue(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverUtils.resolveValue) ParameterValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ParameterValueResolver) PROCESSOR_SCHEDULER_CONTEXT_KEY(org.mule.runtime.core.internal.processor.strategy.AbstractProcessingStrategy.PROCESSOR_SCHEDULER_CONTEXT_KEY) Scheduler(org.mule.runtime.api.scheduler.Scheduler) IMMEDIATE_SCHEDULER(org.mule.runtime.core.internal.util.rx.ImmediateScheduler.IMMEDIATE_SCHEDULER) MuleExtensionUtils.getOperationExecutorFactory(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getOperationExecutorFactory) Map(java.util.Map) TARGET_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_PARAMETER_NAME) OperationArgumentResolverFactory(org.mule.runtime.module.extension.internal.runtime.execution.OperationArgumentResolverFactory) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) Exceptions(org.mule.runtime.core.api.rx.Exceptions) PolicyManager(org.mule.runtime.core.internal.policy.PolicyManager) ParametersResolverProcessor(org.mule.runtime.core.internal.processor.ParametersResolverProcessor) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) String.format(java.lang.String.format) OperationPolicy(org.mule.runtime.core.internal.policy.OperationPolicy) MuleExtensionUtils.getInitialiserEvent(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.getInitialiserEvent) ObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.ObjectBuilder) Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) List(java.util.List) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty) Optional(java.util.Optional) CursorProviderFactory(org.mule.runtime.core.api.streaming.CursorProviderFactory) ValueResolvingContext.from(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext.from) ComponentExecutorFactory(org.mule.runtime.extension.api.runtime.operation.ComponentExecutorFactory) Optional.empty(java.util.Optional.empty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) RetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate) Flux.from(reactor.core.publisher.Flux.from) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ComponentExecutor(org.mule.runtime.extension.api.runtime.operation.ComponentExecutor) HashMap(java.util.HashMap) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) Processor(org.mule.runtime.core.api.processor.Processor) TARGET_VALUE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_VALUE_PARAMETER_NAME) DefaultObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.DefaultObjectBuilder) MuleException(org.mule.runtime.api.exception.MuleException) Flux.error(reactor.core.publisher.Flux.error) BiConsumer(java.util.function.BiConsumer) DEFAULT_GROUP_NAME(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.DEFAULT_GROUP_NAME) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) Mono.fromCallable(reactor.core.publisher.Mono.fromCallable) ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter) DefaultExecutionContext(org.mule.runtime.module.extension.internal.runtime.DefaultExecutionContext) Logger(org.slf4j.Logger) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) Exceptions.checkedFunction(org.mule.runtime.core.api.rx.Exceptions.checkedFunction) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) ComponentLocationProvider.resolveProcessorRepresentation(org.mule.runtime.api.util.ComponentLocationProvider.resolveProcessorRepresentation) LifecycleUtils.startIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.startIfNeeded) Mono(reactor.core.publisher.Mono) Field(java.lang.reflect.Field) ExtensionComponent(org.mule.runtime.module.extension.internal.runtime.ExtensionComponent) LazyExecutionContext(org.mule.runtime.module.extension.internal.runtime.LazyExecutionContext) Interceptor(org.mule.runtime.extension.api.runtime.operation.Interceptor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) LifecycleUtils.disposeIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.disposeIfNeeded) INTERCEPTION_RESOLVED_CONTEXT(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent.INTERCEPTION_RESOLVED_CONTEXT) Collectors.toList(java.util.stream.Collectors.toList) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) LazyValue(org.mule.runtime.api.util.LazyValue) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) IntrospectionUtils.isVoid(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isVoid) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DefaultFlowCallStack(org.mule.runtime.core.internal.context.notification.DefaultFlowCallStack) ValueResolvingContext(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext) OperationExecutionFunction(org.mule.runtime.core.internal.policy.OperationExecutionFunction) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) FieldOperationParameterModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.FieldOperationParameterModelProperty) LazyValue(org.mule.runtime.api.util.LazyValue) Optional(java.util.Optional) HashMap(java.util.HashMap) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.ObjectBuilder) DefaultObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.DefaultObjectBuilder) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ValueResolvingContext(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException)

Aggregations

ParameterGroupDescriptor (org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor)10 ParameterGroupModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty)7 TypeWrapper (org.mule.runtime.module.extension.internal.loader.java.type.runtime.TypeWrapper)5 AnnotatedElement (java.lang.reflect.AnnotatedElement)4 Field (java.lang.reflect.Field)3 Test (org.junit.Test)3 SmallTest (org.mule.tck.size.SmallTest)3 String.format (java.lang.String.format)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 ParameterGroupDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer)2 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)2 DEFAULT_GROUP_NAME (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.DEFAULT_GROUP_NAME)2 DeclaringMemberModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty)2 NullSafeModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.NullSafeModelProperty)2 ResolverSet (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1