Search in sources :

Example 1 with ParameterMetadataDescriptor

use of org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor 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());
}
Also used : ParameterMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor) ParameterMetadataDescriptorBuilder(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor.ParameterMetadataDescriptorBuilder) MetadataType(org.mule.metadata.api.model.MetadataType)

Example 2 with ParameterMetadataDescriptor

use of org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor in project mule by mulesoft.

the class MetadataInputDelegate method getInputMetadataDescriptors.

/**
 * For each of the Component's {@link ParameterModel} creates the corresponding {@link TypeMetadataDescriptor} using only its
 * static {@link MetadataType} and ignoring if any parameter has a dynamic type.
 *
 * @return A {@link List} containing a {@link MetadataResult} of {@link TypeMetadataDescriptor} for each input parameter using
 * only its static {@link MetadataType} and ignoring if any parameter has a dynamic type.
 */
MetadataResult<InputMetadataDescriptor> getInputMetadataDescriptors(MetadataContext context, Object key) {
    InputMetadataDescriptor.InputMetadataDescriptorBuilder input = InputMetadataDescriptor.builder();
    List<MetadataResult<ParameterMetadataDescriptor>> results = new LinkedList<>();
    for (ParameterModel parameter : component.getAllParameterModels()) {
        MetadataResult<ParameterMetadataDescriptor> result = getParameterMetadataDescriptor(parameter, context, key);
        input.withParameter(parameter.getName(), result.get());
        results.add(result);
    }
    List<MetadataFailure> failures = results.stream().flatMap(e -> e.getFailures().stream()).collect(toList());
    return failures.isEmpty() ? success(input.build()) : failure(input.build(), failures);
}
Also used : InputMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.InputMetadataDescriptor) ParameterMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor) MetadataResult.success(org.mule.runtime.api.metadata.resolving.MetadataResult.success) MetadataResult(org.mule.runtime.api.metadata.resolving.MetadataResult) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) InputMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.InputMetadataDescriptor) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) MetadataTypeUtils.isNullType(org.mule.metadata.api.utils.MetadataTypeUtils.isNullType) TypeMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.TypeMetadataDescriptor) MetadataKey(org.mule.runtime.api.metadata.MetadataKey) NO_DYNAMIC_TYPE_AVAILABLE(org.mule.runtime.api.metadata.resolving.FailureCode.NO_DYNAMIC_TYPE_AVAILABLE) LinkedList(java.util.LinkedList) InputTypeResolver(org.mule.runtime.api.metadata.resolving.InputTypeResolver) MetadataTypeUtils.isCollection(org.mule.metadata.api.utils.MetadataTypeUtils.isCollection) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation) String.format(java.lang.String.format) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) MetadataContext(org.mule.runtime.api.metadata.MetadataContext) Builder.newFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure.Builder.newFailure) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) ParameterMetadataDescriptorBuilder(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor.ParameterMetadataDescriptorBuilder) NamedTypeResolver(org.mule.runtime.api.metadata.resolving.NamedTypeResolver) MetadataFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure) JavaTypeUtils.getType(org.mule.metadata.java.api.utils.JavaTypeUtils.getType) MetadataResult.failure(org.mule.runtime.api.metadata.resolving.MetadataResult.failure) ParameterMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) MetadataFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure) LinkedList(java.util.LinkedList) MetadataResult(org.mule.runtime.api.metadata.resolving.MetadataResult)

Example 3 with ParameterMetadataDescriptor

use of org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor in project mule by mulesoft.

the class MetadataMediator method resolveParameterGroupModelType.

private List<ParameterGroupModel> resolveParameterGroupModelType(List<ParameterGroupModel> untypedParameterGroups, Map<String, ParameterMetadataDescriptor> inputTypeDescriptors) {
    List<ParameterGroupModel> parameterGroups = new LinkedList<>();
    untypedParameterGroups.forEach(parameterGroup -> {
        List<ParameterModel> parameters = new LinkedList<>();
        parameterGroup.getParameterModels().forEach(parameterModel -> {
            ParameterMetadataDescriptor parameterMetadataDescriptor = inputTypeDescriptors.get(parameterModel.getName());
            ParameterModel typedParameterModel = new ImmutableParameterModel(parameterModel.getName(), parameterModel.getDescription(), parameterMetadataDescriptor.getType(), parameterMetadataDescriptor.isDynamic(), parameterModel.isRequired(), parameterModel.isOverrideFromConfig(), parameterModel.getExpressionSupport(), parameterModel.getDefaultValue(), parameterModel.getRole(), parameterModel.getDslConfiguration(), parameterModel.getDisplayModel().orElse(null), parameterModel.getLayoutModel().orElse(null), parameterModel.getValueProviderModel().orElse(null), parameterModel.getAllowedStereotypes(), parameterModel.getModelProperties());
            parameters.add(typedParameterModel);
        });
        parameterGroups.add(new ImmutableParameterGroupModel(parameterGroup.getName(), parameterGroup.getDescription(), parameters, parameterGroup.getExclusiveParametersModels(), parameterGroup.isShowInDsl(), parameterGroup.getDisplayModel().orElse(null), parameterGroup.getLayoutModel().orElse(null), parameterGroup.getModelProperties()));
    });
    return parameterGroups;
}
Also used : ParameterMetadataDescriptor(org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor) ImmutableParameterModel(org.mule.runtime.extension.api.model.parameter.ImmutableParameterModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) ImmutableParameterGroupModel(org.mule.runtime.extension.api.model.parameter.ImmutableParameterGroupModel) ImmutableParameterGroupModel(org.mule.runtime.extension.api.model.parameter.ImmutableParameterGroupModel) LinkedList(java.util.LinkedList) ImmutableParameterModel(org.mule.runtime.extension.api.model.parameter.ImmutableParameterModel)

Aggregations

ParameterMetadataDescriptor (org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor)3 LinkedList (java.util.LinkedList)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)2 ParameterMetadataDescriptorBuilder (org.mule.runtime.api.metadata.descriptor.ParameterMetadataDescriptor.ParameterMetadataDescriptorBuilder)2 String.format (java.lang.String.format)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1 MetadataTypeUtils.isCollection (org.mule.metadata.api.utils.MetadataTypeUtils.isCollection)1 MetadataTypeUtils.isNullType (org.mule.metadata.api.utils.MetadataTypeUtils.isNullType)1 ClassInformationAnnotation (org.mule.metadata.java.api.annotation.ClassInformationAnnotation)1 JavaTypeUtils.getType (org.mule.metadata.java.api.utils.JavaTypeUtils.getType)1 ComponentModel (org.mule.runtime.api.meta.model.ComponentModel)1 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)1 MetadataContext (org.mule.runtime.api.metadata.MetadataContext)1 MetadataKey (org.mule.runtime.api.metadata.MetadataKey)1 MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)1 InputMetadataDescriptor (org.mule.runtime.api.metadata.descriptor.InputMetadataDescriptor)1 TypeMetadataDescriptor (org.mule.runtime.api.metadata.descriptor.TypeMetadataDescriptor)1