use of org.mule.runtime.api.meta.model.construct.ConstructModel in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method create.
public <T> Optional<DslElementModel<T>> create(ElementDeclaration declaration) {
setupCurrentExtensionContext(declaration.getDeclaringExtension());
final Function<NamedObject, Boolean> equalsName = (named) -> named.getName().equals(declaration.getName());
if (declaration instanceof TopLevelParameterDeclaration) {
return createFromType((TopLevelParameterDeclaration) declaration);
}
Reference<DslElementModel> elementModel = new Reference<>();
new ExtensionWalker() {
@Override
protected void onConfiguration(ConfigurationModel model) {
if (equalsName.apply(model) && declaration instanceof ConfigurationElementDeclaration) {
elementModel.set(createConfigurationElement(model, (ConfigurationElementDeclaration) declaration));
stop();
}
}
@Override
protected void onOperation(HasOperationModels owner, OperationModel model) {
if (equalsName.apply(model) && declaration instanceof OperationElementDeclaration) {
elementModel.set(createComponentElement(model, (OperationElementDeclaration) declaration));
stop();
}
}
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
if (equalsName.apply(model) && declaration instanceof ConstructElementDeclaration) {
elementModel.set(createComponentElement(model, (ConstructElementDeclaration) declaration));
stop();
}
}
@Override
protected void onSource(HasSourceModels owner, SourceModel model) {
if (equalsName.apply(model) && declaration instanceof SourceElementDeclaration) {
elementModel.set(createComponentElement(model, (SourceElementDeclaration) declaration));
stop();
}
}
}.walk(currentExtension);
if (LOGGER.isDebugEnabled() && elementModel.get() == null) {
LOGGER.debug(format("No model found with name [%s] of type [%s] for extension [%s]", declaration.getName(), declaration.getClass().getName(), declaration.getDeclaringExtension()));
}
return Optional.ofNullable(elementModel.get());
}
use of org.mule.runtime.api.meta.model.construct.ConstructModel in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method getComponentDeclaringWalker.
private ExtensionWalker getComponentDeclaringWalker(final Consumer<ComponentElementDeclaration> declarationConsumer, final ConfigLine line, final ElementDeclarer extensionElementsDeclarer) {
final DslSyntaxResolver dsl = resolvers.get(getNamespace(line));
return new ExtensionWalker() {
@Override
protected void onOperation(HasOperationModels owner, OperationModel model) {
if (!model.getName().equals(TRANSFORM_IDENTIFIER)) {
declareComponentModel(line, model, extensionElementsDeclarer::newOperation).ifPresent(declarer -> {
declarationConsumer.accept((ComponentElementDeclaration) declarer.getDeclaration());
stop();
});
} else {
declareTransform(model);
}
}
@Override
protected void onSource(HasSourceModels owner, SourceModel model) {
declareComponentModel(line, model, extensionElementsDeclarer::newSource).ifPresent(declarer -> {
final DslElementSyntax elementDsl = dsl.resolve(model);
model.getSuccessCallback().ifPresent(cb -> declareParameterizedComponent(cb, elementDsl, declarer, line.getConfigAttributes(), line.getChildren()));
model.getErrorCallback().ifPresent(cb -> declareParameterizedComponent(cb, elementDsl, declarer, line.getConfigAttributes(), line.getChildren()));
declarationConsumer.accept((ComponentElementDeclaration) declarer.getDeclaration());
stop();
});
}
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
declareComponentModel(line, model, extensionElementsDeclarer::newConstruct).ifPresent(declarer -> {
declarationConsumer.accept((ComponentElementDeclaration) declarer.getDeclaration());
stop();
});
}
private void declareTransform(ComponentModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
if (model.getName().equals(TRANSFORM_IDENTIFIER) && elementDsl.getElementName().equals(line.getIdentifier())) {
ComponentElementDeclarer transform = extensionElementsDeclarer.newOperation(TRANSFORM_IDENTIFIER);
line.getChildren().stream().filter(c -> c.getIdentifier().equals("message")).findFirst().ifPresent(messageConfig -> {
ParameterGroupElementDeclarer messageGroup = newParameterGroup("Message");
messageConfig.getChildren().stream().filter(c -> c.getIdentifier().equals("set-payload")).findFirst().ifPresent(payloadConfig -> {
ParameterObjectValue.Builder payload = newObjectValue();
populateTransformScriptParameter(payloadConfig, payload);
messageGroup.withParameter("setPayload", payload.build());
});
messageConfig.getChildren().stream().filter(c -> c.getIdentifier().equals("set-attributes")).findFirst().ifPresent(attributesConfig -> {
ParameterObjectValue.Builder attributes = newObjectValue();
populateTransformScriptParameter(attributesConfig, attributes);
messageGroup.withParameter("setAttributes", attributes.build());
});
transform.withParameterGroup(messageGroup.getDeclaration());
});
line.getChildren().stream().filter(c -> c.getIdentifier().equals("variables")).findFirst().ifPresent(variablesConfig -> {
ParameterGroupElementDeclarer variablesGroup = newParameterGroup("Set Variables");
ParameterListValue.Builder variables = newListValue();
variablesConfig.getChildren().forEach(variableConfig -> {
ParameterObjectValue.Builder variable = newObjectValue();
variable.withParameter(TRANSFORM_VARIABLE_NAME, variableConfig.getConfigAttributes().get(TRANSFORM_VARIABLE_NAME).getValue());
populateTransformScriptParameter(variableConfig, variable);
variables.withValue(variable.build());
});
transform.withParameterGroup(variablesGroup.withParameter("setVariables", variables.build()).getDeclaration());
});
line.getConfigAttributes().values().forEach(a -> transform.withCustomParameter(a.getName(), a.getValue()));
declarationConsumer.accept((ComponentElementDeclaration) transform.getDeclaration());
stop();
}
}
};
}
use of org.mule.runtime.api.meta.model.construct.ConstructModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method splitAggregate.
@Test
public void splitAggregate() {
final ConstructModel splitAggregate = coreExtensionModel.getConstructModel("splitAggregate").get();
NestableElementModel processorsChain = splitAggregate.getNestedComponents().get(0);
assertThat(processorsChain, instanceOf(NestedChainModel.class));
assertThat(processorsChain.isRequired(), is(true));
assertThat(splitAggregate.getAllParameterModels(), hasSize(5));
assertThat(splitAggregate.getAllParameterModels().get(0).getName(), is("collection"));
assertThat(splitAggregate.getAllParameterModels().get(0).getExpressionSupport(), is(REQUIRED));
assertThat(splitAggregate.getAllParameterModels().get(0).getType(), instanceOf(DefaultStringType.class));
assertThat(splitAggregate.getAllParameterModels().get(0).isRequired(), is(false));
assertThat(splitAggregate.getAllParameterModels().get(1).getName(), is("timeout"));
assertThat(splitAggregate.getAllParameterModels().get(1).getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(splitAggregate.getAllParameterModels().get(1).getType(), instanceOf(DefaultNumberType.class));
assertThat(splitAggregate.getAllParameterModels().get(1).isRequired(), is(false));
assertThat(splitAggregate.getAllParameterModels().get(2).getName(), is("maxConcurrency"));
assertThat(splitAggregate.getAllParameterModels().get(2).getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(splitAggregate.getAllParameterModels().get(2).getType(), instanceOf(DefaultNumberType.class));
assertThat(splitAggregate.getAllParameterModels().get(2).isRequired(), is(false));
assertThat(splitAggregate.getAllParameterModels().get(3).getName(), is(TARGET_PARAMETER_NAME));
assertThat(splitAggregate.getAllParameterModels().get(3).getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(splitAggregate.getAllParameterModels().get(3).getType(), instanceOf(DefaultStringType.class));
assertThat(splitAggregate.getAllParameterModels().get(3).isRequired(), is(false));
assertThat(splitAggregate.getAllParameterModels().get(4).getName(), is(TARGET_VALUE_PARAMETER_NAME));
assertThat(splitAggregate.getAllParameterModels().get(4).getExpressionSupport(), is(REQUIRED));
assertThat(splitAggregate.getAllParameterModels().get(4).getType(), instanceOf(StringType.class));
assertThat(splitAggregate.getAllParameterModels().get(4).isRequired(), is(false));
}
use of org.mule.runtime.api.meta.model.construct.ConstructModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method flow.
@Test
public void flow() {
final ConstructModel flow = coreExtensionModel.getConstructModel("flow").get();
assertThat(flow.getStereotype().getType(), is(FLOW.getType()));
assertThat(flow.allowsTopLevelDeclaration(), is(true));
final List<ParameterModel> paramModels = flow.getAllParameterModels();
assertThat(paramModels, hasSize(2));
ParameterModel initialState = paramModels.get(0);
assertThat(initialState.getName(), is("initialState"));
assertThat(initialState.getDefaultValue(), is("started"));
ParameterModel maxConcurrency = paramModels.get(1);
assertThat(maxConcurrency.getName(), is("maxConcurrency"));
List<? extends NestableElementModel> nestedComponents = flow.getNestedComponents();
assertThat(nestedComponents, hasSize(3));
NestableElementModel source = nestedComponents.get(0);
assertThat(source.getName(), is("source"));
assertThat(source.isRequired(), is(false));
assertThat(source, instanceOf(NestedComponentModel.class));
assertThat(((NestedComponentModel) source).getAllowedStereotypes(), contains(SOURCE));
NestableElementModel chain = nestedComponents.get(1);
assertThat(chain.getName(), is("processors"));
assertThat(chain.isRequired(), is(true));
assertThat(chain, instanceOf(NestedChainModel.class));
assertThat(((NestedChainModel) chain).getAllowedStereotypes().stream().anyMatch(s -> s.getType().equals(PROCESSOR.getType())), is(true));
NestableElementModel errorHandler = nestedComponents.get(2);
assertThat(errorHandler.getName(), is("errorHandler"));
assertThat(errorHandler.isRequired(), is(false));
assertThat(errorHandler, instanceOf(NestedComponentModel.class));
assertThat(((NestedComponentModel) errorHandler).getAllowedStereotypes(), contains(ERROR_HANDLER));
}
use of org.mule.runtime.api.meta.model.construct.ConstructModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method untilSuccessful.
@Test
public void untilSuccessful() {
final ConstructModel tryModel = coreExtensionModel.getConstructModel("untilSuccessful").get();
List<ParameterModel> allParameterModels = tryModel.getAllParameterModels();
assertThat(allParameterModels, hasSize(2));
ParameterModel action = allParameterModels.get(0);
assertThat(action.getName(), is("maxRetries"));
assertThat(action.getType(), is(instanceOf(DefaultNumberType.class)));
assertThat(action.getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(action.getDefaultValue(), is(5));
assertThat(action.isRequired(), is(false));
ParameterModel type = allParameterModels.get(1);
assertThat(type.getName(), is("millisBetweenRetries"));
assertThat(type.getType(), is(instanceOf(DefaultNumberType.class)));
assertThat(type.getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(type.getDefaultValue(), is(60000));
assertThat(type.isRequired(), is(false));
}
Aggregations