Search in sources :

Example 1 with ParameterDeclaration

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)));
    }
}
Also used : InfrastructureParameterModelProperty(org.mule.runtime.extension.api.property.InfrastructureParameterModelProperty) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) PollingSource(org.mule.runtime.extension.api.runtime.source.PollingSource) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) QNameModelProperty(org.mule.runtime.extension.api.property.QNameModelProperty) CORE_NAMESPACE(org.mule.runtime.internal.dsl.DslConstants.CORE_NAMESPACE) DEFAULT_GROUP_NAME(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.DEFAULT_GROUP_NAME) MetadataTypeUtils.getTypeId(org.mule.metadata.api.utils.MetadataTypeUtils.getTypeId) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) ParameterDslConfiguration(org.mule.runtime.api.meta.model.ParameterDslConfiguration) SCHEDULING_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.SCHEDULING_STRATEGY_PARAMETER_NAME) ObjectType(org.mule.metadata.api.model.ObjectType) DeclarationEnricherPhase(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) STRUCTURE(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.STRUCTURE) SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION(org.mule.runtime.extension.api.ExtensionConstants.SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) Reference(org.mule.runtime.api.util.Reference) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) QName(javax.xml.namespace.QName) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) QNameModelProperty(org.mule.runtime.extension.api.property.QNameModelProperty) Reference(org.mule.runtime.api.util.Reference) QName(javax.xml.namespace.QName) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) PollingSource(org.mule.runtime.extension.api.runtime.source.PollingSource) InfrastructureParameterModelProperty(org.mule.runtime.extension.api.property.InfrastructureParameterModelProperty) ObjectType(org.mule.metadata.api.model.ObjectType) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)

Example 2 with ParameterDeclaration

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)));
    }
}
Also used : ObjectStore(org.mule.runtime.api.store.ObjectStore) Reference(org.mule.runtime.api.util.Reference) ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ObjectType(org.mule.metadata.api.model.ObjectType) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) List(java.util.List) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)

Example 3 with ParameterDeclaration

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);
}
Also used : ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) Test(org.junit.Test)

Example 4 with ParameterDeclaration

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"));
}
Also used : ConfigurationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration) ClassValueModel(org.mule.runtime.api.meta.model.display.ClassValueModel) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) Test(org.junit.Test)

Example 5 with ParameterDeclaration

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());
}
Also used : ConfigurationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration) PathModel(org.mule.runtime.api.meta.model.display.PathModel) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) Test(org.junit.Test)

Aggregations

ParameterDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)28 Test (org.junit.Test)18 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)15 OperationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration)9 ConfigurationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration)4 ParameterGroupDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration)3 PathModel (org.mule.runtime.api.meta.model.display.PathModel)3 List (java.util.List)2 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 ObjectType (org.mule.metadata.api.model.ObjectType)2 StringType (org.mule.metadata.api.model.StringType)2 ClassInformationAnnotation (org.mule.metadata.java.api.annotation.ClassInformationAnnotation)2 ImportedTypeModel (org.mule.runtime.api.meta.model.ImportedTypeModel)2 ConnectionProviderDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclaration)2 SourceDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)2 ClassValueModel (org.mule.runtime.api.meta.model.display.ClassValueModel)2 Reference (org.mule.runtime.api.util.Reference)2 IdempotentDeclarationWalker (org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker)2 BigDecimal (java.math.BigDecimal)1