Source:
public void populateDatastreamDestination(Datastream datastream, List<Datastream> datastreams) { Validate.notNull(datastreams, "Datastream should not be null"); HashMap<DatastreamSource, Datastream> sourceStreamMapping = new HashMap<>(); datastreams.stream().filter(d -> d.hasDestination() && d.getDestination().hasConnectionString() && !d.getDestination().getConnectionString().isEmpty()).forEach(d -> sourceStreamMapping.put(d.getSource(), d)); LOG.debug("Datastream Source -> Datastream mapping before populating new datastream destinations", sourceStreamMapping); if (datastream.hasDestination() && datastream.getDestination().hasConnectionString() && !datastream.getDestination().getConnectionString().isEmpty()) { return; } boolean topicReuse = _reuseExistingTopic; if (datastream.hasMetadata()) { topicReuse = Boolean.parseBoolean(datastream.getMetadata() .getOrDefault(DatastreamMetadataConstants.REUSE_EXISTING_DESTINATION_KEY, String.valueOf(_reuseExistingTopic))); } Datastream existingStream = sourceStreamMapping.getOrDefault(datastream.getSource(), null); if (topicReuse && existingStream != null && existingStream.getConnectorName().equals(datastream.getConnectorName())) { populateDatastreamDestinationFromExistingDatastream(datastream, existingStream); } else { populateNewDestination(datastream); LOG.info(String.format( "Datastream %s has an unique source or topicReuse (%s) is set to true, Creating a new topic %s", datastream.getName(), topicReuse, datastream.getDestination())); sourceStreamMapping.put(datastream.getSource(), datastream); } LOG.debug("Datastream Source -> Destination mapping after the populating new datastream destinations", sourceStreamMapping); }

Target:
public void populateDatastreamDestination(Datastream datastream, List<Datastream> datastreams) { Validate.notNull(datastream, "Datastream should not be null"); Validate.notNull(datastreams, "Datastreams should not be null"); if (datastream.hasDestination() && datastream.getDestination().hasConnectionString() && !datastream.getDestination().getConnectionString().isEmpty()) { return; } HashMap<DatastreamSource, Datastream> sourceStreamMapping = new HashMap<>(); datastreams.stream().filter(d -> d.hasDestination() && d.getDestination().hasConnectionString() && !d.getDestination().getConnectionString().isEmpty()).forEach(d -> sourceStreamMapping.put(d.getSource(), d)); LOG.debug("Datastream Source -> Datastream mapping before populating new datastream destinations", sourceStreamMapping); boolean topicReuse = _reuseExistingTopic; if (datastream.hasMetadata()) { topicReuse = Boolean.parseBoolean(datastream.getMetadata() .getOrDefault(DatastreamMetadataConstants.REUSE_EXISTING_DESTINATION_KEY, String.valueOf(_reuseExistingTopic))); } Datastream existingStream = sourceStreamMapping.getOrDefault(datastream.getSource(), null); if (topicReuse && existingStream != null && existingStream.getConnectorName().equals(datastream.getConnectorName())) { LOG.info(String.format("Datastream: %s has same source as existing datastream: %s, Setting the destination %s", datastream.getName(), existingStream.getName(), existingStream.getDestination())); populateDatastreamDestinationFromExistingDatastream(datastream, existingStream); } else { populateNewDestination(datastream); LOG.info( String.format("Datastream %s has an unique source or topicReuse (%s) is set to true, Creating a new topic %s", datastream.getName(), topicReuse, datastream.getDestination())); sourceStreamMapping.put(datastream.getSource(), datastream); } LOG.debug("Datastream Source -> Destination mapping after the populating new datastream destinations", sourceStreamMapping); }