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 static com.google.common.base.Preconditions.checkArgument;
13 import com.google.common.base.MoreObjects;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.restconf.api.query.ChangedLeafNodesOnlyParam;
17 import org.opendaylight.restconf.api.query.FilterParam;
18 import org.opendaylight.restconf.api.query.LeafNodesOnlyParam;
19 import org.opendaylight.restconf.api.query.SkipNotificationDataParam;
20 import org.opendaylight.restconf.api.query.StartTimeParam;
21 import org.opendaylight.restconf.api.query.StopTimeParam;
22 import org.opendaylight.yangtools.concepts.Immutable;
25 * Parser and holder of query parameters from uriInfo for notifications.
27 public final class NotificationQueryParams implements Immutable {
28 private final SkipNotificationDataParam skipNotificationData;
29 private final LeafNodesOnlyParam leafNodesOnly;
30 private final StartTimeParam startTime;
31 private final StopTimeParam stopTime;
32 private final FilterParam filter;
33 private final ChangedLeafNodesOnlyParam changedLeafNodesOnly;
35 private NotificationQueryParams(final StartTimeParam startTime, final StopTimeParam stopTime,
36 final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
37 final SkipNotificationDataParam skipNotificationData,
38 final ChangedLeafNodesOnlyParam changedLeafNodesOnly) {
39 this.startTime = startTime;
40 this.stopTime = stopTime;
42 this.leafNodesOnly = leafNodesOnly;
43 this.skipNotificationData = skipNotificationData;
44 this.changedLeafNodesOnly = changedLeafNodesOnly;
47 public static @NonNull NotificationQueryParams of(final StartTimeParam startTime, final StopTimeParam stopTime,
48 final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
49 final SkipNotificationDataParam skipNotificationData,
50 final ChangedLeafNodesOnlyParam changedLeafNodesOnly) {
51 checkArgument(stopTime == null || startTime != null,
52 "Stop-time parameter has to be used with start-time parameter.");
53 checkArgument(changedLeafNodesOnly == null || leafNodesOnly == null,
54 "ChangedLeafNodesOnly parameter cannot be used with leafNodesOnlyParameter.");
55 return new NotificationQueryParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
56 changedLeafNodesOnly);
60 * Get start-time query parameter.
64 public @Nullable StartTimeParam startTime() {
69 * Get stop-time query parameter.
73 public @Nullable StopTimeParam stopTime() {
78 * Get filter query parameter.
82 public @Nullable FilterParam filter() {
87 * Get odl-leaf-nodes-only query parameter.
89 * @return odl-leaf-nodes-only
91 public @Nullable LeafNodesOnlyParam leafNodesOnly() {
96 * Get odl-skip-notification-data query parameter.
98 * @return odl-skip-notification-data
100 public @Nullable SkipNotificationDataParam skipNotificationData() {
101 return skipNotificationData;
105 * Get changed-leaf-nodes-only query parameter.
107 * @return changed-leaf-nodes-only
109 public @Nullable ChangedLeafNodesOnlyParam changedLeafNodesOnly() {
110 return changedLeafNodesOnly;
114 public String toString() {
115 final var helper = MoreObjects.toStringHelper(this);
116 if (startTime != null) {
117 helper.add("startTime", startTime.paramValue());
119 if (stopTime != null) {
120 helper.add("stopTime", stopTime.paramValue());
122 if (filter != null) {
123 helper.add("filter", filter.paramValue());
125 if (leafNodesOnly != null) {
126 helper.add("leafNodesOnly", leafNodesOnly.value());
128 if (skipNotificationData != null) {
129 helper.add("skipNotificationData", skipNotificationData.value());
131 if (changedLeafNodesOnly != null) {
132 helper.add("changedLeafNodesOnly", changedLeafNodesOnly.value());
134 return helper.toString();