Fix NetconfKeystoreAdapter onDataTreeChanged method
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / sal / NetconfKeystoreAdapter.java
index 6facc7d237001620181ac6cc006748e0b541f84b..b1d707f7081833e16c130052a1b315a7a83e6b9b 100644 (file)
@@ -5,7 +5,6 @@
  * 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.netconf.sal.connect.netconf.sal;
 
 import java.io.ByteArrayInputStream;
@@ -28,12 +27,12 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.Keystore;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017._private.keys.PrivateKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.keystore.entry.KeyCredential;
@@ -57,8 +56,8 @@ public class NetconfKeystoreAdapter implements ClusteredDataTreeChangeListener<K
     public NetconfKeystoreAdapter(final DataBroker dataBroker) {
         this.dataBroker = dataBroker;
 
-        dataBroker.registerDataTreeChangeListener(
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, keystoreIid), this);
+        dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
+            keystoreIid), this);
     }
 
     public Optional<KeyCredential> getKeypairFromId(final String keyId) {
@@ -111,7 +110,7 @@ public class NetconfKeystoreAdapter implements ClusteredDataTreeChangeListener<K
         return keyStore;
     }
 
-    private java.security.PrivateKey getJavaPrivateKey(final String base64PrivateKey)
+    private static java.security.PrivateKey getJavaPrivateKey(final String base64PrivateKey)
             throws GeneralSecurityException {
         final byte[] encodedKey = base64Decode(base64PrivateKey);
         final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encodedKey);
@@ -128,7 +127,7 @@ public class NetconfKeystoreAdapter implements ClusteredDataTreeChangeListener<K
         return key;
     }
 
-    private List<X509Certificate> getCertificateChain(final String[] base64Certificates)
+    private static List<X509Certificate> getCertificateChain(final String[] base64Certificates)
             throws GeneralSecurityException {
         final CertificateFactory factory = CertificateFactory.getInstance("X.509");
         final List<X509Certificate> certificates = new ArrayList<>();
@@ -141,7 +140,7 @@ public class NetconfKeystoreAdapter implements ClusteredDataTreeChangeListener<K
         return certificates;
     }
 
-    private byte[] base64Decode(final String base64) {
+    private static byte[] base64Decode(final String base64) {
         return Base64.getMimeDecoder().decode(base64.getBytes(java.nio.charset.StandardCharsets.US_ASCII));
     }
 
@@ -158,9 +157,8 @@ public class NetconfKeystoreAdapter implements ClusteredDataTreeChangeListener<K
 
                     pairs.clear();
                     if (dataAfter != null) {
-                        dataAfter.getKeyCredential().forEach(pair -> pairs.put(pair.getKey().getKeyId(), pair));
+                        dataAfter.getKeyCredential().forEach(pair -> pairs.put(pair.key().getKeyId(), pair));
                     }
-                    break;
 
                 } else if (changedChild.getDataType().equals(PrivateKey.class)) {
                     onPrivateKeyChanged((DataObjectModification<PrivateKey>)changedChild);