Refactor NBINotifications and serviceHandlerImpl
[transportpce.git] / nbinotifications / src / main / java / org / opendaylight / transportpce / nbinotifications / serialization / NotificationAlarmServiceDeserializer.java
index 4612d84bc6faa698f717fbb34c1b9e6df232f316..c08dbfb2fa9ceda56cd4a45569f65738437271a1 100644 (file)
@@ -11,17 +11,17 @@ import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import org.apache.kafka.common.serialization.Deserializer;
 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.get.notifications.alarm.service.output.NotificationAlarmService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.get.notifications.alarm.service.output.NotificationAlarmServiceBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.get.notifications.alarm.service.output.NotificationsAlarmService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.get.notifications.alarm.service.output.NotificationsAlarmServiceBuilder;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class NotificationAlarmServiceDeserializer implements Deserializer<NotificationAlarmService> {
+public class NotificationAlarmServiceDeserializer implements Deserializer<NotificationsAlarmService> {
     private static final Logger LOG = LoggerFactory.getLogger(NotificationAlarmServiceDeserializer.class);
-    private JsonStringConverter<org.opendaylight.yang.gen.v1
-        .nbi.notifications.rev210628.NotificationAlarmService> converter;
+    private JsonStringConverter<NotificationAlarmService> converter;
 
     @SuppressWarnings("unchecked")
     @Override
@@ -29,37 +29,33 @@ public class NotificationAlarmServiceDeserializer implements Deserializer<Notifi
         LOG.info("Deserializer configuration {}", configs);
         if (configs.containsKey(ConfigConstants.CONVERTER)
                 && configs.get(ConfigConstants.CONVERTER) instanceof JsonStringConverter<?>) {
-            converter = (JsonStringConverter<org.opendaylight.yang.gen.v1
-                    .nbi.notifications.rev210628.NotificationAlarmService>) configs
-                    .get(ConfigConstants.CONVERTER);
+            converter = (JsonStringConverter<NotificationAlarmService>) configs.get(ConfigConstants.CONVERTER);
         }
     }
 
     @Override
-    public NotificationAlarmService deserialize(String topic, byte[] data) {
+    public NotificationsAlarmService deserialize(String topic, byte[] data) {
         if (converter == null) {
             throw new IllegalArgumentException(
                     "Converter should be configured through configure method of deserializer");
         }
         String value = new String(data, StandardCharsets.UTF_8);
         // The message published is
-        // org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.NotificationService
+        // org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService
         // we have to map it to
         // org.opendaylight.yang.gen
-        // .v1.nbi.notifications.rev201130.get.notifications.service.output.NotificationService
-        org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationAlarmService mappedString = converter
-                .createDataObjectFromJsonString(YangInstanceIdentifier.of(
-                        org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationAlarmService.QNAME),
-                        value,
-                        JSONCodecFactorySupplier.RFC7951);
-        if (mappedString != null) {
-            LOG.info("Reading event {}", mappedString);
-            return new NotificationAlarmServiceBuilder().setConnectionType(mappedString.getConnectionType())
-                    .setMessage(mappedString.getMessage())
-                    .setOperationalState(mappedString.getOperationalState())
-                    .setServiceName(mappedString.getServiceName())
-                    .build();
+        // .v1.nbi.notifications.rev210813.get.notifications.service.output.NotificationsAlarmService
+        NotificationAlarmService mappedString = converter.createDataObjectFromJsonString(
+                YangInstanceIdentifier.of(NotificationAlarmService.QNAME), value, JSONCodecFactorySupplier.RFC7951);
+        if (mappedString == null) {
+            return null;
         }
-        return null;
+        LOG.info("Reading event {}", mappedString);
+        return new NotificationsAlarmServiceBuilder()
+                .setConnectionType(mappedString.getConnectionType())
+                .setMessage(mappedString.getMessage())
+                .setOperationalState(mappedString.getOperationalState())
+                .setServiceName(mappedString.getServiceName())
+                .build();
     }
 }