Skip to content

Commit

Permalink
Refactor code to improve readability and maintainability
Browse files Browse the repository at this point in the history
This commit was made as a response to bugs reported by sonarcloud.
https://sonarcloud.io/project/issues?resolved=false&sinceLeakPeriod=true&types=BUG&id=PantheonTechnologies_lighty-core&open=AYpqn0fygwnrORD6WXZp

JIRA: LIGHTY-235
Signed-off-by: tobias.pobocik <[email protected]>
  • Loading branch information
Tobianas committed Sep 12, 2023
1 parent 7d44019 commit af2f4a8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ public ResponseEntity getNetconfDevicesIds(Authentication authentication) throws
.get(TIMEOUT, TimeUnit.SECONDS);
}

if (netconfTopoOptional.isPresent()) {
return ResponseEntity.ok(getNetconfDevices(netconfTopoOptional.get()));
}
return ResponseEntity.ok(Collections.emptyList());
return netconfTopoOptional.isPresent() ? ResponseEntity.ok(getNetconfDevices(netconfTopoOptional.get())) :
ResponseEntity.ok(Collections.emptyList());
}

private List<NetconfDeviceResponse> getNetconfDevices(final Topology netconfTopology)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public ResponseEntity getAllTopologyIdsOperational(Authentication authentication
final Optional<NetworkTopology> readData =
tx.read(LogicalDatastoreType.OPERATIONAL, iid).get(TIMEOUT, TimeUnit.SECONDS);

if (readData.isPresent() && readData.get().getTopology() != null) {
final List<String> topology = readData.get().getTopology().values().stream()
return ResponseEntity.ok(
readData.map(NetworkTopology::getTopology)
.map(topologyMap -> topologyMap.values()
.stream()
.map(topology1 -> topology1.getTopologyId().getValue())
.collect(Collectors.toList());
return ResponseEntity.ok(topology);
} else {
return ResponseEntity.ok(Collections.emptyList());
}
.collect(Collectors.toList()))
.orElse(Collections.emptyList())
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,13 @@ public GetResponseToNormalizedNodeCodec(final SchemaContextProvider schemaContex
public Optional<NormalizedNode> apply(Gnmi.GetResponse response, YangInstanceIdentifier identifier)
throws GnmiCodecException {
for (Gnmi.Notification notification : response.getNotificationList()) {
for (Gnmi.Update update : notification.getUpdateList()) {
// Json to NormalizedNode
final NormalizedNode codecResult = updateToNormalizedNode(update, identifier);
/*
If the serialized normalized node is of type AugmentationNode we need to return the child
because the AugmentationNode has no QName so later post processing (for example restconf)
can correctly deal with that.
*/
return Optional.of(codecResult);
}
return Optional.of(updateToNormalizedNode(
notification.getUpdateList().get(0), identifier));
}
return Optional.empty();
}
Expand Down

0 comments on commit af2f4a8

Please sign in to comment.