Merge "SONAR TD - Remove unused fields, fix naming" into stable/boron
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalTableServiceImpl.java
index 90d5dc62cf24ad8573559705d5f579023a6355b2..ef757c9c4f80bce02bd22f370d24f8e27193fd0d 100644 (file)
@@ -13,18 +13,19 @@ import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.Future;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesReplyConvertor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
@@ -54,13 +55,14 @@ import org.slf4j.Logger;
 public final class SalTableServiceImpl extends AbstractMultipartService<UpdateTableInput> implements SalTableService {
     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalTableServiceImpl.class);
     private final TxFacade txFacade;
-    private final NodeId nodeId;
+    private final ConvertorExecutor convertorExecutor;
+    private final VersionConvertorData data;
 
-    public SalTableServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
-                               final NodeId nodeId) {
+    public SalTableServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor) {
         super(requestContextStack, deviceContext);
         this.txFacade = deviceContext;
-        this.nodeId = nodeId;
+        this.convertorExecutor = convertorExecutor;
+        data = new VersionConvertorData(getVersion());
     }
 
     @Override
@@ -120,7 +122,7 @@ public final class SalTableServiceImpl extends AbstractMultipartService<UpdateTa
         final List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> salTableFeatures = convertToSalTableFeatures(multipartReplies);
 
         final InstanceIdentifier<FlowCapableNode> flowCapableNodeII = InstanceIdentifier.create(Nodes.class)
-                .child(Node.class, new NodeKey(getNodeId())).augmentation(FlowCapableNode.class);
+                .child(Node.class, new NodeKey(getDeviceInfo().getNodeId())).augmentation(FlowCapableNode.class);
         for (final org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures tableFeatureData : salTableFeatures) {
             final Short tableId = tableFeatureData.getTableId();
             final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures, TableFeaturesKey> tableFeaturesII = flowCapableNodeII
@@ -133,7 +135,7 @@ public final class SalTableServiceImpl extends AbstractMultipartService<UpdateTa
         txFacade.submitTransaction();
     }
 
-    protected static List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> convertToSalTableFeatures(
+    protected List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> convertToSalTableFeatures(
             final List<MultipartReply> multipartReplies) {
         final List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> salTableFeaturesAll = new ArrayList<>();
         for (final MultipartReply multipartReply : multipartReplies) {
@@ -143,9 +145,14 @@ public final class SalTableServiceImpl extends AbstractMultipartService<UpdateTa
                     final MultipartReplyTableFeaturesCase tableFeaturesCase = ((MultipartReplyTableFeaturesCase) multipartReplyBody);
                     final MultipartReplyTableFeatures salTableFeatures = tableFeaturesCase
                             .getMultipartReplyTableFeatures();
-                    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> salTableFeaturesPartial = TableFeaturesReplyConvertor
-                            .toTableFeaturesReply(salTableFeatures);
-                    salTableFeaturesAll.addAll(salTableFeaturesPartial);
+
+                    final Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures>> salTableFeaturesPartial =
+                            convertorExecutor.convert(salTableFeatures, data);
+
+                    if (salTableFeaturesPartial.isPresent()) {
+                        salTableFeaturesAll.addAll(salTableFeaturesPartial.get());
+                    }
+
                     LOG.debug("TableFeature {} for xid {}.", salTableFeatures, multipartReply.getXid());
                 }
             }
@@ -163,12 +170,12 @@ public final class SalTableServiceImpl extends AbstractMultipartService<UpdateTa
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final UpdateTableInput input) {
+    protected OfHeader buildRequest(final Xid xid, final UpdateTableInput input) throws ServiceException {
         final MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
         final MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
-        final List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input
-            .getUpdatedTable());
-        requestBuilder.setTableFeatures(ofTableFeatureList);
+
+        final Optional<List<TableFeatures>> ofTableFeatureList = convertorExecutor.convert(input.getUpdatedTable(), data);
+        requestBuilder.setTableFeatures(ofTableFeatureList.orElse(Collections.emptyList()));
         caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());
 
         // Set request body to main multipart request