Search in sources :

Example 1 with ParameterGroupDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration 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 2 with ParameterGroupDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration in project mule by mulesoft.

the class ExclusiveOptionalModelTestCase method exclusiveOptionals.

@Test
public void exclusiveOptionals() {
    OperationDeclaration operation = getOperation(extensionDeclaration, "convinceAnimalKiller");
    assertThat(operation.getParameterGroups(), hasSize(2));
    ParameterGroupDeclaration group = operation.getParameterGroups().get(0);
    assertThat(group.getName(), equalTo("arguments"));
    assertThat(group.getExclusiveParameters(), hasSize(1));
    ExclusiveParametersDeclaration exclusive = group.getExclusiveParameters().get(0);
    assertThat(exclusive.isRequiresOne(), is(false));
    assertThat(exclusive.getParameterNames(), containsInAnyOrder("argument1", "argument2", "argument3"));
}
Also used : ExclusiveParametersDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExclusiveParametersDeclaration) ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) Test(org.junit.Test)

Example 3 with ParameterGroupDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration in project mule by mulesoft.

the class LayoutModelTestCase method assertParameterPlacement.

private void assertParameterPlacement(Pair<ParameterGroupDeclaration, ParameterDeclaration> pair, String groupName, Integer order) {
    ParameterGroupDeclaration group = pair.getFirst();
    assertThat(group.getName(), equalTo(groupName));
    assertParameterPlacement(pair.getSecond(), order);
}
Also used : ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration)

Example 4 with ParameterGroupDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration in project mule by mulesoft.

the class ParameterModelsLoaderDelegate method parseExclusiveOptional.

private void parseExclusiveOptional(ExtensionParameter extensionParameter, ParameterGroupDeclarer parameterGroupDeclarer, ParameterDeclarer parameter) {
    ParameterGroupDeclaration groupDeclaration = (ParameterGroupDeclaration) parameterGroupDeclarer.getDeclaration();
    List<ExclusiveParametersDeclaration> exclusiveParameters = groupDeclaration.getExclusiveParameters();
    exclusiveParameters.stream().filter(group -> group.getParameterNames().contains(extensionParameter.getAlias())).findFirst().ifPresent(exclusiveParametersDeclaration -> {
        ExclusiveParametersModel exclusiveParametersModel = new ImmutableExclusiveParametersModel(exclusiveParametersDeclaration.getParameterNames(), exclusiveParametersDeclaration.isRequiresOne());
        parameter.withModelProperty(new ExclusiveOptionalModelProperty(exclusiveParametersModel));
    });
}
Also used : ExclusiveParametersDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExclusiveParametersDeclaration) ExclusiveParametersModel(org.mule.runtime.api.meta.model.parameter.ExclusiveParametersModel) ImmutableExclusiveParametersModel(org.mule.runtime.extension.api.model.parameter.ImmutableExclusiveParametersModel) ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration) ExclusiveOptionalModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ExclusiveOptionalModelProperty) ImmutableExclusiveParametersModel(org.mule.runtime.extension.api.model.parameter.ImmutableExclusiveParametersModel)

Example 5 with ParameterGroupDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration in project mule by mulesoft.

the class ExtensionsTestUtils method mockParameters.

public static ParameterGroupDeclaration mockParameters(ParameterizedDeclaration declaration, String groupName, ParameterDeclaration... parameters) {
    ParameterGroupDeclaration group = mock(ParameterGroupDeclaration.class);
    when(group.getName()).thenReturn(groupName);
    when(declaration.getParameterGroups()).thenReturn(asList(group));
    when(declaration.getParameterGroup(groupName)).thenReturn(group);
    List<ParameterDeclaration> params = new ArrayList<>(asList(parameters));
    when(group.getParameters()).thenReturn(params);
    when(declaration.getAllParameters()).thenReturn(params);
    return group;
}
Also used : ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration) ArrayList(java.util.ArrayList) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)

Aggregations

ParameterGroupDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration)8 ParameterDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)3 Test (org.junit.Test)2 ExclusiveParametersDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExclusiveParametersDeclaration)2 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)2 OperationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Before (org.junit.Before)1 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)1 BooleanType (org.mule.metadata.api.model.BooleanType)1 ObjectType (org.mule.metadata.api.model.ObjectType)1 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)1 ImportedTypeModel (org.mule.runtime.api.meta.model.ImportedTypeModel)1 ParameterizedDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration)1 DeclarationWalker (org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker)1 ExclusiveParametersModel (org.mule.runtime.api.meta.model.parameter.ExclusiveParametersModel)1 ObjectStore (org.mule.runtime.api.store.ObjectStore)1 Reference (org.mule.runtime.api.util.Reference)1 ConfigOverride (org.mule.runtime.extension.api.annotation.param.ConfigOverride)1