Add Child Nodes Only query parameter to SSE events
[netconf.git] / protocol / restconf-api / src / main / java / org / opendaylight / restconf / api / query / ChildNodesOnlyParam.java
1 /*
2  * Copyright (c) 2023 Orange 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.restconf.api.query;
9
10 import java.net.URI;
11 import org.eclipse.jdt.annotation.NonNull;
12
13 /**
14  * OpenDaylight extension parameter. When used as {@code odl-child-nodes-only=true}, it will instruct the listener
15  * streams to only emit child nodes.
16  */
17 public final class ChildNodesOnlyParam implements RestconfQueryParam<ChildNodesOnlyParam> {
18     // API consistency: must not be confused with enum constants
19     @SuppressWarnings("checkstyle:ConstantName")
20     public static final String uriName = "odl-child-nodes-only";
21
22     private static final @NonNull URI CAPABILITY =
23         URI.create("urn:opendaylight:params:restconf:capability:child-nodes-only:1.0");
24     private static final @NonNull ChildNodesOnlyParam FALSE = new ChildNodesOnlyParam(false);
25     private static final @NonNull ChildNodesOnlyParam TRUE = new ChildNodesOnlyParam(true);
26
27     private final boolean value;
28
29     private ChildNodesOnlyParam(final boolean value) {
30         this.value = value;
31     }
32
33     public static @NonNull ChildNodesOnlyParam of(final boolean value) {
34         return value ? TRUE : FALSE;
35     }
36
37     public static @NonNull ChildNodesOnlyParam forUriValue(final String uriValue) {
38         return switch (uriValue) {
39             case "false" -> FALSE;
40             case "true" -> TRUE;
41             default -> throw new IllegalArgumentException("Value can be 'false' or 'true', not '" + uriValue + "'");
42         };
43     }
44
45     @Override
46     public Class<ChildNodesOnlyParam> javaClass() {
47         return ChildNodesOnlyParam.class;
48     }
49
50     @Override
51     public String paramName() {
52         return uriName;
53     }
54
55     @Override
56     public String paramValue() {
57         return String.valueOf(value);
58     }
59
60     public boolean value() {
61         return value;
62     }
63
64     public static @NonNull URI capabilityUri() {
65         return CAPABILITY;
66     }
67 }