Bug Fixes for Kafka Application(patchset #2)

1. Coding Errors in both the Converters
2. Pom file needs an import for com.google.protobuf
3. Port Object can be null in DeviceEvent. Added a check in the DeviceEventConverter

Change-Id: I28fe7e388b31bec7971b4ab1f431a3520162b53e
diff --git a/apps/kafka-integration/app/pom.xml b/apps/kafka-integration/app/pom.xml
index 20b9427..1dafb0d 100644
--- a/apps/kafka-integration/app/pom.xml
+++ b/apps/kafka-integration/app/pom.xml
@@ -167,7 +167,8 @@
                         org.onlab.packet.*,
                         org.onosproject.*,
                         org.onlab.util.*,
-                        com.google.common.*
+                        com.google.common.*,
+                        com.google.protobuf.*
                     </Import-Package>
                     <Web-ContextPath>${web.context}</Web-ContextPath>
                 </instructions>
diff --git a/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/converter/DeviceEventConverter.java b/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/converter/DeviceEventConverter.java
index e08d6e1..ac04040 100644
--- a/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/converter/DeviceEventConverter.java
+++ b/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/converter/DeviceEventConverter.java
@@ -40,7 +40,7 @@
 
         DeviceEvent deviceEvent = (DeviceEvent) event;
 
-        if (!deviceEventSubtypeSupported(deviceEvent)) {
+        if (!deviceEventTypeSupported(deviceEvent)) {
             log.error("Unsupported Onos Device Event {}. There is no matching"
                     + "proto Device Event type", deviceEvent.type().toString());
             return null;
@@ -55,7 +55,7 @@
      * @param event ONOS Device event
      * @return true if there is a match and false otherwise
      */
-    private boolean deviceEventSubtypeSupported(DeviceEvent event) {
+    private boolean deviceEventTypeSupported(DeviceEvent event) {
         DeviceEventType[] deviceEvents = DeviceEventType.values();
         for (DeviceEventType deviceEventType : deviceEvents) {
             if (deviceEventType.name().equals(event.type().name())) {
@@ -67,9 +67,11 @@
     }
 
     private DeviceNotification buildDeviceProtoMessage(DeviceEvent deviceEvent) {
-        DeviceNotification notification = DeviceNotification.newBuilder()
-                .setDeviceEventType(getProtoType(deviceEvent))
-                .setDevice(DeviceCore.newBuilder()
+        DeviceNotification.Builder notificationBuilder =
+                DeviceNotification.newBuilder();
+
+        DeviceCore deviceCore =
+                DeviceCore.newBuilder()
                         .setChassisId(deviceEvent.subject().chassisId().id()
                                 .toString())
                         .setDeviceId(deviceEvent.subject().id().toString())
@@ -77,18 +79,29 @@
                         .setManufacturer(deviceEvent.subject().manufacturer())
                         .setSerialNumber(deviceEvent.subject().serialNumber())
                         .setSwVersion(deviceEvent.subject().swVersion())
-                        .setType(DeviceType.valueOf(deviceEvent.type().name()))
-                        .build())
-                .setPort(PortCore.newBuilder()
-                        .setIsEnabled(deviceEvent.port().isEnabled())
-                        .setPortNumber(deviceEvent.port().number().toString())
-                        .setPortSpeed(deviceEvent.port().portSpeed())
-                        .setType(PortType
-                                .valueOf(deviceEvent.port().type().name()))
-                        .build())
-                .build();
+                        .setType(DeviceType
+                                .valueOf(deviceEvent.subject().type().name()))
+                        .build();
 
-        return notification;
+        PortCore portCore = null;
+        if (deviceEvent.port() != null) {
+            portCore =
+                    PortCore.newBuilder()
+                            .setIsEnabled(deviceEvent.port().isEnabled())
+                            .setPortNumber(deviceEvent.port().number()
+                                    .toString())
+                            .setPortSpeed(deviceEvent.port().portSpeed())
+                            .setType(PortType
+                                    .valueOf(deviceEvent.port().type().name()))
+                            .build();
+
+            notificationBuilder.setPort(portCore);
+        }
+
+        notificationBuilder.setDeviceEventType(getProtoType(deviceEvent))
+                .setDevice(deviceCore);
+
+        return notificationBuilder.build();
     }
 
     /**
diff --git a/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/converter/LinkEventConverter.java b/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/converter/LinkEventConverter.java
index 2d65537..a1db209 100644
--- a/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/converter/LinkEventConverter.java
+++ b/apps/kafka-integration/app/src/main/java/org/onosproject/kafkaintegration/converter/LinkEventConverter.java
@@ -40,7 +40,7 @@
 
         LinkEvent linkEvent = (LinkEvent) event;
 
-        if (!linkEventSubtypeSupported(linkEvent)) {
+        if (!linkEventTypeSupported(linkEvent)) {
             log.error("Unsupported Onos Event {}. There is no matching"
                     + "proto Event type", linkEvent.type().toString());
             return null;
@@ -49,9 +49,9 @@
         return buildDeviceProtoMessage(linkEvent);
     }
 
-    private boolean linkEventSubtypeSupported(LinkEvent event) {
-        LinkType[] kafkaLinkEvents = LinkType.values();
-        for (LinkType linkEventType : kafkaLinkEvents) {
+    private boolean linkEventTypeSupported(LinkEvent event) {
+        LinkEventType[] kafkaLinkEvents = LinkEventType.values();
+        for (LinkEventType linkEventType : kafkaLinkEvents) {
             if (linkEventType.name().equals(event.type().name())) {
                 return true;
             }