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);
}
}
}
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);
}
}
Aggregations