use of org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration in project mule by mulesoft.
the class BackPressureDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
final ExtensionDeclaration extensionDeclaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
new IdempotentDeclarationWalker() {
@Override
protected void onSource(SourceDeclaration sourceDeclaration) {
BackPressureStrategyModelProperty property;
Optional<ExtensionTypeDescriptorModelProperty> extensionTypeDescriptorModelProperty = sourceDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (extensionTypeDescriptorModelProperty.isPresent()) {
Type sourceType = extensionTypeDescriptorModelProperty.get().getType();
property = sourceType.getAnnotation(BackPressure.class).map(BackPressureStrategyModelProperty::of).orElseGet(BackPressureStrategyModelProperty::getDefault);
sourceDeclaration.addModelProperty(property);
if (property.getSupportedModes().size() > 1) {
addBackPressureParameter(extensionDeclaration, sourceDeclaration, property);
}
}
}
}.walk(extensionDeclaration);
}
use of org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration in project mule by mulesoft.
the class JavaDeclarationDelegateTestCase method flyweight.
@Test
public void flyweight() {
setLoader(loaderFor(VeganExtension.class));
ExtensionDeclarer declarer = declareExtension();
final ExtensionDeclaration declaration = declarer.getDeclaration();
final ConfigurationDeclaration appleConfiguration = findDeclarationByName(declaration.getConfigurations(), APPLE);
final ConfigurationDeclaration bananaConfiguration = findDeclarationByName(declaration.getConfigurations(), BANANA);
final String sourceName = PaulMcCartneySource.class.getSimpleName();
SourceDeclaration appleSource = findDeclarationByName(appleConfiguration.getMessageSources(), sourceName);
SourceDeclaration bananaSource = findDeclarationByName(bananaConfiguration.getMessageSources(), sourceName);
assertThat(appleSource, is(sameInstance(bananaSource)));
final String operationName = "spreadTheWord";
OperationDeclaration appleOperation = findDeclarationByName(appleConfiguration.getOperations(), operationName);
OperationDeclaration bananaOperation = findDeclarationByName(bananaConfiguration.getOperations(), operationName);
assertThat(appleOperation, is(sameInstance(bananaOperation)));
}
use of org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration in project mule by mulesoft.
the class ExtensionDescriptionsEnricher method document.
/**
* Fills all the descriptions in the provided {@link ExtensionDeclaration} based on the
* <strong>extensions-descriptions.xml</strong> file.
*
* @param declaration the declaration to describe.
* @param documentation the extension documentation with its corresponding description.
*/
private void document(ExtensionDeclaration declaration, XmlExtensionDocumentation documentation) {
declaration.setDescription(documentation.getExtension().getDescription());
new DeclarationWalker() {
@Override
protected void onConfiguration(ConfigurationDeclaration declaration) {
document(declaration, documentation.getConfigs());
}
@Override
protected void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
document(declaration, documentation.getOperations());
}
@Override
protected void onConnectionProvider(ConnectedDeclaration owner, ConnectionProviderDeclaration declaration) {
document(declaration, documentation.getConnections());
}
@Override
protected void onSource(WithSourcesDeclaration owner, SourceDeclaration declaration) {
document(declaration, documentation.getSources());
}
private void document(ParameterizedDeclaration<?> declaration, List<XmlExtensionElementDocumentation> elements) {
elements.stream().filter(e -> e.getName().equals(declaration.getName())).findAny().ifPresent(e -> {
declaration.setDescription(e.getDescription());
declaration.getAllParameters().forEach(param -> e.getParameters().stream().filter(p -> p.getName().equals(param.getName())).findAny().ifPresent(p -> param.setDescription(p.getDescription())));
});
}
}.walk(declaration);
}
use of org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration in project mule by mulesoft.
the class DynamicMetadataDeclarationEnricherTestCase method declareStaticAndDynamicTypesInSource.
@Test
public void declareStaticAndDynamicTypesInSource() {
List<SourceDeclaration> messageSources = declaration.getConfigurations().get(0).getMessageSources();
SourceDeclaration sourceDynamicAttributes = getDeclaration(messageSources, "MetadataSource");
assertOutputType(sourceDynamicAttributes.getOutput(), TYPE_BUILDER.objectType().with(new ClassInformationAnnotation(Map.class, asList(String.class, Object.class))).openWith(TYPE_LOADER.load(Object.class)).build(), true);
assertOutputType(sourceDynamicAttributes.getOutputAttributes(), toMetadataType(StringAttributes.class), false);
assertParameterType(getDeclaration(sourceDynamicAttributes.getAllParameters(), "type"), toMetadataType(String.class));
messageSources = declaration.getMessageSources();
SourceDeclaration sourceStaticAttributes = getDeclaration(messageSources, "MetadataSourceWithMultilevel");
assertOutputType(sourceStaticAttributes.getOutput(), TYPE_BUILDER.objectType().with(new ClassInformationAnnotation(Map.class, asList(String.class, Object.class))).openWith(TYPE_LOADER.load(Object.class)).build(), true);
assertOutputType(sourceStaticAttributes.getOutputAttributes(), toMetadataType(StringAttributes.class), false);
List<ParameterDeclaration> locationKey = sourceStaticAttributes.getAllParameters();
assertParameterType(getDeclaration(locationKey, "continent"), toMetadataType(String.class));
assertParameterType(getDeclaration(locationKey, "country"), toMetadataType(String.class));
assertParameterType(getDeclaration(locationKey, "city"), toMetadataType(String.class));
}
use of org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration in project mule by mulesoft.
the class JavaConfigurationDeclarationEnricherTestCase method verifyConfigurationModelPropertyOnSource.
@Test
public void verifyConfigurationModelPropertyOnSource() {
SourceDeclaration sourceDeclaration = getDeclaration(declaration.getConfigurations().get(0).getMessageSources(), LISTEN_PAYMENTS);
final ConfigTypeModelProperty configTypeModelProperty = checkIsPresent(sourceDeclaration, ConfigTypeModelProperty.class);
assertType(configTypeModelProperty);
}
Aggregations