use of org.mule.runtime.api.component.ComponentIdentifier in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method handleInfrastructure.
private void handleInfrastructure(final ParameterModel paramModel, final DslElementSyntax paramDsl, final Multimap<ComponentIdentifier, ComponentConfiguration> nested, final Map<String, String> parameters, final DslElementModel.Builder<ParameterGroupModel> groupElementBuilder) {
switch(paramModel.getName()) {
case RECONNECTION_CONFIG_PARAMETER_NAME:
ComponentConfiguration reconnection = getSingleComponentConfiguration(nested, of(newIdentifier(RECONNECTION_CONFIG_PARAMETER_NAME, paramDsl.getPrefix())));
if (reconnection != null) {
groupElementBuilder.containing(newElementModel(paramModel, paramDsl, reconnection));
}
return;
case RECONNECTION_STRATEGY_PARAMETER_NAME:
ComponentIdentifier reconnectId = newIdentifier(RECONNECT_ELEMENT_IDENTIFIER, paramDsl.getPrefix());
ComponentConfiguration config = nested.containsKey(reconnectId) ? getSingleComponentConfiguration(nested, of(reconnectId)) : getSingleComponentConfiguration(nested, of(newIdentifier(RECONNECT_FOREVER_ELEMENT_IDENTIFIER, paramDsl.getPrefix())));
if (config != null) {
groupElementBuilder.containing(newElementModel(paramModel, paramDsl, config));
}
return;
case REDELIVERY_POLICY_PARAMETER_NAME:
ComponentConfiguration redelivery = getSingleComponentConfiguration(nested, of(newIdentifier(REDELIVERY_POLICY_ELEMENT_IDENTIFIER, paramDsl.getPrefix())));
if (redelivery != null) {
groupElementBuilder.containing(newElementModel(paramModel, paramDsl, redelivery));
}
return;
case EXPIRATION_POLICY_PARAMETER_NAME:
ComponentConfiguration expiration = getSingleComponentConfiguration(nested, of(newIdentifier(EXPIRATION_POLICY_ELEMENT_IDENTIFIER, paramDsl.getPrefix())));
if (expiration != null) {
groupElementBuilder.containing(newElementModel(paramModel, paramDsl, expiration));
}
return;
case POOLING_PROFILE_PARAMETER_NAME:
ComponentConfiguration pooling = getSingleComponentConfiguration(nested, getIdentifier(paramDsl));
if (pooling != null) {
groupElementBuilder.containing(newElementModel(paramModel, paramDsl, pooling));
}
return;
case STREAMING_STRATEGY_PARAMETER_NAME:
Set<ComponentIdentifier> streaming = newHashSet(newIdentifier(NON_REPEATABLE_BYTE_STREAM_ALIAS, CORE_PREFIX), newIdentifier(REPEATABLE_IN_MEMORY_BYTES_STREAM_ALIAS, CORE_PREFIX), newIdentifier(REPEATABLE_FILE_STORE_BYTES_STREAM_ALIAS, EE_PREFIX), newIdentifier(REPEATABLE_IN_MEMORY_OBJECTS_STREAM_ALIAS, CORE_PREFIX), newIdentifier(REPEATABLE_FILE_STORE_OBJECTS_STREAM_ALIAS, EE_PREFIX), newIdentifier(NON_REPEATABLE_OBJECTS_STREAM_ALIAS, CORE_PREFIX));
streaming.stream().filter(nested::containsKey).findFirst().ifPresent(s -> groupElementBuilder.containing(newElementModel(paramModel, paramDsl, getSingleComponentConfiguration(nested, of(s)))));
return;
case TLS_PARAMETER_NAME:
ComponentConfiguration tls = getSingleComponentConfiguration(nested, getIdentifier(paramDsl));
if (tls != null) {
groupElementBuilder.containing(newElementModel(paramModel, paramDsl, tls));
} else if (!isBlank(parameters.get(TLS_PARAMETER_NAME))) {
groupElementBuilder.containing(DslElementModel.builder().withModel(paramModel).withDsl(paramDsl).withValue(parameters.get(TLS_PARAMETER_NAME)).build());
}
return;
case SCHEDULING_STRATEGY_PARAMETER_NAME:
ComponentConfiguration schedulingStrategyWrapper = getSingleComponentConfiguration(nested, of(ComponentIdentifier.builder().name(SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER).namespace(CORE_PREFIX).build()));
if (schedulingStrategyWrapper != null) {
DslElementModel.Builder wrapper = DslElementModel.builder().withModel(paramModel).withDsl(paramDsl).withConfig(schedulingStrategyWrapper);
Iterator<ComponentConfiguration> nestedIt = schedulingStrategyWrapper.getNestedComponents().iterator();
if (nestedIt.hasNext()) {
final ComponentConfiguration strategy = nestedIt.next();
final MetadataType type = CRON_STRATEGY_ELEMENT_IDENTIFIER.equals(strategy.getIdentifier().getName()) ? typeLoader.load(CronScheduler.class) : typeLoader.load(FixedFrequencyScheduler.class);
dsl.resolve(type).ifPresent(typeDsl -> wrapper.containing(DslElementModel.builder().withModel(type).withDsl(typeDsl).withConfig(strategy).build()));
}
groupElementBuilder.containing(wrapper.build());
}
return;
}
}
use of org.mule.runtime.api.component.ComponentIdentifier in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method addConnectionProvider.
private DslElementModel.Builder<ConfigurationModel> addConnectionProvider(ConfigurationModel model, DslSyntaxResolver dsl, DslElementModel.Builder<ConfigurationModel> element, ComponentConfiguration configuration) {
concat(model.getConnectionProviders().stream(), currentExtension.getConnectionProviders().stream()).map(provider -> {
DslElementSyntax providerDsl = dsl.resolve(provider);
ComponentIdentifier identifier = getIdentifier(providerDsl).orElse(null);
return configuration.getNestedComponents().stream().filter(c -> c.getIdentifier().equals(identifier)).findFirst().map(providerConfig -> element.containing(createElementModel(provider, providerDsl, providerConfig).build())).orElse(null);
}).filter(Objects::nonNull).findFirst();
return element;
}
use of org.mule.runtime.api.component.ComponentIdentifier in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method addElementParameter.
private void addElementParameter(Multimap<ComponentIdentifier, ComponentConfiguration> innerComponents, Map<String, String> parameters, DslElementSyntax groupDsl, DslElementModel.Builder<ParameterGroupModel> groupElementBuilder, ParameterModel paramModel) {
groupDsl.getContainedElement(paramModel.getName()).ifPresent(paramDsl -> {
if (isInfrastructure(paramModel)) {
handleInfrastructure(paramModel, paramDsl, innerComponents, parameters, groupElementBuilder);
return;
}
ComponentConfiguration paramComponent = getSingleComponentConfiguration(innerComponents, getIdentifier(paramDsl));
if (paramDsl.isWrapped()) {
resolveWrappedElement(groupElementBuilder, paramModel, paramDsl, paramComponent);
return;
}
String value = paramDsl.supportsAttributeDeclaration() ? parameters.get(paramDsl.getAttributeName()) : null;
Optional<String> defaultValue = getDefaultValue(paramModel);
if (paramComponent != null || !isBlank(value) || defaultValue.isPresent()) {
DslElementModel.Builder<ParameterModel> paramElementBuilder = DslElementModel.<ParameterModel>builder().withModel(paramModel).withDsl(paramDsl);
if (paramComponent != null && !isContent(paramModel)) {
paramElementBuilder.withConfig(paramComponent);
paramModel.getType().accept(new MetadataTypeVisitor() {
@Override
public void visitArrayType(ArrayType arrayType) {
MetadataType itemType = arrayType.getType();
paramDsl.getGeneric(itemType).ifPresent(itemdsl -> {
ComponentIdentifier itemIdentifier = getIdentifier(itemdsl).get();
paramComponent.getNestedComponents().forEach(c -> {
if (c.getIdentifier().equals(itemIdentifier)) {
itemType.accept(getComponentChildVisitor(paramElementBuilder, c, itemType, VALUE_ATTRIBUTE_NAME, itemdsl, defaultValue, new ArrayDeque<>()));
}
});
});
}
@Override
public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
populateMapEntries(objectType, paramDsl, paramElementBuilder, paramComponent);
return;
}
populateObjectFields(objectType, paramComponent, paramDsl, paramElementBuilder, new ArrayDeque<>());
}
});
} else {
if (isBlank(value)) {
if (paramComponent != null && paramComponent.getValue().isPresent() && !isBlank(paramComponent.getValue().get())) {
value = paramComponent.getValue().get().trim();
} else if (defaultValue.isPresent()) {
value = defaultValue.get();
paramElementBuilder.isExplicitInDsl(false);
}
}
paramElementBuilder.withValue(value);
}
groupElementBuilder.containing(paramElementBuilder.build());
}
});
}
use of org.mule.runtime.api.component.ComponentIdentifier in project mule by mulesoft.
the class SecureConfigurationPropertiesProviderFactory method createProvider.
@Override
public SecureConfigurationPropertiesProvider createProvider(ConfigurationParameters parameters, ResourceProvider externalResourceProvider) {
String file = parameters.getStringParameter("file");
Preconditions.checkArgument(file != null, "Required attribute 'file' of 'secure-configuration-properties' not found");
ComponentIdentifier encryptComponentIdentifier = ComponentIdentifier.builder().namespace(EXTENSION_NAME).name("encrypt").build();
String algorithm = parameters.getComplexConfigurationParameter(encryptComponentIdentifier).get(0).getStringParameter("algorithm");
String mode = parameters.getComplexConfigurationParameter(encryptComponentIdentifier).get(0).getStringParameter("mode");
return new SecureConfigurationPropertiesProvider(externalResourceProvider, file, algorithm, mode);
}
use of org.mule.runtime.api.component.ComponentIdentifier in project mule by mulesoft.
the class ExtensionErrorsRegistrant method getErrorType.
private ErrorType getErrorType(ErrorModel errorModel, ExtensionModel extensionModel) {
ComponentIdentifier identifier = createIdentifier(errorModel.getType(), errorModel.getNamespace());
Optional<ErrorType> optionalError = errorTypeRepository.getErrorType(identifier);
return optionalError.orElseGet(() -> createErrorType(errorModel, identifier, extensionModel));
}
Aggregations