use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration 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.declaration.fluent.ParameterDeclaration in project mule by mulesoft.
the class ObjectStoreParameterDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
final ExtensionDeclaration extension = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
final Reference<Boolean> hasObjectStoreParams = new Reference<>(false);
new IdempotentDeclarationWalker() {
@Override
protected void onParameter(ParameterGroupDeclaration parameterGroup, ParameterDeclaration parameter) {
if (isObjectStore(parameter.getType())) {
List<StereotypeModel> stereotypes = parameter.getAllowedStereotypeModels();
if (!stereotypes.contains(OBJECT_STORE)) {
stereotypes.add(OBJECT_STORE);
}
hasObjectStoreParams.set(true);
}
}
}.walk(extension);
if (hasObjectStoreParams.get() && !isObjectStoreAlreadyImported(extension)) {
ClassTypeLoader typeLoader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
extension.getImportedTypes().add(new ImportedTypeModel((ObjectType) typeLoader.load(ObjectStore.class)));
}
}
use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration in project mule by mulesoft.
the class DisplayDeclarationEnricherTestCase method parseSummaryAnnotationOnConfigParameter.
@Test
public void parseSummaryAnnotationOnConfigParameter() {
ExtensionDeclaration extensionDeclaration = heisenbergDeclarer.getDeclaration();
List<ParameterDeclaration> parameters = extensionDeclaration.getConfigurations().get(0).getAllParameters();
assertParameterSummary(findParameter(parameters, "ricinPacks"), RICIN_PACKS_SUMMARY);
}
use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration in project mule by mulesoft.
the class DisplayDeclarationEnricherTestCase method parseClassParameter.
@Test
public void parseClassParameter() {
ExtensionDeclaration declaration = marvelDeclarer.getDeclaration();
ConfigurationDeclaration config = findConfigByName(declaration, IronMan.CONFIG_NAME);
List<ParameterDeclaration> params = config.getAllParameters();
assertThat(params, hasSize(2));
ParameterDeclaration pathParam = params.get(1);
Optional<ClassValueModel> classValueModel = pathParam.getDisplayModel().getClassValueModel();
assertThat(classValueModel.isPresent(), is(true));
assertThat(classValueModel.get().getAssignableFrom(), hasSize(1));
assertThat(classValueModel.get().getAssignableFrom().get(0), equalTo("com.starkindustries.AIEngine"));
}
use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration in project mule by mulesoft.
the class DisplayDeclarationEnricherTestCase method parseSimplePathParameter.
@Test
public void parseSimplePathParameter() {
ExtensionDeclaration declaration = marvelDeclarer.getDeclaration();
ConfigurationDeclaration config = findConfigByName(declaration, IronMan.CONFIG_NAME);
List<ParameterDeclaration> params = config.getAllParameters();
assertThat(params, hasSize(2));
ParameterDeclaration pathParam = params.get(0);
Optional<PathModel> pathModel = pathParam.getDisplayModel().getPathModel();
assertThat(pathModel.isPresent(), is(true));
assertThat(pathModel.get().getType(), is(ANY));
assertThat(pathModel.get().acceptsUrls(), is(true));
assertThat(pathModel.get().getFileExtensions(), empty());
}
Aggregations