Retrofit YangNetconfError into Unique*Exception
[yangtools.git] / data / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / UniqueValidationFailedException.java
index 79e41a926579e42c3d80d9d0aa167101c55f21c6..3a034ff311c0cafd44766413fb61a88307c2e56d 100644 (file)
@@ -7,15 +7,34 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
+import java.util.List;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
+import org.opendaylight.yangtools.yang.data.api.ImmutableYangNetconfError;
+import org.opendaylight.yangtools.yang.data.api.YangNetconfError;
+import org.opendaylight.yangtools.yang.data.api.YangNetconfErrorAware;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.UniqueConstraintException;
 
 /**
  * Exception thrown when unique constraints would be violated and we cannot throw a {@link UniqueConstraintException}.
  */
-final class UniqueValidationFailedException extends SchemaValidationFailedException {
+final class UniqueValidationFailedException extends SchemaValidationFailedException implements YangNetconfErrorAware {
     private static final long serialVersionUID = 1L;
 
     UniqueValidationFailedException(final String message) {
         super(message);
     }
+
+    @Override
+    public List<YangNetconfError> getNetconfErrors() {
+        return List.of(ImmutableYangNetconfError.builder()
+            .severity(ErrorSeverity.ERROR)
+            .type(ErrorType.APPLICATION)
+            .tag(ErrorTag.OPERATION_FAILED)
+            .appTag("data-not-unique")
+            // FIXME: 8.0.0: we are missing path information which should be filled in here. Constructor call site needs
+            //               to provide that.
+            .build());
+    }
 }