Search in sources :

Example 1 with ErrorTypeDefinition

use of org.mule.runtime.extension.api.error.ErrorTypeDefinition in project mule by mulesoft.

the class ErrorsDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclaration declaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
    String extensionNamespace = getExtensionsNamespace(declaration);
    Optional<ExtensionTypeDescriptorModelProperty> implementingType = declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    ErrorsModelFactory errorModelDescriber = new ErrorsModelFactory(extensionNamespace);
    errorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
    if (implementingType.isPresent() && implementingType.get().getType().getDeclaringClass().isPresent()) {
        Type extensionElement = implementingType.get().getType();
        Optional<ErrorTypes> errorAnnotation = extensionElement.getAnnotation(ErrorTypes.class);
        List<Pair<ComponentDeclaration, MethodElement>> errorOperations = collectErrorOperations(declaration);
        if (errorAnnotation.isPresent()) {
            ErrorTypeDefinition<?>[] errorTypes = (ErrorTypeDefinition<?>[]) errorAnnotation.get().value().getEnumConstants();
            if (errorTypes.length > 0) {
                ErrorsModelFactory operationErrorModelDescriber = new ErrorsModelFactory(errorTypes, extensionNamespace);
                operationErrorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
                errorOperations.stream().forEach(pair -> registerOperationErrorTypes(pair.getSecond(), pair.getFirst(), operationErrorModelDescriber, errorTypes, extensionElement));
            } else {
                handleNoErrorTypes(extensionElement, errorOperations);
            }
        } else {
            handleNoErrorTypes(extensionElement, errorOperations);
        }
    }
}
Also used : ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) Pair(org.mule.runtime.api.util.Pair)

Example 2 with ErrorTypeDefinition

use of org.mule.runtime.extension.api.error.ErrorTypeDefinition in project mule by mulesoft.

the class ErrorsModelFactory method addType.

private void addType(ErrorTypeDefinition<?> errorType, Graph<ErrorTypeDefinition, Pair<ErrorTypeDefinition, ErrorTypeDefinition>> graph) {
    graph.addVertex(errorType);
    String type = errorType.getType();
    if (!ANY.name().equals(type) && !CRITICAL.name().equals(type)) {
        ErrorTypeDefinition parentErrorType = errorType.getParent().orElse((ANY));
        graph.addVertex(parentErrorType);
        graph.addEdge(errorType, parentErrorType);
    }
}
Also used : ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition)

Aggregations

ErrorTypeDefinition (org.mule.runtime.extension.api.error.ErrorTypeDefinition)2 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)1 Pair (org.mule.runtime.api.util.Pair)1 ErrorTypes (org.mule.runtime.extension.api.annotation.error.ErrorTypes)1 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)1 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)1