use of org.mule.runtime.extension.api.annotation.error.ErrorTypes 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);
}
}
}
Aggregations