Simplify builder 09/104309/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Feb 2023 13:59:07 +0000 (14:59 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Feb 2023 14:27:33 +0000 (15:27 +0100)
We do not need the intermediate products, we can just pass them to a
fluent builder.

Change-Id: Id384d2fd54a454b89de7b43b12b23f1f135a767f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
apps/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java

index 22d664d130d6a4141375bfed12d0e431a69b1bc7..3da56e0d5b45469536fa7fb535e69594367893fb 100644 (file)
@@ -37,10 +37,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.Transport;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.SshBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParamsBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
@@ -196,14 +194,14 @@ final class CallhomeStatusReporter implements DataTreeChangeListener<Node>, Stat
         } catch (IOException e) {
             LOG.warn("Unable to encode public key to ssh format.", e);
         }
-        final SshClientParams sshParams = new SshClientParamsBuilder().setHostKey(sshEncodedKey).build();
-        final Transport transport = new SshBuilder().setSshClientParams(sshParams).build();
         return new DeviceBuilder()
-                .setUniqueId(id)
-                .withKey(new DeviceKey(id))
-                .setTransport(transport)
-                .addAugmentation(new Device1Builder().setDeviceStatus(status).build())
-                .build();
+            .setUniqueId(id)
+            .withKey(new DeviceKey(id))
+            .setTransport(new SshBuilder()
+                .setSshClientParams(new SshClientParamsBuilder().setHostKey(sshEncodedKey).build())
+                .build())
+            .addAugmentation(new Device1Builder().setDeviceStatus(status).build())
+            .build();
     }
 
     private Device readAndGetDevice(final NodeId nodeId) {
@@ -304,8 +302,8 @@ final class CallhomeStatusReporter implements DataTreeChangeListener<Node>, Stat
 
         for (final Device device : getDevicesAsList()) {
             final String keyString;
-            if (device.getTransport() instanceof Ssh) {
-                keyString = ((Ssh) device.getTransport()).getSshClientParams().getHostKey();
+            if (device.getTransport() instanceof Ssh ssh) {
+                keyString = ssh.getSshClientParams().getHostKey();
             } else {
                 keyString = device.getSshHostKey();
             }