use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createWrappedObject.
private void createWrappedObject(ParameterObjectValue objectValue, ParameterModel parameterModel, DslElementSyntax paramDsl, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
DslElementModel.Builder<ParameterModel> wrapperElement = DslElementModel.<ParameterModel>builder().withModel(parameterModel).withDsl(paramDsl);
InternalComponentConfiguration.Builder wrapperConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(paramDsl));
Reference<DslSyntaxResolver> customDsl = new Reference<>(dsl);
ObjectType nestedElementType;
if (objectValue.getTypeId() == null || objectValue.getTypeId().trim().isEmpty() || getId(parameterModel.getType()).map(id -> id.equals(objectValue.getTypeId())).orElse(false)) {
nestedElementType = (ObjectType) parameterModel.getType();
} else {
nestedElementType = lookupType(objectValue);
context.getTypeCatalog().getDeclaringExtension(objectValue.getTypeId()).ifPresent(owner -> context.getExtension(owner).ifPresent(extensionModel -> customDsl.set(resolvers.get(extensionModel))));
}
customDsl.get().resolve(nestedElementType).ifPresent(typeDsl -> createObject(objectValue, typeDsl, nestedElementType, nestedElementType, wrapperConfig, wrapperElement));
ComponentConfiguration result = wrapperConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(wrapperElement.withConfig(result).build());
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class ExtensionModelHelper method findComponentModel.
/**
* Finds a {@link org.mule.runtime.api.meta.model.ComponentModel} within the provided set of {@link ExtensionModel}s by a
* {@link ComponentIdentifier}.
*
* @param componentIdentifier the identifier to use for the search.
* @return the found {@link org.mule.runtime.api.meta.model.ComponentModel} or {@link Optional#empty()} if it couldn't be found.
*/
public Optional<? extends org.mule.runtime.api.meta.model.ComponentModel> findComponentModel(ComponentIdentifier componentIdentifier) {
try {
return extensionComponentModelByComponentIdentifier.get(componentIdentifier, () -> {
String componentName = toCamelCase(componentIdentifier.getName(), COMPONENT_NAME_SEPARATOR);
for (ExtensionModel extensionModel : extensionsModels) {
if (extensionModel.getXmlDslModel().getPrefix().equals(componentIdentifier.getNamespace())) {
List<HasOperationModels> operationModelsProviders = ImmutableList.<HasOperationModels>builder().add(extensionModel).addAll(extensionModel.getConfigurationModels()).build();
List<HasSourceModels> sourceModelsProviders = ImmutableList.<HasSourceModels>builder().add(extensionModel).addAll(extensionModel.getConfigurationModels()).build();
List<HasConstructModels> constructModelsProviders = singletonList(extensionModel);
Optional<? extends org.mule.runtime.api.meta.model.ComponentModel> componentModel = resolveModel(operationModelsProviders, sourceModelsProviders, constructModelsProviders, componentName);
// TODO MULE-13894 remove this once unified extensionModel names to use camelCase (see smart connectors and crafted declared extesion models)
if (!componentModel.isPresent()) {
componentModel = resolveModel(operationModelsProviders, sourceModelsProviders, constructModelsProviders, componentIdentifier.getName());
}
return componentModel;
}
}
return empty();
});
} catch (ExecutionException e) {
throw new MuleRuntimeException(e);
}
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class MacroExpansionModuleModel method lookForOperation.
/**
* Looks for an operation checking if it is defined within the scope of a {@link ConfigurationModel} or the
* {@link ExtensionModel}.
*
* @param operationIdentifier element to look for in the current {@link #extensionModel}
* @param prefix to check if the {@code operationIdentifier} namespace targets an operation of the <module/> (usually maps to
* the {@link ExtensionModel} prefix, or the {@link #TNS_PREFIX}.
* @return an {@link OperationModel} if found, {@link Optional#empty()} otherwise.
*/
private Optional<OperationModel> lookForOperation(ComponentIdentifier operationIdentifier, String prefix) {
Optional<OperationModel> result = Optional.empty();
final String operationName = operationIdentifier.getName();
if (operationIdentifier.getNamespace().equals(prefix)) {
// As the operation can be inside the extension or the config, it has to be looked up in both elements.
final HasOperationModels hasOperationModels = getConfigurationModel().map(configurationModel -> (HasOperationModels) configurationModel).orElse(extensionModel);
result = hasOperationModels.getOperationModel(operationName);
}
// If the operation is not present, it might be a private one and it must be looked inside of the model property
if (!result.isPresent() && extensionModel.getModelProperty(PrivateOperationsModelProperty.class).isPresent()) {
result = extensionModel.getModelProperty(PrivateOperationsModelProperty.class).get().getOperationModel(operationName);
}
return result;
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class DeclarationElementModelFactoryTestCase method testConfigNoConnectionNoParams.
@Test
public void testConfigNoConnectionNoParams() {
ConfigurationModel emptyConfig = mock(ConfigurationModel.class);
when(emptyConfig.getName()).thenReturn(CONFIGURATION_NAME);
when(emptyConfig.getParameterGroupModels()).thenReturn(emptyList());
when(emptyConfig.getOperationModels()).thenReturn(emptyList());
when(emptyConfig.getSourceModels()).thenReturn(emptyList());
when(emptyConfig.getConnectionProviders()).thenReturn(emptyList());
ExtensionModel extensionModel = mock(ExtensionModel.class);
initializeExtensionMock(extensionModel);
when(extensionModel.getConfigurationModels()).thenReturn(asList(emptyConfig));
ConfigurationElementDeclaration declaration = ElementDeclarer.forExtension(EXTENSION_NAME).newConfiguration(CONFIGURATION_NAME).withRefName("sample").getDeclaration();
DslElementModel<ConfigurationModel> element = create(declaration);
assertThat(element.getModel(), is(configuration));
assertThat(element.getContainedElements().isEmpty(), is(true));
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class ExtensionPluginMetadataGenerator method generateExtensionResources.
/**
* Generates the extension resources for the {@link Artifact} plugin with the {@link Extension}.
*
* @param plugin the {@link Artifact} to generate its extension manifest if it is an extension.
* @param extensionClass {@link Class} annotated with {@link Extension}
* @param dependencyResolver the dependency resolver used to discover test extensions poms to find which loader to use
* @param rootArtifactRemoteRepositories remote repositories defined at the rootArtifact
* @return {@link File} folder where extension manifest resources were generated
*/
File generateExtensionResources(Artifact plugin, Class extensionClass, DependencyResolver dependencyResolver, List<RemoteRepository> rootArtifactRemoteRepositories) {
logger.debug("Generating Extension metadata for extension class: '{}'", extensionClass);
final ExtensionModel extensionModel = getExtensionModel(plugin, extensionClass, dependencyResolver, rootArtifactRemoteRepositories);
File generatedResourcesDirectory = new File(generatedResourcesBase, plugin.getArtifactId() + separator + "META-INF");
generatedResourcesDirectory.mkdirs();
extensionsInfrastructure.generateLoaderResources(extensionModel, generatedResourcesDirectory);
extensionsInfrastructure.generateSchemaTestResource(extensionModel, generatedResourcesDirectory);
extensionGeneratorEntries.add(new ExtensionGeneratorEntry(extensionModel, generatedResourcesDirectory));
return generatedResourcesDirectory.getParentFile();
}
Aggregations