implement dependency checking for security rule's group
[neutron.git] / transcriber / src / main / java / org / opendaylight / neutron / transcriber / NeutronSecurityRuleInterface.java
index a6d16b9589c4f1044bd83a81fd0ee99c22c3c2be..653e76ffeea8db0adeeb86bb5058aa2455a443e2 100644 (file)
@@ -13,6 +13,7 @@ import java.util.List;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.neutron.northbound.api.BadRequestException;
 import org.opendaylight.neutron.spi.INeutronSecurityRuleCRUD;
 import org.opendaylight.neutron.spi.NeutronSecurityRule;
@@ -39,9 +40,12 @@ public final class NeutronSecurityRuleInterface extends
             String> ETHERTYPE_MAP = new ImmutableBiMap.Builder<Class<? extends EthertypeBase>, String>()
                     .put(EthertypeV4.class, "IPv4").put(EthertypeV6.class, "IPv6").build();
 
+    private final NeutronSecurityGroupInterface securityGroupInterface;
+
     @Inject
-    public NeutronSecurityRuleInterface(DataBroker db) {
+    public NeutronSecurityRuleInterface(DataBroker db, NeutronSecurityGroupInterface securityGroupInterface) {
         super(SecurityRuleBuilder.class, db);
+        this.securityGroupInterface = securityGroupInterface;
     }
 
     @Override
@@ -129,4 +133,11 @@ public final class NeutronSecurityRuleInterface extends
         }
         return securityRuleBuilder.build();
     }
+
+    @Override
+    protected boolean areAllDependenciesAvailable(ReadTransaction tx, NeutronSecurityRule securityRule) {
+        return securityGroupInterface.exists(securityRule.getSecurityRuleGroupID(), tx)
+                && ifNonNull(securityRule.getSecurityRemoteGroupID(),
+                    remoteGroupID -> securityGroupInterface.exists(remoteGroupID, tx));
+    }
 }