use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class JavaDeclarationDelegateTestCase method listOfResultsOperationWithoutGenerics.
@Test
public void listOfResultsOperationWithoutGenerics() throws Exception {
ExtensionDeclarer declarer = loaderFor(HeisenbergWithListOfResultOperations.class).declare(new DefaultExtensionLoadingContext(getClass().getClassLoader(), getDefault(emptySet())));
OperationDeclaration operation = getOperation(declarer.getDeclaration(), "listOfResultsWithoutGenerics");
MetadataType outputType = operation.getOutput().getType();
assertThat(outputType, is(instanceOf(ArrayType.class)));
assertMessageType(((ArrayType) outputType).getType(), TYPE_BUILDER.anyType().build(), TYPE_BUILDER.anyType().build());
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class JavaDeclarationDelegateTestCase method listOfResultsOperation.
@Test
public void listOfResultsOperation() throws Exception {
ExtensionDeclarer declarer = loaderFor(HeisenbergWithListOfResultOperations.class).declare(new DefaultExtensionLoadingContext(getClass().getClassLoader(), getDefault(emptySet())));
OperationDeclaration operation = getOperation(declarer.getDeclaration(), "listOfResults");
MetadataType outputType = operation.getOutput().getType();
assertThat(outputType, is(instanceOf(ArrayType.class)));
assertMessageType(((ArrayType) outputType).getType(), TYPE_LOADER.load(Integer.class), TYPE_LOADER.load(IntegerAttributes.class));
assertThat(operation.getOutputAttributes().getType(), is(instanceOf(VoidType.class)));
}
use of org.mule.metadata.api.model.MetadataType 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.metadata.api.model.MetadataType in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method populateMapEntries.
private void populateMapEntries(ObjectType objectType, DslElementSyntax modelDsl, DslElementModel.Builder mapBuilder, ComponentConfiguration mapConfig) {
mapConfig.getNestedComponents().forEach(entryConfig -> {
MetadataType entryType = objectType.getOpenRestriction().get();
modelDsl.getGeneric(entryType).ifPresent(entryDsl -> {
DslElementModel.Builder<Object> entry = DslElementModel.builder().withModel(entryType).withConfig(entryConfig).withDsl(entryDsl);
entry.containing(DslElementModel.builder().withModel(typeLoader.load(String.class)).withValue(entryConfig.getParameters().get(KEY_ATTRIBUTE_NAME)).withDsl(entryDsl.getAttribute(KEY_ATTRIBUTE_NAME).get()).build());
String value = entryConfig.getParameters().get(VALUE_ATTRIBUTE_NAME);
if (isBlank(value)) {
getComponentChildVisitor(entry, entryConfig, entryType, VALUE_ATTRIBUTE_NAME, entryDsl.getAttribute(VALUE_ATTRIBUTE_NAME).get(), empty(), new ArrayDeque<>());
} else {
entry.containing(DslElementModel.builder().withModel(typeLoader.load(String.class)).withValue(value).withDsl(entryDsl.getAttribute(VALUE_ATTRIBUTE_NAME).get()).build());
}
mapBuilder.containing(entry.build());
});
});
}
use of org.mule.metadata.api.model.MetadataType 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());
}
});
}
Aggregations