Merge "Take advantage of MultipartTransactionAware"
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / Validate.java
index 24611c26cd5030637daed3c3a0aa884afa842a4e..33432e45dfcfcc5c3a82b8d399f807a4d7b38fdf 100644 (file)
@@ -8,7 +8,9 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.operations;
 
-import com.google.common.base.Preconditions;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.opendaylight.controller.config.api.ValidationException;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
@@ -23,8 +25,7 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import java.util.HashMap;
-import java.util.Map;
+import com.google.common.base.Preconditions;
 
 public class Validate extends AbstractConfigNetconfOperation {
 
@@ -62,16 +63,18 @@ public class Validate extends AbstractConfigNetconfOperation {
     }
 
     @Override
-    protected Element handle(Document document, XmlElement xml) throws NetconfDocumentedException {
+    protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
         try {
             checkXml(xml);
         } catch (IllegalStateException e) {
+            //FIXME where can IllegalStateException  be thrown? I see precondition that guards for programming bugs..
             logger.warn("Rpc error: {}", ErrorTag.missing_attribute, e);
             final Map<String, String> errorInfo = new HashMap<>();
             errorInfo.put(ErrorTag.missing_attribute.name(), "Missing value of datastore attribute");
             throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.missing_attribute,
                     ErrorSeverity.error, errorInfo);
         } catch (final IllegalArgumentException e) {
+            // FIXME use checked exception if it has domain meaning
             logger.warn("Rpc error: {}", ErrorTag.bad_attribute, e);
             final Map<String, String> errorInfo = new HashMap<>();
             errorInfo.put(ErrorTag.bad_attribute.name(), e.getMessage());
@@ -83,10 +86,7 @@ public class Validate extends AbstractConfigNetconfOperation {
             transactionProvider.validateTransaction();
         } catch (ValidationException e) {
             logger.warn("Validation failed", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.operation_failed.name(), "Validation failed");
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
-                    ErrorSeverity.error, errorInfo);
+            throw NetconfDocumentedException.wrap(e);
         } catch (IllegalStateException e) {
             logger.warn("Validation failed", e);
             final Map<String, String> errorInfo = new HashMap<>();