Remove StoreTreeNodes.getChild()
[yangtools.git] / data / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / tree / UniqueConstraintException.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.api.schema.tree;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14 import java.util.Collections;
15 import java.util.List;
16 import java.util.Map;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
19 import org.opendaylight.yangtools.yang.common.ErrorTag;
20 import org.opendaylight.yangtools.yang.common.ErrorType;
21 import org.opendaylight.yangtools.yang.data.api.ImmutableYangNetconfError;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangNetconfError;
24 import org.opendaylight.yangtools.yang.data.api.YangNetconfErrorAware;
25 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Descendant;
26
27 /**
28  * Exception thrown when a {@code unique} statement restrictions are violated.
29  *
30  * @author Robert Varga
31  */
32 @Beta
33 public class UniqueConstraintException extends DataValidationFailedException implements YangNetconfErrorAware {
34     private static final long serialVersionUID = 1L;
35
36     // Note: this cannot be an ImmutableMap because we must support null values
37     @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Best effort on serialization")
38     private final Map<Descendant, @Nullable Object> values;
39
40     // FIXME: 8.0.0: this maps to a list of 'non-unique' YangInstanceIdentifiers, really. we should be getting
41     //               a list of YangErrorInfo containing them -- but what about Serializability then?
42     public UniqueConstraintException(final YangInstanceIdentifier path, final Map<Descendant, @Nullable Object> values,
43             final String message) {
44         super(path, message);
45         this.values = requireNonNull(values);
46     }
47
48     // FIXME: 8.0.0: this should be completely nonnull, there is no point in reporting missing values
49     public final Map<Descendant, @Nullable Object> values() {
50         return Collections.unmodifiableMap(values);
51     }
52
53     @Override
54     public List<YangNetconfError> getNetconfErrors() {
55         return List.of(ImmutableYangNetconfError.builder()
56             .severity(ErrorSeverity.ERROR)
57             .type(ErrorType.APPLICATION)
58             .tag(ErrorTag.OPERATION_FAILED)
59             .appTag("data-not-unique")
60             // FIXME: 8.0.0: and then we need to append YangErrorInfo here
61             .build());
62     }
63 }