Split out restconf-api
[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.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;
23
24 /**
25  * Parser and holder of query parameters from uriInfo for notifications.
26  */
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;
34
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;
41         this.filter = filter;
42         this.leafNodesOnly = leafNodesOnly;
43         this.skipNotificationData = skipNotificationData;
44         this.changedLeafNodesOnly = changedLeafNodesOnly;
45     }
46
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);
57     }
58
59     /**
60      * Get start-time query parameter.
61      *
62      * @return start-time
63      */
64     public @Nullable StartTimeParam startTime() {
65         return startTime;
66     }
67
68     /**
69      * Get stop-time query parameter.
70      *
71      * @return stop-time
72      */
73     public @Nullable StopTimeParam stopTime() {
74         return stopTime;
75     }
76
77     /**
78      * Get filter query parameter.
79      *
80      * @return filter
81      */
82     public @Nullable FilterParam filter() {
83         return filter;
84     }
85
86     /**
87      * Get odl-leaf-nodes-only query parameter.
88      *
89      * @return odl-leaf-nodes-only
90      */
91     public @Nullable LeafNodesOnlyParam leafNodesOnly() {
92         return leafNodesOnly;
93     }
94
95     /**
96      * Get odl-skip-notification-data query parameter.
97      *
98      * @return odl-skip-notification-data
99      */
100     public @Nullable SkipNotificationDataParam skipNotificationData() {
101         return skipNotificationData;
102     }
103
104     /**
105      * Get changed-leaf-nodes-only query parameter.
106      *
107      * @return changed-leaf-nodes-only
108      */
109     public @Nullable ChangedLeafNodesOnlyParam changedLeafNodesOnly() {
110         return changedLeafNodesOnly;
111     }
112
113     @Override
114     public String toString() {
115         final var helper = MoreObjects.toStringHelper(this);
116         if (startTime != null) {
117             helper.add("startTime", startTime.paramValue());
118         }
119         if (stopTime != null) {
120             helper.add("stopTime", stopTime.paramValue());
121         }
122         if (filter != null) {
123             helper.add("filter", filter.paramValue());
124         }
125         if (leafNodesOnly != null) {
126             helper.add("leafNodesOnly", leafNodesOnly.value());
127         }
128         if (skipNotificationData != null) {
129             helper.add("skipNotificationData", skipNotificationData.value());
130         }
131         if (changedLeafNodesOnly != null) {
132             helper.add("changedLeafNodesOnly", changedLeafNodesOnly.value());
133         }
134         return helper.toString();
135     }
136 }