From: Robert Varga Date: Tue, 26 Oct 2021 07:53:57 +0000 (+0200) Subject: Update AbstractQueryParams X-Git-Tag: v2.0.6~5 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=05ef2fae0cc97b6f8213f6e1ac94a61263d64493;p=netconf.git Update AbstractQueryParams We now have properly-encapsulated notification query parameters, make sure we use them as a whole rather than breaking them apart in callers. JIRA: NETCONF-773 Change-Id: I53bca1d2404e887de16f4e6c3f827c54db45945d Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java index b95059beb5..2019aff332 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java @@ -130,13 +130,8 @@ abstract class SubscribeToStreamUtil { final EffectiveModelContext schemaContext = handlersHolder.getSchemaHandler().get(); final URI uri = prepareUriByStreamName(uriInfo, streamName); + notificationListenerAdapter.setQueryParams(notificationQueryParams); notificationListenerAdapter.listen(handlersHolder.getNotificationServiceHandler()); - notificationListenerAdapter.setQueryParams( - notificationQueryParams.startTime(), - notificationQueryParams.stopTime(), - notificationQueryParams.filter(), - notificationQueryParams.leafNodesOnly(), - notificationQueryParams.skipNotificationData()); final DOMDataBroker dataBroker = handlersHolder.getDataBroker(); notificationListenerAdapter.setCloseVars(dataBroker, handlersHolder.getSchemaHandler()); final MapEntryNode mapToStreams = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring( @@ -183,13 +178,7 @@ abstract class SubscribeToStreamUtil { final ListenerAdapter listener = ListenersBroker.getInstance().getDataChangeListenerFor(streamName) .orElseThrow(() -> new RestconfDocumentedException("No listener found for stream " + streamName, ErrorType.APPLICATION, ErrorTag.DATA_MISSING)); - - listener.setQueryParams( - notificationQueryParams.startTime(), - notificationQueryParams.stopTime(), - notificationQueryParams.filter(), - notificationQueryParams.leafNodesOnly(), - notificationQueryParams.skipNotificationData()); + listener.setQueryParams(notificationQueryParams); final DOMDataBroker dataBroker = handlersHolder.getDataBroker(); final SchemaContextHandler schemaHandler = handlersHolder.getSchemaHandler(); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractQueryParams.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractQueryParams.java index 25265cf80c..f31a72f376 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractQueryParams.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractQueryParams.java @@ -17,11 +17,7 @@ import javax.xml.xpath.XPathExpressionException; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; -import org.opendaylight.restconf.nb.rfc8040.FilterParam; -import org.opendaylight.restconf.nb.rfc8040.LeafNodesOnlyParam; -import org.opendaylight.restconf.nb.rfc8040.SkipNotificationDataParam; -import org.opendaylight.restconf.nb.rfc8040.StartTimeParam; -import org.opendaylight.restconf.nb.rfc8040.StopTimeParam; +import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; /** @@ -51,20 +47,22 @@ abstract class AbstractQueryParams extends AbstractNotificationsData { /** * Set query parameters for listener. * - * @param startTime Start-time of getting notification. - * @param stopTime Stop-time of getting notification. - * @param filter Indicates which subset of all possible events are of interest. - * @param leafNodesOnly If TRUE, notifications will contain changes of leaf nodes only. + * @param params NotificationQueryParams to use. */ - @SuppressWarnings("checkstyle:hiddenField") - public final void setQueryParams(final StartTimeParam startTime, final StopTimeParam stopTime, - final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly, - final SkipNotificationDataParam skipNotificationData) { + public final void setQueryParams(final NotificationQueryParams params) { + final var startTime = params.startTime(); start = startTime == null ? Instant.now() : parseDateAndTime(startTime.value()); + + final var stopTime = params.stopTime(); stop = stopTime == null ? null : parseDateAndTime(stopTime.value()); - this.leafNodesOnly = leafNodesOnly == null ? false : leafNodesOnly.value(); - this.skipNotificationData = skipNotificationData == null ? false : skipNotificationData.value(); + final var leafNodes = params.leafNodesOnly(); + leafNodesOnly = leafNodes == null ? false : leafNodes.value(); + + final var skipData = params.skipNotificationData(); + skipNotificationData = skipData == null ? false : skipData.value(); + + final var filter = params.filter(); if (filter != null) { try { setFilter(filter.paramValue()); diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java index 7083a1a9a7..b616916c69 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java @@ -35,6 +35,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.nb.rfc8040.LeafNodesOnlyParam; +import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams; import org.opendaylight.restconf.nb.rfc8040.SkipNotificationDataParam; import org.opendaylight.restconf.nb.rfc8040.StartTimeParam; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; @@ -42,7 +43,7 @@ import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.P import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.patch.cont.MyList1; import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.patch.cont.MyList1Builder; import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.patch.cont.MyList1Key; -import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping; +import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; @@ -119,11 +120,11 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { private CountDownLatch notificationLatch = new CountDownLatch(1); ListenerAdapterTester(final YangInstanceIdentifier path, final String streamName, - final NotificationOutputTypeGrouping.NotificationOutputType outputType, + final NotificationOutputType outputType, final boolean leafNodesOnly, final boolean skipNotificationData) { super(path, streamName, outputType); - setQueryParams(StartTimeParam.forUriValue("1970-01-01T00:00:00Z"), null, null, - LeafNodesOnlyParam.of(leafNodesOnly), SkipNotificationDataParam.of(skipNotificationData)); + setQueryParams(NotificationQueryParams.of(StartTimeParam.forUriValue("1970-01-01T00:00:00Z"), null, null, + LeafNodesOnlyParam.of(leafNodesOnly), SkipNotificationDataParam.of(skipNotificationData))); } @Override @@ -201,8 +202,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { @Test public void testJsonNotifsLeaves() throws Exception { - ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", - NotificationOutputTypeGrouping.NotificationOutputType.JSON, true, false); + ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON, + true, false); adapter.setCloseVars(domDataBroker, schemaContextHandler); final DOMDataTreeChangeService changeService = domDataBroker.getExtensions() @@ -233,8 +234,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { @Test public void testJsonNotifs() throws Exception { - ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", - NotificationOutputTypeGrouping.NotificationOutputType.JSON, false, false); + ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON, + false, false); adapter.setCloseVars(domDataBroker, schemaContextHandler); final DOMDataTreeChangeService changeService = domDataBroker.getExtensions() @@ -265,8 +266,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { @Test public void testJsonNotifsWithoutData() throws Exception { - ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", - NotificationOutputTypeGrouping.NotificationOutputType.JSON, false, true); + ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON, + false, true); adapter.setCloseVars(domDataBroker, schemaContextHandler); DOMDataTreeChangeService changeService = domDataBroker.getExtensions() @@ -295,8 +296,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { @Test public void testXmlNotifications() throws Exception { - ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", - NotificationOutputTypeGrouping.NotificationOutputType.XML, false, false); + ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML, + false, false); adapter.setCloseVars(domDataBroker, schemaContextHandler); DOMDataTreeChangeService changeService = domDataBroker.getExtensions() @@ -325,8 +326,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { @Test public void testXmlSkipData() throws Exception { - ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", - NotificationOutputTypeGrouping.NotificationOutputType.XML, false, true); + ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML, + false, true); adapter.setCloseVars(domDataBroker, schemaContextHandler); DOMDataTreeChangeService changeService = domDataBroker.getExtensions() @@ -355,8 +356,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { @Test public void testXmlLeavesOnly() throws Exception { - ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", - NotificationOutputTypeGrouping.NotificationOutputType.XML, true, false); + ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML, + true, false); adapter.setCloseVars(domDataBroker, schemaContextHandler); DOMDataTreeChangeService changeService = domDataBroker.getExtensions()