Fix checkstyle
[netvirt.git] / vpnmanager / api / src / main / java / org / opendaylight / netvirt / vpnmanager / api / VpnExtraRouteHelper.java
index 110f5eddfa70ce4b881e34f6614c48035870b1e7..1533aa581813bb0414365c562ad30d5fe7307053 100644 (file)
@@ -5,18 +5,17 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netvirt.vpnmanager.api;
 
 import static java.util.stream.Collectors.toList;
 
 import com.google.common.base.Optional;
-
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
-
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.infra.Datastore.Configuration;
@@ -49,12 +48,8 @@ import org.slf4j.LoggerFactory;
 public final class VpnExtraRouteHelper {
     private static final Logger LOG = LoggerFactory.getLogger(VpnExtraRouteHelper.class);
 
-    private VpnExtraRouteHelper() { }
+    private VpnExtraRouteHelper() {
 
-    public static  List<Routes> getVpnExtraroutes(DataBroker broker, String vpnName, String vpnRd) {
-        InstanceIdentifier<ExtraRoutes> vpnExtraRoutesId = getVpnToExtrarouteIdentifier(vpnName, vpnRd);
-        Optional<ExtraRoutes> vpnOpc = MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, vpnExtraRoutesId);
-        return vpnOpc.isPresent() ? vpnOpc.get().getRoutes() : new ArrayList<>();
     }
 
     public static Optional<Routes> getVpnExtraroutes(DataBroker broker, String vpnName,
@@ -75,12 +70,6 @@ public final class VpnExtraRouteHelper {
                         new ExtraRoutesKey(vrfId)).child(Routes.class, new RoutesKey(ipPrefix)).build();
     }
 
-    public static  InstanceIdentifier<ExtraRoutes> getVpnToExtrarouteIdentifier(String vpnName, String vrfId) {
-        return InstanceIdentifier.builder(VpnToExtraroutes.class)
-                .child(Vpn.class, new VpnKey(vpnName)).child(ExtraRoutes.class,
-                        new ExtraRoutesKey(vrfId)).build();
-    }
-
     public static  InstanceIdentifier<Vpn> getVpnToExtrarouteVpnIdentifier(String vpnName) {
         return InstanceIdentifier.builder(VpnToExtraroutes.class)
                 .child(Vpn.class, new VpnKey(vpnName)).build();
@@ -103,14 +92,14 @@ public final class VpnExtraRouteHelper {
     public static  List<String> getUsedRds(DataBroker broker, long vpnId, String destPrefix) {
         InstanceIdentifier<DestPrefixes> usedRdsId = getUsedRdsIdentifier(vpnId, destPrefix);
         Optional<DestPrefixes> usedRds = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, usedRdsId);
-        return usedRds.isPresent() ? usedRds.get().getAllocatedRds().stream()
+        return usedRds.isPresent() && usedRds.get().getAllocatedRds() != null ? usedRds.get().getAllocatedRds().stream()
                 .map(AllocatedRds::getRd).distinct().collect(toList()) : new ArrayList<>();
     }
 
     public static  List<String> getUsedRds(TypedReadTransaction<Configuration> confTx, long vpnId, String destPrefix)
             throws ExecutionException, InterruptedException {
         Optional<DestPrefixes> usedRds = confTx.read(getUsedRdsIdentifier(vpnId, destPrefix)).get();
-        return usedRds.isPresent() ? usedRds.get().getAllocatedRds().stream()
+        return usedRds.isPresent() && usedRds.get().getAllocatedRds() != null ? usedRds.get().getAllocatedRds().stream()
             .map(AllocatedRds::getRd).distinct().collect(toList()) : new ArrayList<>();
     }
 
@@ -132,16 +121,7 @@ public final class VpnExtraRouteHelper {
                 .child(AllocatedRds.class, new AllocatedRdsKey(nh)).build();
     }
 
-    public static List<Routes> getAllExtraRoutes(DataBroker broker, String vpnName, String vrfId) {
-        Optional<ExtraRoutes> extraRoutes = MDSALUtil.read(broker,LogicalDatastoreType.OPERATIONAL,
-                getVpnToExtrarouteIdentifier(vpnName, vrfId));
-        List<Routes> extraRoutesList = new ArrayList<>();
-        if (extraRoutes.isPresent()) {
-            extraRoutesList = extraRoutes.get().getRoutes();
-        }
-        return extraRoutesList;
-    }
-
+    @Nullable
     public static Class<? extends TunnelTypeBase> getTunnelType(ItmRpcService itmRpcService, String ifName) {
         try {
             Future<RpcResult<GetTunnelTypeOutput>> result =
@@ -166,8 +146,10 @@ public final class VpnExtraRouteHelper {
     }
 
     public static List<DestPrefixes> getExtraRouteDestPrefixes(DataBroker broker, Long vpnId) {
-        Optional<ExtrarouteRds> extraRoutes = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION,
+        Optional<ExtrarouteRds> optionalExtraRoutes = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION,
                 getUsedRdsIdentifier(vpnId));
-        return extraRoutes.isPresent() ? extraRoutes.get().getDestPrefixes() : new ArrayList<>();
+        List<DestPrefixes> prefixes =
+            optionalExtraRoutes.isPresent() ? optionalExtraRoutes.get().getDestPrefixes() : null;
+        return prefixes == null ? Collections.emptyList() : prefixes;
     }
 }