Remove DocumentedException.ErrorType
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / transactions / NetconfRestconfTransaction.java
index f5c48882d7072ce5856a4223491e09ca19f68d08..635042114a77ccca546d226175dc2dd13e68da67 100644 (file)
@@ -34,6 +34,8 @@ import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
@@ -211,8 +213,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
                             return operation.get();
                         } else {
                             return Futures.immediateFailedFuture(new NetconfDocumentedException("Lock operation failed",
-                                DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.LOCK_DENIED,
-                                DocumentedException.ErrorSeverity.ERROR));
+                                ErrorType.APPLICATION, DocumentedException.ErrorTag.LOCK_DENIED, ErrorSeverity.ERROR));
                         }
                     },
                     MoreExecutors.directExecutor());
@@ -248,35 +249,13 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
             justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static TransactionCommitFailedException toCommitFailedException(
             final Collection<? extends RpcError> errors) {
-        DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
-        DocumentedException.ErrorSeverity errSeverity = DocumentedException.ErrorSeverity.ERROR;
+        ErrorType errType = ErrorType.APPLICATION;
+        ErrorSeverity errSeverity = ErrorSeverity.ERROR;
         StringJoiner msgBuilder = new StringJoiner(" ");
         String errorTag = "operation-failed";
         for (final RpcError error : errors) {
-            switch (error.getErrorType()) {
-                case RPC:
-                    errType = DocumentedException.ErrorType.RPC;
-                    break;
-                case PROTOCOL:
-                    errType = DocumentedException.ErrorType.PROTOCOL;
-                    break;
-                case TRANSPORT:
-                    errType = DocumentedException.ErrorType.TRANSPORT;
-                    break;
-                case APPLICATION:
-                default:
-                    errType = DocumentedException.ErrorType.APPLICATION;
-                    break;
-            }
-            switch (error.getSeverity()) {
-                case WARNING:
-                    errSeverity = DocumentedException.ErrorSeverity.WARNING;
-                    break;
-                case ERROR:
-                default:
-                    errSeverity = DocumentedException.ErrorSeverity.ERROR;
-                    break;
-            }
+            errType = error.getErrorType().toNetconf();
+            errSeverity = error.getSeverity().toNetconf();
             msgBuilder.add(error.getMessage());
             msgBuilder.add(error.getInfo());
             errorTag = error.getTag();