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);
}
}
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);
}
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);
}
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));
}
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);
}
Aggregations