Fix checkstyle warnings for statistics package
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / compatibility / FlowStatisticsToNotificationTransformer.java
index c3e2a91c828995e311f8c71cf52fc3f4915749b0..bf1d21dbc50f80ab330cb6abb45d4c5fc03578f6 100644 (file)
@@ -11,9 +11,12 @@ package org.opendaylight.openflowplugin.impl.statistics.services.compatibility;
 import com.google.common.base.Preconditions;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.FlowStatsResponseConvertorData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
@@ -24,23 +27,32 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow;
 
 /**
- * pulled out flow stats to notification transformation
+ * Pulled out flow stats to notification transformation.
  */
 public class FlowStatisticsToNotificationTransformer {
 
-    private static FlowStatsResponseConvertor flowStatsConvertor = new FlowStatsResponseConvertor();
+    private FlowStatisticsToNotificationTransformer() {
+        // Hide implicit constructor
+    }
 
     /**
+     * Transform to notification.
+     *
      * @param mpResult      raw multipart response from device
-     * @param deviceInfo   device state
+     * @param deviceInfo    device state
      * @param ofVersion     device version
-     * @param emulatedTxId
+     * @param emulatedTxId  emulated transaction Id
+     * @param convertorExecutor convertor executor
      * @return notification containing flow stats
      */
     public static FlowsStatisticsUpdate transformToNotification(final List<MultipartReply> mpResult,
                                                                 final DeviceInfo deviceInfo,
                                                                 final OpenflowVersion ofVersion,
-                                                                final TransactionId emulatedTxId) {
+                                                                final TransactionId emulatedTxId,
+                                                                final ConvertorExecutor convertorExecutor) {
+        final FlowStatsResponseConvertorData data = new FlowStatsResponseConvertorData(ofVersion.getVersion());
+        data.setDatapathId(deviceInfo.getDatapathId());
+        data.setMatchPath(MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
         final FlowsStatisticsUpdateBuilder notification = new FlowsStatisticsUpdateBuilder();
         final List<FlowAndStatisticsMapList> statsList = new ArrayList<>();
         notification.setId(deviceInfo.getNodeId());
@@ -53,11 +65,13 @@ public class FlowStatisticsToNotificationTransformer {
 
             MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpRawReply.getMultipartReplyBody();
             MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
-            List<FlowAndStatisticsMapList> outStatsItem = flowStatsConvertor.toSALFlowStatsList(
-                    replyBody.getFlowStats(),
-                    deviceInfo.getDatapathId(),
-                    ofVersion);
-            statsList.addAll(outStatsItem);
+            final Optional<List<FlowAndStatisticsMapList>> outStatsItem =
+                    convertorExecutor.convert(replyBody.getFlowStats(), data);
+
+
+            if (outStatsItem.isPresent()) {
+                statsList.addAll(outStatsItem.get());
+            }
         }
 
         return notification.build();