use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method streamingHintOnSource.
@Test
public void streamingHintOnSource() throws Exception {
ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
SourceModel sourceModel = extensionModel.getConfigurationModels().get(0).getSourceModel("ListenPayments").get();
ParameterModel streamingParameter = sourceModel.getAllParameterModels().stream().filter(p -> p.getName().equals(STREAMING_STRATEGY_PARAMETER_NAME)).findFirst().get();
assertStreamingStrategy(streamingParameter);
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class BytesStreamingExtensionTestCase method streamingStrategyParameterInSource.
@Test
@Description("Streaming source has a streaming strategy parameter")
public void streamingStrategyParameterInSource() throws Exception {
ParameterModel streamingParameter = getStreamingStrategyParameterModel(() -> getConfigurationModel().getSourceModel("bytes-caster").get());
assertStreamingStrategyParameter(streamingParameter);
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class BytesStreamingExtensionTestCase method streamingStrategyParameterInOperation.
@Test
@Description("Streaming operation has a streaming strategy parameter")
public void streamingStrategyParameterInOperation() throws Exception {
ParameterModel streamingParameter = getStreamingStrategyParameterModel(() -> getConfigurationModel().getOperationModel("toStream").get());
assertStreamingStrategyParameter(streamingParameter);
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class NullSafeModelValidator method validate.
@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problemsReporter) {
ReflectionCache reflectionCache = new ReflectionCache();
TypeLoader typeLoader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
new ExtensionWalker() {
@Override
public void onParameter(ParameterizedModel owner, ParameterGroupModel groupModel, ParameterModel model) {
model.getType().accept(new MetadataTypeVisitor() {
@Override
public void visitObject(ObjectType objectType) {
if (objectType.getMetadataFormat().equals(JAVA) && !isMap(objectType)) {
objectType.getAnnotation(TypeIdAnnotation.class).map(TypeIdAnnotation::getValue).ifPresent(typeId -> typeLoader.load(typeId).ifPresent(fieldMetadataType -> objectType.getFields().stream().filter(f -> f.getAnnotation(NullSafeTypeAnnotation.class).isPresent()).forEach(f -> validateField(getLocalPart(f), f, getType(fieldMetadataType), f.getAnnotation(NullSafeTypeAnnotation.class).get()))));
}
}
private void validateField(String fieldName, ObjectFieldType field, Class<?> declaringClass, NullSafeTypeAnnotation nullSafeTypeAnnotation) {
Class<?> nullSafeType = nullSafeTypeAnnotation.getType();
Class<?> fieldType = getType(field.getValue());
boolean hasDefaultOverride = nullSafeTypeAnnotation.hasDefaultOverride();
field.getValue().accept(new BasicTypeMetadataVisitor() {
@Override
protected void visitBasicType(MetadataType metadataType) {
problemsReporter.addError(new Problem(extensionModel, format("Field '%s' in class '%s' is annotated with '@%s' but is of type '%s'. That annotation can only be " + "used with complex types (Pojos, Lists, Maps)", fieldName, declaringClass.getName(), NullSafe.class.getSimpleName(), fieldType.getName())));
}
@Override
public void visitArrayType(ArrayType arrayType) {
if (hasDefaultOverride) {
problemsReporter.addError(new Problem(extensionModel, format("Field '%s' in class '%s' is annotated with '@%s' is of type '%s'" + " but a 'defaultImplementingType' was provided." + " Type override is not allowed for Collections", fieldName, declaringClass.getName(), NullSafe.class.getSimpleName(), fieldType.getName())));
}
}
@Override
public void visitObject(ObjectType objectType) {
String requiredFields = objectType.getFields().stream().filter(f -> f.isRequired() && !isFlattenedParameterGroup(f)).map(MetadataTypeUtils::getLocalPart).collect(joining(", "));
if (!isBlank(requiredFields) && isCompiletime(extensionModel)) {
problemsReporter.addError(new Problem(model, format("Class '%s' cannot be used with '@%s' parameter since it contains non optional fields: [%s]", getId(objectType).orElse(""), NullSafe.class.getSimpleName(), requiredFields)));
}
if (objectType.isOpen()) {
if (hasDefaultOverride) {
problemsReporter.addError(new Problem(model, format("Field '%s' in class '%s' is annotated with '@%s' is of type '%s'" + " but a 'defaultImplementingType' was provided." + " Type override is not allowed for Maps", fieldName, declaringClass.getName(), NullSafe.class.getSimpleName(), fieldType.getName())));
}
return;
}
if (hasDefaultOverride && isInstantiable(fieldType, reflectionCache)) {
problemsReporter.addError(new Problem(model, format("Field '%s' in class '%s' is annotated with '@%s' is of concrete type '%s'," + " but a 'defaultImplementingType' was provided." + " Type override is not allowed for concrete types", fieldName, declaringClass.getName(), NullSafe.class.getSimpleName(), fieldType.getName())));
}
if (!isInstantiable(nullSafeType, reflectionCache)) {
problemsReporter.addError(new Problem(model, format("Field '%s' in class '%s' is annotated with '@%s' but is of type '%s'. That annotation can only be " + "used with complex instantiable types (Pojos, Lists, Maps)", fieldName, declaringClass.getName(), NullSafe.class.getSimpleName(), nullSafeType.getName())));
}
if (hasDefaultOverride && !fieldType.isAssignableFrom(nullSafeType)) {
problemsReporter.addError(new Problem(model, format("Field '%s' in class '%s' is annotated with '@%s' of type '%s', but provided type '%s" + " is not a subtype of the parameter's type", fieldName, declaringClass.getName(), NullSafe.class.getSimpleName(), fieldType.getName(), nullSafeType.getName())));
}
}
});
}
});
}
}.walk(extensionModel);
}
use of org.mule.runtime.api.meta.model.parameter.ParameterModel in project mule by mulesoft.
the class ParametersResolver method getParametersAsResolverSet.
/**
* Constructs a {@link ResolverSet} from the parameters, using {@link #toValueResolver(Object, Set)} to process the values.
*
* @return a {@link ResolverSet}
*/
public ResolverSet getParametersAsResolverSet(ParameterizedModel model, MuleContext muleContext) throws ConfigurationException {
List<ParameterGroupModel> inlineGroups = getInlineGroups(model.getParameterGroupModels());
List<ParameterModel> flatParameters = getFlatParameters(inlineGroups, model.getAllParameterModels());
ResolverSet resolverSet = getParametersAsResolverSet(model, flatParameters, muleContext);
for (ParameterGroupModel group : inlineGroups) {
getInlineGroupResolver(group, resolverSet, muleContext);
}
return resolverSet;
}
Aggregations