56bad1b86d4a6b39007bd27f55df993eeb586d12
[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 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;
22
23 /**
24  * Parser and holder of query parameters from uriInfo for notifications.
25  */
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;
34
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;
41         this.filter = filter;
42         this.leafNodesOnly = leafNodesOnly;
43         this.skipNotificationData = skipNotificationData;
44         this.changedLeafNodesOnly = changedLeafNodesOnly;
45         this.childNodesOnly = childNodesOnly;
46     }
47
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");
55         }
56         if (changedLeafNodesOnly != null) {
57             if (leafNodesOnly != null) {
58                 throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
59                     + LeafNodesOnlyParam.uriName + " parameter");
60             }
61             if (childNodesOnly != null) {
62                 throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
63                     + ChildNodesOnlyParam.uriName + " parameter");
64             }
65         }
66         return new NotificationQueryParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
67             changedLeafNodesOnly, childNodesOnly);
68     }
69
70     /**
71      * Get start-time query parameter.
72      *
73      * @return start-time
74      */
75     public @Nullable StartTimeParam startTime() {
76         return startTime;
77     }
78
79     /**
80      * Get stop-time query parameter.
81      *
82      * @return stop-time
83      */
84     public @Nullable StopTimeParam stopTime() {
85         return stopTime;
86     }
87
88     /**
89      * Get filter query parameter.
90      *
91      * @return filter
92      */
93     public @Nullable FilterParam filter() {
94         return filter;
95     }
96
97     /**
98      * Get odl-leaf-nodes-only query parameter.
99      *
100      * @return odl-leaf-nodes-only
101      */
102     public @Nullable LeafNodesOnlyParam leafNodesOnly() {
103         return leafNodesOnly;
104     }
105
106     /**
107      * Get odl-skip-notification-data query parameter.
108      *
109      * @return odl-skip-notification-data
110      */
111     public @Nullable SkipNotificationDataParam skipNotificationData() {
112         return skipNotificationData;
113     }
114
115     /**
116      * Get changed-leaf-nodes-only query parameter.
117      *
118      * @return changed-leaf-nodes-only
119      */
120     public @Nullable ChangedLeafNodesOnlyParam changedLeafNodesOnly() {
121         return changedLeafNodesOnly;
122     }
123
124     /**
125      * Get odl-child-nodes-only query parameter.
126      *
127      * @return odl-child-nodes-only
128      */
129     public @Nullable ChildNodesOnlyParam childNodesOnly() {
130         return childNodesOnly;
131     }
132
133     @Override
134     public String toString() {
135         final var helper = MoreObjects.toStringHelper(this);
136         if (startTime != null) {
137             helper.add("startTime", startTime.paramValue());
138         }
139         if (stopTime != null) {
140             helper.add("stopTime", stopTime.paramValue());
141         }
142         if (filter != null) {
143             helper.add("filter", filter.paramValue());
144         }
145         if (leafNodesOnly != null) {
146             helper.add("leafNodesOnly", leafNodesOnly.value());
147         }
148         if (skipNotificationData != null) {
149             helper.add("skipNotificationData", skipNotificationData.value());
150         }
151         if (changedLeafNodesOnly != null) {
152             helper.add("changedLeafNodesOnly", changedLeafNodesOnly.value());
153         }
154         if (childNodesOnly != null) {
155             helper.add("childNodesOnly", childNodesOnly.value());
156         }
157         return helper.toString();
158     }
159 }