package org.opendaylight.restconf.nb.rfc8040.streams;
import java.time.Instant;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.dom.api.DOMEvent;
import org.opendaylight.mdsal.dom.api.DOMNotification;
@SuppressWarnings("checkstyle:IllegalCatch")
public final void onNotification(final DOMNotification notification) {
final var eventInstant = notification instanceof DOMEvent domEvent ? domEvent.getEventInstant() : Instant.now();
- final Optional<String> maybeOutput;
+ final String data;
try {
- maybeOutput = formatter().eventData(effectiveModel(), notification, eventInstant);
+ data = formatter().eventData(effectiveModel(), notification, eventInstant);
} catch (Exception e) {
LOG.error("Failed to process notification {}", notification, e);
return;
}
- maybeOutput.ifPresent(this::post);
+ if (data != null) {
+ post(data);
+ }
}
abstract @NonNull EffectiveModelContext effectiveModel();
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
-import java.util.Optional;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.w3c.dom.Document;
filter = xpath.compile(xpathFilter);
}
- final Optional<String> eventData(final EffectiveModelContext schemaContext, final T input, final Instant now)
+ final @Nullable String eventData(final EffectiveModelContext schemaContext, final T input, final Instant now)
throws Exception {
- if (!filterMatches(schemaContext, input, now)) {
- return Optional.empty();
- }
- return Optional.ofNullable(createText(textParams, schemaContext, input, now));
+ return filterMatches(schemaContext, input, now) ? createText(textParams, schemaContext, input, now) : null;
}
/**
import java.time.Instant;
import java.util.Collection;
import java.util.List;
-import java.util.Optional;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@SuppressWarnings("checkstyle:IllegalCatch")
public void onDataTreeChanged(final List<DataTreeCandidate> dataTreeCandidates) {
final var now = Instant.now();
- final Optional<String> maybeData;
+ final String data;
try {
- maybeData = formatter().eventData(databindProvider.currentContext().modelContext(), dataTreeCandidates,
- now);
+ data = formatter().eventData(databindProvider.currentContext().modelContext(), dataTreeCandidates, now);
} catch (final Exception e) {
LOG.error("Failed to process notification {}",
dataTreeCandidates.stream().map(Object::toString).collect(Collectors.joining(",")), e);
return;
}
-
- maybeData.ifPresent(this::post);
+ if (data != null) {
+ post(data);
+ }
}
/**
*/
package org.opendaylight.restconf.nb.rfc8040.streams;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
private String prepareJson(final DOMNotification notificationData, final QName schemaPathNotifi)
throws Exception {
- final var notifiAdapter = listenersBroker.registerNotificationListener(MODEL_CONTEXT,
- ImmutableSet.of(schemaPathNotifi), NotificationOutputType.JSON);
- return notifiAdapter.formatter().eventData(MODEL_CONTEXT, notificationData, Instant.now()).orElseThrow();
+ final var ret = listenersBroker.registerNotificationListener(MODEL_CONTEXT, ImmutableSet.of(schemaPathNotifi),
+ NotificationOutputType.JSON).formatter().eventData(MODEL_CONTEXT, notificationData, Instant.now());
+ assertNotNull(ret);
+ return ret;
}
}
*/
package org.opendaylight.restconf.nb.rfc8040.streams;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
private String prepareXmlResult(final DOMNotification notificationData, final QName schemaPathNotifi)
throws Exception {
- final var notifiAdapter = listenersBroker.registerNotificationListener(MODEL_CONTEXT,
- ImmutableSet.of(schemaPathNotifi), NotificationOutputType.XML);
- return notifiAdapter.formatter().eventData(MODEL_CONTEXT, notificationData, Instant.now()).orElseThrow();
+ final var ret = listenersBroker.registerNotificationListener(MODEL_CONTEXT, ImmutableSet.of(schemaPathNotifi),
+ NotificationOutputType.XML).formatter().eventData(MODEL_CONTEXT, notificationData, Instant.now());
+ assertNotNull(ret);
+ return ret;
}
}