Rename restconf-nb-rfc8040 to restconf-nb
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / NotificationQueryParams.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  * Copyright (c) 2021 PANTHEON.tech, s.r.o.
4  *
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
8  */
9 package org.opendaylight.restconf.nb.rfc8040;
10
11 import static com.google.common.base.Preconditions.checkArgument;
12
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.yangtools.concepts.Immutable;
17
18 /**
19  * Parser and holder of query parameters from uriInfo for notifications.
20  */
21 public final class NotificationQueryParams implements Immutable {
22     private final SkipNotificationDataParam skipNotificationData;
23     private final LeafNodesOnlyParam leafNodesOnly;
24     private final StartTimeParam startTime;
25     private final StopTimeParam stopTime;
26     private final FilterParam filter;
27
28     private NotificationQueryParams(final StartTimeParam startTime, final StopTimeParam stopTime,
29             final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
30             final SkipNotificationDataParam skipNotificationData) {
31         this.startTime = startTime;
32         this.stopTime = stopTime;
33         this.filter = filter;
34         this.leafNodesOnly = leafNodesOnly;
35         this.skipNotificationData = skipNotificationData;
36     }
37
38     public static @NonNull NotificationQueryParams of(final StartTimeParam startTime, final StopTimeParam stopTime,
39             final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
40             final SkipNotificationDataParam skipNotificationData) {
41         checkArgument(stopTime == null || startTime != null,
42             "Stop-time parameter has to be used with start-time parameter.");
43         return new NotificationQueryParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData);
44     }
45
46     /**
47      * Get start-time query parameter.
48      *
49      * @return start-time
50      */
51     public @Nullable StartTimeParam startTime() {
52         return startTime;
53     }
54
55     /**
56      * Get stop-time query parameter.
57      *
58      * @return stop-time
59      */
60     public @Nullable StopTimeParam stopTime() {
61         return stopTime;
62     }
63
64     /**
65      * Get filter query parameter.
66      *
67      * @return filter
68      */
69     public @Nullable FilterParam filter() {
70         return filter;
71     }
72
73     /**
74      * Get odl-leaf-nodes-only query parameter.
75      *
76      * @return odl-leaf-nodes-only
77      */
78     public @Nullable LeafNodesOnlyParam leafNodesOnly() {
79         return leafNodesOnly;
80     }
81
82     /**
83      * Get odl-skip-notification-data query parameter.
84      *
85      * @return odl-skip-notification-data
86      */
87     public @Nullable SkipNotificationDataParam skipNotificationData() {
88         return skipNotificationData;
89     }
90
91     @Override
92     public String toString() {
93         final var helper = MoreObjects.toStringHelper(this);
94         if (startTime != null) {
95             helper.add("startTime", startTime.paramValue());
96         }
97         if (stopTime != null) {
98             helper.add("stopTime", stopTime.paramValue());
99         }
100         if (filter != null) {
101             helper.add("filter", filter.paramValue());
102         }
103         if (leafNodesOnly != null) {
104             helper.add("leafNodesOnly", leafNodesOnly.value());
105         }
106         if (skipNotificationData != null) {
107             helper.add("skipNotificationData", skipNotificationData.value());
108         }
109         return helper.toString();
110     }
111 }