+ /**
+ * Read specific type of data from data store via transaction and if identifier read data from
+ * streams then put streams from actual schema context to datastore.
+ *
+ * @param identifier identifier of data to read
+ * @param content type of data to read (config, state, all)
+ * @param strategy {@link RestconfStrategy} - object that perform the actual DS operations
+ * @param withDefa value of with-defaults parameter
+ * @param schemaContext schema context
+ * @param uriInfo uri info
+ * @return {@link NormalizedNode}
+ */
+ private NormalizedNode<?, ?> readData(final String identifier, final String content,
+ final YangInstanceIdentifier path, final RestconfStrategy strategy, final String withDefa,
+ final EffectiveModelContext schemaContext, final UriInfo uriInfo) {
+ if (identifier != null && identifier.contains(STREAMS_PATH) && !identifier.contains(STREAM_PATH_PART)) {
+ createAllYangNotificationStreams(strategy, schemaContext, uriInfo);
+ }
+ return ReadDataTransactionUtil.readData(content, path, strategy, withDefa, schemaContext);
+ }
+
+ private void createAllYangNotificationStreams(final RestconfStrategy strategy,
+ final EffectiveModelContext schemaContext, final UriInfo uriInfo) {
+ strategy.prepareReadWriteExecution();
+ final boolean exist = checkExist(schemaContext, strategy);
+
+ for (final NotificationDefinition notificationDefinition : schemaContext.getNotifications()) {
+ final NotificationListenerAdapter notifiStreamXML =
+ CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContext,
+ NotificationOutputType.XML);
+ final NotificationListenerAdapter notifiStreamJSON =
+ CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContext,
+ NotificationOutputType.JSON);
+ writeNotificationStreamToDatastore(schemaContext, uriInfo, strategy, exist, notifiStreamXML);
+ writeNotificationStreamToDatastore(schemaContext, uriInfo, strategy, exist, notifiStreamJSON);
+ }
+ try {
+ strategy.commit().get();
+ } catch (final InterruptedException | ExecutionException e) {
+ throw new RestconfDocumentedException("Problem while putting data to DS.", e);
+ }
+ }
+
+ private void writeNotificationStreamToDatastore(final EffectiveModelContext schemaContext,
+ final UriInfo uriInfo, final RestconfStrategy strategy, final boolean exist,
+ final NotificationListenerAdapter listener) {
+ final URI uri = streamUtils.prepareUriByStreamName(uriInfo, listener.getStreamName());
+ final NormalizedNode<?, ?> mapToStreams =
+ RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring(
+ listener.getSchemaPath().lastNodeIdentifier(), schemaContext.getNotifications(), null,
+ listener.getOutputType(), uri, SubscribeToStreamUtil.getMonitoringModule(schemaContext), exist);
+ writeDataToDS(schemaContext,
+ listener.getSchemaPath().lastNodeIdentifier().getLocalName(), strategy, exist, mapToStreams);
+ }
+
+ private static boolean checkExist(final EffectiveModelContext schemaContext, final RestconfStrategy strategy) {
+ try {
+ return strategy.exists(LogicalDatastoreType.OPERATIONAL,
+ IdentifierCodec.deserialize(Rfc8040.MonitoringModule.PATH_TO_STREAMS, schemaContext)).get();
+ } catch (final InterruptedException | ExecutionException exception) {
+ throw new RestconfDocumentedException("Problem while checking data if exists", exception);
+ }
+ }
+
+ private static void writeDataToDS(final EffectiveModelContext schemaContext, final String name,
+ final RestconfStrategy strategy, final boolean exist,
+ final NormalizedNode<?, ?> mapToStreams) {
+ final String pathId;
+ if (exist) {
+ pathId = Rfc8040.MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + name;
+ } else {
+ pathId = Rfc8040.MonitoringModule.PATH_TO_STREAMS;
+ }
+ strategy.merge(LogicalDatastoreType.OPERATIONAL, IdentifierCodec.deserialize(pathId, schemaContext),
+ mapToStreams);
+ }
+