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.FilterParam;
16 import org.opendaylight.restconf.api.query.LeafNodesOnlyParam;
17 import org.opendaylight.restconf.api.query.SkipNotificationDataParam;
18 import org.opendaylight.restconf.api.query.StartTimeParam;
19 import org.opendaylight.restconf.api.query.StopTimeParam;
20 import org.opendaylight.yangtools.concepts.Immutable;
23 * Parser and holder of query parameters from uriInfo for notifications.
25 public final class NotificationQueryParams implements Immutable {
26 private final SkipNotificationDataParam skipNotificationData;
27 private final LeafNodesOnlyParam leafNodesOnly;
28 private final StartTimeParam startTime;
29 private final StopTimeParam stopTime;
30 private final FilterParam filter;
31 private final ChangedLeafNodesOnlyParam changedLeafNodesOnly;
33 private NotificationQueryParams(final StartTimeParam startTime, final StopTimeParam stopTime,
34 final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
35 final SkipNotificationDataParam skipNotificationData,
36 final ChangedLeafNodesOnlyParam changedLeafNodesOnly) {
37 this.startTime = startTime;
38 this.stopTime = stopTime;
40 this.leafNodesOnly = leafNodesOnly;
41 this.skipNotificationData = skipNotificationData;
42 this.changedLeafNodesOnly = changedLeafNodesOnly;
45 public static @NonNull NotificationQueryParams of(final StartTimeParam startTime, final StopTimeParam stopTime,
46 final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
47 final SkipNotificationDataParam skipNotificationData,
48 final ChangedLeafNodesOnlyParam changedLeafNodesOnly) {
49 if (stopTime != null && startTime == null) {
50 throw new IllegalArgumentException(StopTimeParam.uriName + " parameter has to be used with "
51 + StartTimeParam.uriName + " parameter");
53 if (changedLeafNodesOnly != null && leafNodesOnly != null) {
54 throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
55 + LeafNodesOnlyParam.uriName + " parameter");
57 return new NotificationQueryParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
58 changedLeafNodesOnly);
62 * Get start-time query parameter.
66 public @Nullable StartTimeParam startTime() {
71 * Get stop-time query parameter.
75 public @Nullable StopTimeParam stopTime() {
80 * Get filter query parameter.
84 public @Nullable FilterParam filter() {
89 * Get odl-leaf-nodes-only query parameter.
91 * @return odl-leaf-nodes-only
93 public @Nullable LeafNodesOnlyParam leafNodesOnly() {
98 * Get odl-skip-notification-data query parameter.
100 * @return odl-skip-notification-data
102 public @Nullable SkipNotificationDataParam skipNotificationData() {
103 return skipNotificationData;
107 * Get changed-leaf-nodes-only query parameter.
109 * @return changed-leaf-nodes-only
111 public @Nullable ChangedLeafNodesOnlyParam changedLeafNodesOnly() {
112 return changedLeafNodesOnly;
116 public String toString() {
117 final var helper = MoreObjects.toStringHelper(this);
118 if (startTime != null) {
119 helper.add("startTime", startTime.paramValue());
121 if (stopTime != null) {
122 helper.add("stopTime", stopTime.paramValue());
124 if (filter != null) {
125 helper.add("filter", filter.paramValue());
127 if (leafNodesOnly != null) {
128 helper.add("leafNodesOnly", leafNodesOnly.value());
130 if (skipNotificationData != null) {
131 helper.add("skipNotificationData", skipNotificationData.value());
133 if (changedLeafNodesOnly != null) {
134 helper.add("changedLeafNodesOnly", changedLeafNodesOnly.value());
136 return helper.toString();