2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3 * Copyright (c) 2021 PANTHEON.tech, s.r.o.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.restconf.nb.rfc8040;
11 import com.google.common.base.MoreObjects;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.restconf.api.query.ChangedLeafNodesOnlyParam;
15 import org.opendaylight.restconf.api.query.ChildNodesOnlyParam;
16 import org.opendaylight.restconf.api.query.FilterParam;
17 import org.opendaylight.restconf.api.query.LeafNodesOnlyParam;
18 import org.opendaylight.restconf.api.query.SkipNotificationDataParam;
19 import org.opendaylight.restconf.api.query.StartTimeParam;
20 import org.opendaylight.restconf.api.query.StopTimeParam;
21 import org.opendaylight.yangtools.concepts.Immutable;
24 * Parser and holder of query parameters from uriInfo for notifications.
26 public final class NotificationQueryParams implements Immutable {
27 private final SkipNotificationDataParam skipNotificationData;
28 private final LeafNodesOnlyParam leafNodesOnly;
29 private final StartTimeParam startTime;
30 private final StopTimeParam stopTime;
31 private final FilterParam filter;
32 private final ChangedLeafNodesOnlyParam changedLeafNodesOnly;
33 private final ChildNodesOnlyParam childNodesOnly;
35 private NotificationQueryParams(final StartTimeParam startTime, final StopTimeParam stopTime,
36 final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
37 final SkipNotificationDataParam skipNotificationData, final ChangedLeafNodesOnlyParam changedLeafNodesOnly,
38 final ChildNodesOnlyParam childNodesOnly) {
39 this.startTime = startTime;
40 this.stopTime = stopTime;
42 this.leafNodesOnly = leafNodesOnly;
43 this.skipNotificationData = skipNotificationData;
44 this.changedLeafNodesOnly = changedLeafNodesOnly;
45 this.childNodesOnly = childNodesOnly;
48 public static @NonNull NotificationQueryParams of(final StartTimeParam startTime, final StopTimeParam stopTime,
49 final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
50 final SkipNotificationDataParam skipNotificationData, final ChangedLeafNodesOnlyParam changedLeafNodesOnly,
51 final ChildNodesOnlyParam childNodesOnly) {
52 if (stopTime != null && startTime == null) {
53 throw new IllegalArgumentException(StopTimeParam.uriName + " parameter has to be used with "
54 + StartTimeParam.uriName + " parameter");
56 if (changedLeafNodesOnly != null) {
57 if (leafNodesOnly != null) {
58 throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
59 + LeafNodesOnlyParam.uriName + " parameter");
61 if (childNodesOnly != null) {
62 throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
63 + ChildNodesOnlyParam.uriName + " parameter");
66 return new NotificationQueryParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
67 changedLeafNodesOnly, childNodesOnly);
71 * Get start-time query parameter.
75 public @Nullable StartTimeParam startTime() {
80 * Get stop-time query parameter.
84 public @Nullable StopTimeParam stopTime() {
89 * Get filter query parameter.
93 public @Nullable FilterParam filter() {
98 * Get odl-leaf-nodes-only query parameter.
100 * @return odl-leaf-nodes-only
102 public @Nullable LeafNodesOnlyParam leafNodesOnly() {
103 return leafNodesOnly;
107 * Get odl-skip-notification-data query parameter.
109 * @return odl-skip-notification-data
111 public @Nullable SkipNotificationDataParam skipNotificationData() {
112 return skipNotificationData;
116 * Get changed-leaf-nodes-only query parameter.
118 * @return changed-leaf-nodes-only
120 public @Nullable ChangedLeafNodesOnlyParam changedLeafNodesOnly() {
121 return changedLeafNodesOnly;
125 * Get odl-child-nodes-only query parameter.
127 * @return odl-child-nodes-only
129 public @Nullable ChildNodesOnlyParam childNodesOnly() {
130 return childNodesOnly;
134 public String toString() {
135 final var helper = MoreObjects.toStringHelper(this);
136 if (startTime != null) {
137 helper.add("startTime", startTime.paramValue());
139 if (stopTime != null) {
140 helper.add("stopTime", stopTime.paramValue());
142 if (filter != null) {
143 helper.add("filter", filter.paramValue());
145 if (leafNodesOnly != null) {
146 helper.add("leafNodesOnly", leafNodesOnly.value());
148 if (skipNotificationData != null) {
149 helper.add("skipNotificationData", skipNotificationData.value());
151 if (changedLeafNodesOnly != null) {
152 helper.add("changedLeafNodesOnly", changedLeafNodesOnly.value());
154 if (childNodesOnly != null) {
155 helper.add("childNodesOnly", childNodesOnly.value());
157 return helper.toString();