use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class OperationModelLoaderDelegate method processBlockingOperation.
private void processBlockingOperation(boolean supportsConfig, MethodElement operationMethod, OperationDeclarer operation) {
operation.blocking(true);
operation.withOutputAttributes().ofType(operationMethod.getAttributesMetadataType());
final MetadataType outputType = operationMethod.getReturnMetadataType();
if (isAutoPaging(operationMethod)) {
operation.supportsStreaming(true).withOutput().ofType(outputType);
addPagedOperationModelProperty(operationMethod, operation, supportsConfig);
processPagingTx(operation, operationMethod);
} else {
operation.withOutput().ofType(outputType);
handleByteStreaming(operationMethod, operation, outputType);
}
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class ParameterModelsLoaderDelegate method parseNullSafe.
private void parseNullSafe(ExtensionParameter extensionParameter, ParameterDeclarer parameter) {
if (extensionParameter.isAnnotatedWith(NullSafe.class)) {
if (extensionParameter.isAnnotatedWith(ConfigOverride.class)) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' and also marked as a config override, which is redundant. " + "The default value for this parameter will come from the configuration parameter", extensionParameter.getName(), NullSafe.class.getSimpleName()));
}
if (extensionParameter.isRequired() && !extensionParameter.isAnnotatedWith(ParameterGroup.class)) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is required but annotated with '@%s', which is redundant", extensionParameter.getName(), NullSafe.class.getSimpleName()));
}
Type nullSafeAnnotationType = extensionParameter.getValueFromAnnotation(NullSafe.class).get().getClassValue(NullSafe::defaultImplementingType);
final boolean hasDefaultOverride = !nullSafeAnnotationType.isSameType(Object.class);
MetadataType nullSafeType = hasDefaultOverride ? nullSafeAnnotationType.asMetadataType() : parameter.getDeclaration().getType();
boolean isInstantiable = hasDefaultOverride ? nullSafeAnnotationType.isInstantiable() : extensionParameter.getType().isInstantiable();
parameter.getDeclaration().getType().accept(new BasicTypeMetadataVisitor() {
@Override
protected void visitBasicType(MetadataType metadataType) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' but is of type '%s'. That annotation can only be " + "used with complex types (Pojos, Lists, Maps)", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName()));
}
@Override
public void visitArrayType(ArrayType arrayType) {
if (hasDefaultOverride) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' is of type '%s'" + " but a 'defaultImplementingType' was provided." + " Type override is not allowed for Collections", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName()));
}
}
@Override
public void visitObject(ObjectType objectType) {
if (hasDefaultOverride && isMap(objectType)) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' is of type '%s'" + " but a 'defaultImplementingType' was provided." + " Type override is not allowed for Maps", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName()));
}
if (hasDefaultOverride && extensionParameter.getType().isInstantiable()) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' is of concrete type '%s'," + " but a 'defaultImplementingType' was provided." + " Type override is not allowed for concrete types", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName()));
}
if (!isInstantiable && !isMap(nullSafeType)) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' but is of type '%s'. That annotation can only be " + "used with complex instantiable types (Pojos, Lists, Maps)", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName()));
}
if (hasDefaultOverride && !extensionParameter.getType().isAssignableFrom(nullSafeAnnotationType)) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' of type '%s', but provided type '%s" + " is not a subtype of the parameter's type", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName(), getType(nullSafeType).getName()));
}
}
});
parameter.withModelProperty(new NullSafeModelProperty(nullSafeType));
if (hasDefaultOverride) {
parameter.withModelProperty(new DefaultImplementingTypeModelProperty(nullSafeType));
}
}
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class MetadataInputDelegate method getParameterMetadataDescriptor.
/**
* Creates a {@link TypeMetadataDescriptor} representing the Component's Content metadata using the
* {@link InputTypeResolver}, if one is available to resolve the {@link MetadataType}. If no the Component has no Content
* parameter, then {@link Optional#empty()} is returned.
*
* @param context current {@link MetadataContext} that will be used by the {@link InputTypeResolver}
* @param key {@link MetadataKey} of the type which's structure has to be resolved
* @return Success with an {@link Optional} {@link TypeMetadataDescriptor} representing the Component's Content metadata,
* resolved using the {@link InputTypeResolver} if one is available to resolve its {@link MetadataType}, returning
* {@link Optional#empty()} if no Content parameter is present Failure if the dynamic resolution fails for any reason.
*/
private MetadataResult<ParameterMetadataDescriptor> getParameterMetadataDescriptor(ParameterModel parameter, MetadataContext context, Object key) {
ParameterMetadataDescriptorBuilder descriptorBuilder = ParameterMetadataDescriptor.builder(parameter.getName());
if (!parameter.hasDynamicType()) {
return success(descriptorBuilder.withType(parameter.getType()).build());
}
descriptorBuilder.dynamic(true);
MetadataResult<MetadataType> inputMetadataResult = getParameterMetadata(parameter, context, key);
MetadataType type = inputMetadataResult.get() == null ? parameter.getType() : inputMetadataResult.get();
ParameterMetadataDescriptor descriptor = descriptorBuilder.withType(type).build();
return inputMetadataResult.isSuccess() ? success(descriptor) : failure(descriptor, inputMetadataResult.getFailures());
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class MetadataOutputDelegate method adaptToListIfNecessary.
private MetadataType adaptToListIfNecessary(MetadataType resolvedType, Object key, MetadataContext metadataContext) throws MetadataResolvingException {
MetadataType componentOutputType = ((HasOutputModel) component).getOutput().getType();
if (!isCollection(componentOutputType) || isVoid(resolvedType) || isNullType(resolvedType)) {
return resolvedType;
}
MetadataType collectionValueType = ((ArrayType) componentOutputType).getType();
Class<?> collectionType = getCollectionType(collectionValueType);
if (Message.class.equals(collectionType)) {
MessageMetadataType message = (MessageMetadataType) collectionValueType;
resolvedType = wrapInMessageType(resolvedType, key, metadataContext, message.getAttributesType());
}
return metadataContext.getTypeBuilder().arrayType().with(new ClassInformationAnnotation(getCollectionType(componentOutputType))).of(resolvedType).build();
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class MetadataOutputDelegate method toMetadataDescriptorResult.
private MetadataResult<TypeMetadataDescriptor> toMetadataDescriptorResult(MetadataType type, boolean isDynamic, MetadataResult<MetadataType> result) {
MetadataType resultingType = result.get() == null ? type : result.get();
TypeMetadataDescriptor descriptor = TypeMetadataDescriptor.builder().withType(resultingType).dynamic(isDynamic).build();
return result.isSuccess() ? success(descriptor) : failure(descriptor, result.getFailures());
}
Aggregations