Fix the maven build problem caused by incorrect protobuf model #2

Change-Id: I8a1260d486c99569386ff27fbeac48dfc222fb4b
diff --git a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/LinkProtoTranslator.java b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/LinkProtoTranslator.java
index a43e995..fd139da 100644
--- a/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/LinkProtoTranslator.java
+++ b/incubator/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/LinkProtoTranslator.java
@@ -25,6 +25,7 @@
 import org.onosproject.net.SparseAnnotations;
 import org.onosproject.net.provider.ProviderId;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -33,10 +34,10 @@
 public final class LinkProtoTranslator {
 
     /**
-     * Translates gRPC LinkCore message to {@link org.onosproject.net.Link}.
+     * Translates gRPC LinkCore message to {@link Link}.
      *
      * @param link gRPC message
-     * @return {@link org.onosproject.net.Link} null if link is a default instance
+     * @return {@link Link} null if link is a default instance
      */
     public static Link translate(LinkProtoOuterClass.LinkProto link) {
         if (link.equals(LinkProtoOuterClass.LinkProto.getDefaultInstance())) {
@@ -60,9 +61,9 @@
     }
 
     /**
-     * Translates {@link org.onosproject.net.Link} to gRPC LinkCore message.
+     * Translates {@link Link} to gRPC LinkCore message.
      *
-     * @param link {@link org.onosproject.net.Link}
+     * @param link {@link Link}
      * @return gRPC LinkCore message
      */
     public static LinkProtoOuterClass.LinkProto translate(Link link) {
@@ -80,6 +81,7 @@
     }
 
     // may be this can be moved to Annotation itself or AnnotationsUtils
+
     /**
      * Converts Map of Strings to {@link SparseAnnotations}.
      *
@@ -98,8 +100,26 @@
         return builder.build();
     }
 
+    /**
+     * Converts Annotations to Map of Strings.
+     *
+     * @param annotations {@link Annotations}
+     * @return Map of annotation key and values
+     */
+    public static Map<String, String> asMap(Annotations annotations) {
+        if (annotations instanceof DefaultAnnotations) {
+            return ((DefaultAnnotations) annotations).asMap();
+        }
+        Map<String, String> map = new HashMap<>();
+        annotations.keys()
+                .forEach(k -> map.put(k, annotations.value(k)));
+
+        return map;
+    }
+
     // Utility class not intended for instantiation.
-    private LinkProtoTranslator() {}
+    private LinkProtoTranslator() {
+    }
 
 }
 
diff --git a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/DeviceProviderServiceClientProxy.java b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/DeviceProviderServiceClientProxy.java
index d11a834..5438c67 100644
--- a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/DeviceProviderServiceClientProxy.java
+++ b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/DeviceProviderServiceClientProxy.java
@@ -17,7 +17,6 @@
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static java.util.stream.Collectors.toList;
-import static org.onosproject.incubator.protobuf.models.ProtobufUtils.translate;
 import static org.onosproject.net.DeviceId.deviceId;
 
 import java.util.Collection;
@@ -33,7 +32,6 @@
 import org.onosproject.grpc.net.device.DeviceService.TriggerProbe;
 import org.onosproject.grpc.net.device.models.PortDescriptionProtoOuterClass.PortDescriptionProto;
 import org.onosproject.grpc.net.device.models.PortStatisticsProtoOuterClass.PortStatisticsProto;
-import org.onosproject.incubator.protobuf.models.ProtobufUtils;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.MastershipRole;
 import org.onosproject.net.device.DeviceDescription;
@@ -42,6 +40,10 @@
 import org.onosproject.net.device.PortDescription;
 import org.onosproject.net.device.PortStatistics;
 import org.onosproject.net.provider.AbstractProviderService;
+import org.onosproject.incubator.protobuf.models.net.device.DeviceProtoTranslator;
+import org.onosproject.incubator.protobuf.models.net.device.PortProtoTranslator;
+import org.onosproject.incubator.protobuf.models.net.MastershipRoleProtoTranslator;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -93,7 +95,7 @@
         DeviceProviderServiceMsg.Builder builder = DeviceProviderServiceMsg.newBuilder();
         builder.setDeviceConnected(builder.getDeviceConnectedBuilder()
                                       .setDeviceId(deviceId.toString())
-                                      .setDeviceDescription(translate(deviceDescription))
+                                      .setDeviceDescription(DeviceProtoTranslator.translate(deviceDescription))
                                       .build());
 
         devProvService.onNext(builder.build());
@@ -119,7 +121,7 @@
         DeviceProviderServiceMsg.Builder builder = DeviceProviderServiceMsg.newBuilder();
         List<PortDescriptionProto> portDescs =
                 portDescriptions.stream()
-                    .map(ProtobufUtils::translate)
+                    .map(PortProtoTranslator::translate)
                     .collect(toList());
 
         builder.setUpdatePorts(builder.getUpdatePortsBuilder()
@@ -143,7 +145,7 @@
         DeviceProviderServiceMsg.Builder builder = DeviceProviderServiceMsg.newBuilder();
         builder.setPortStatusChanged(builder.getPortStatusChangedBuilder()
                                       .setDeviceId(deviceId.toString())
-                                      .setPortDescription(translate(portDescription))
+                                      .setPortDescription(PortProtoTranslator.translate(portDescription))
                                       .build());
 
         devProvService.onNext(builder.build());
@@ -157,8 +159,8 @@
         DeviceProviderServiceMsg.Builder builder = DeviceProviderServiceMsg.newBuilder();
         builder.setReceivedRoleReply(builder.getReceivedRoleReplyBuilder()
                                       .setDeviceId(deviceId.toString())
-                                      .setRequested(translate(requested))
-                                      .setResponse(translate(response))
+                                      .setRequested(MastershipRoleProtoTranslator.translate(requested))
+                                      .setResponse(MastershipRoleProtoTranslator.translate(response))
                                       .build());
 
         devProvService.onNext(builder.build());
@@ -172,7 +174,7 @@
         DeviceProviderServiceMsg.Builder builder = DeviceProviderServiceMsg.newBuilder();
         List<PortStatisticsProto> portStats =
                 portStatistics.stream()
-                    .map(ProtobufUtils::translate)
+                    .map(PortProtoTranslator::translate)
                     .collect(toList());
         builder.setUpdatePortStatistics(builder.getUpdatePortStatisticsBuilder()
                                       .setDeviceId(deviceId.toString())
@@ -271,7 +273,7 @@
             case ROLE_CHANGED:
                 RoleChanged roleChanged = msg.getRoleChanged();
                 provider.roleChanged(deviceId(roleChanged.getDeviceId()),
-                                     translate(roleChanged.getNewRole()));
+                        (MastershipRole) MastershipRoleProtoTranslator.translate(roleChanged.getNewRole()).get());
                 break;
             case IS_REACHABLE_REQUEST:
                 IsReachableRequest isReachableRequest = msg.getIsReachableRequest();
diff --git a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcRemoteServiceServer.java b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcRemoteServiceServer.java
index 270fed2..e7ca04b 100644
--- a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcRemoteServiceServer.java
+++ b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcRemoteServiceServer.java
@@ -18,7 +18,9 @@
 import static com.google.common.base.Preconditions.checkNotNull;
 import static java.util.concurrent.Executors.newScheduledThreadPool;
 import static java.util.stream.Collectors.toList;
-import static org.onosproject.incubator.protobuf.models.ProtobufUtils.translate;
+import org.onosproject.incubator.protobuf.models.net.device.DeviceProtoTranslator;
+import org.onosproject.incubator.protobuf.models.net.device.PortProtoTranslator;
+import org.onosproject.incubator.protobuf.models.net.MastershipRoleProtoTranslator;
 import static org.onosproject.net.DeviceId.deviceId;
 
 import java.io.IOException;
@@ -50,7 +52,6 @@
 import org.onosproject.grpc.net.device.DeviceService.RegisterProvider;
 import org.onosproject.grpc.net.device.DeviceService.UpdatePortStatistics;
 import org.onosproject.grpc.net.device.DeviceService.UpdatePorts;
-import org.onosproject.incubator.protobuf.models.ProtobufUtils;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.MastershipRole;
 import org.onosproject.net.PortNumber;
@@ -272,7 +273,7 @@
             case DEVICE_CONNECTED:
                 DeviceConnected deviceConnected = msg.getDeviceConnected();
                 deviceProviderService.deviceConnected(deviceId(deviceConnected.getDeviceId()),
-                                                      translate(deviceConnected.getDeviceDescription()));
+                        DeviceProtoTranslator.translate(deviceConnected.getDeviceDescription()));
                 break;
             case DEVICE_DISCONNECTED:
                 DeviceDisconnected deviceDisconnected = msg.getDeviceDisconnected();
@@ -283,26 +284,26 @@
                 deviceProviderService.updatePorts(deviceId(updatePorts.getDeviceId()),
                                                   updatePorts.getPortDescriptionsList()
                                                       .stream()
-                                                          .map(ProtobufUtils::translate)
+                                                          .map(PortProtoTranslator::translate)
                                                           .collect(toList()));
                 break;
             case PORT_STATUS_CHANGED:
                 PortStatusChanged portStatusChanged = msg.getPortStatusChanged();
                 deviceProviderService.portStatusChanged(deviceId(portStatusChanged.getDeviceId()),
-                                                        translate(portStatusChanged.getPortDescription()));
+                        PortProtoTranslator.translate(portStatusChanged.getPortDescription()));
                 break;
             case RECEIVED_ROLE_REPLY:
                 ReceivedRoleReply receivedRoleReply = msg.getReceivedRoleReply();
                 deviceProviderService.receivedRoleReply(deviceId(receivedRoleReply.getDeviceId()),
-                                                        translate(receivedRoleReply.getRequested()),
-                                                        translate(receivedRoleReply.getResponse()));
+                        (MastershipRole) MastershipRoleProtoTranslator.translate(receivedRoleReply.getRequested()).get(),
+                        (MastershipRole) MastershipRoleProtoTranslator.translate(receivedRoleReply.getResponse()).get());
                 break;
             case UPDATE_PORT_STATISTICS:
                 UpdatePortStatistics updatePortStatistics = msg.getUpdatePortStatistics();
                 deviceProviderService.updatePortStatistics(deviceId(updatePortStatistics.getDeviceId()),
                                                            updatePortStatistics.getPortStatisticsList()
                                                              .stream()
-                                                                .map(ProtobufUtils::translate)
+                                                                .map(PortProtoTranslator::translate)
                                                                 .collect(toList()));
                 break;
 
@@ -429,7 +430,7 @@
             DeviceProviderMsg.Builder msgBuilder = DeviceProviderMsg.newBuilder();
             msgBuilder.setRoleChanged(msgBuilder.getRoleChangedBuilder()
                                           .setDeviceId(deviceId.toString())
-                                          .setNewRole(translate(newRole))
+                                          .setNewRole(MastershipRoleProtoTranslator.translate(newRole))
                                           .build());
             toDeviceProvider.onNext(msgBuilder.build());
         }
diff --git a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceClientProxy.java b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceClientProxy.java
index e59fa7b..d80fb8d 100644
--- a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceClientProxy.java
+++ b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceClientProxy.java
@@ -40,7 +40,7 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
-import static org.onosproject.incubator.protobuf.models.ProtobufUtils.asMap;
+import static org.onosproject.incubator.protobuf.models.net.LinkProtoTranslator.asMap;
 
 /**
  * Proxy object to handle LinkProviderService calls.
diff --git a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceServerProxy.java b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceServerProxy.java
index 15b2e1b..55c93fb 100644
--- a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceServerProxy.java
+++ b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/LinkProviderServiceServerProxy.java
@@ -29,7 +29,7 @@
 import org.onosproject.grpc.net.link.models.LinkEnumsProto.LinkTypeProto;
 import org.onosproject.grpc.net.models.ConnectPointProtoOuterClass.ConnectPointProto;
 import org.onosproject.grpc.net.models.ConnectPointProtoOuterClass.ConnectPointProto.ElementIdCase;
-import org.onosproject.incubator.protobuf.models.ProtobufUtils;
+import org.onosproject.incubator.protobuf.models.net.LinkProtoTranslator;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link.Type;
@@ -191,7 +191,7 @@
         ConnectPoint src = translate(linkDescription.getSrc());
         ConnectPoint dst = translate(linkDescription.getDst());
         Type type = translate(linkDescription.getType());
-        SparseAnnotations annotations = ProtobufUtils.asAnnotations(linkDescription.getAnnotations());
+        SparseAnnotations annotations = LinkProtoTranslator.asAnnotations(linkDescription.getAnnotations());
         return new DefaultLinkDescription(src, dst, type, annotations);
     }