use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.DEFAULT_GROUP_NAME in project mule by mulesoft.
the class PollingSourceDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
ClassTypeLoader loader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
ExtensionDeclarer extensionDeclarer = extensionLoadingContext.getExtensionDeclarer();
Reference<Boolean> thereArePollingSources = new Reference<>(false);
new IdempotentDeclarationWalker() {
@Override
protected void onSource(SourceDeclaration source) {
extractType(source).ifPresent(type -> {
if (type.isAssignableTo(PollingSource.class)) {
source.setRunsOnPrimaryNodeOnly(true);
ParameterDeclaration parameter = new ParameterDeclaration(SCHEDULING_STRATEGY_PARAMETER_NAME);
parameter.setDescription(SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION);
parameter.setRequired(true);
parameter.setType(loader.load(Scheduler.class), false);
parameter.setExpressionSupport(NOT_SUPPORTED);
parameter.addModelProperty(new InfrastructureParameterModelProperty(10));
parameter.addModelProperty(new QNameModelProperty(new QName(CORE_NAMESPACE, SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER, CORE_PREFIX)));
parameter.setDslConfiguration(ParameterDslConfiguration.builder().allowsInlineDefinition(true).allowsReferences(false).allowTopLevelDefinition(false).build());
thereArePollingSources.set(true);
source.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter);
}
});
}
}.walk(extensionDeclarer.getDeclaration());
if (thereArePollingSources.get() && !isSchedulerAlreadyImported(extensionDeclarer.getDeclaration())) {
ClassTypeLoader typeLoader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
extensionDeclarer.withImportedType(new ImportedTypeModel((ObjectType) typeLoader.load(Scheduler.class)));
}
}
use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.DEFAULT_GROUP_NAME 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