[cleaning] avoid NPE

This commit is contained in:
Claudio Atzori 2022-12-10 11:41:38 +01:00
parent 8b44afe5e5
commit c18b8048c3
1 changed files with 24 additions and 3 deletions

View File

@ -151,11 +151,32 @@ public class CleanCfHbSparkJob {
private static <T extends Result> FlatMapFunction<T, IdCfHbMapping> flattenCfHbFn() { private static <T extends Result> FlatMapFunction<T, IdCfHbMapping> flattenCfHbFn() {
return r -> Stream return r -> Stream
.concat( .concat(
r.getCollectedfrom().stream().map(KeyValue::getKey), Optional
.ofNullable(r.getCollectedfrom())
.map(cf -> cf.stream().map(KeyValue::getKey))
.orElse(Stream.empty()),
Stream Stream
.concat( .concat(
r.getInstance().stream().map(Instance::getHostedby).map(KeyValue::getKey), Optional
r.getInstance().stream().map(Instance::getCollectedfrom).map(KeyValue::getKey))) .ofNullable(r.getInstance())
.map(
instances -> instances
.stream()
.map(i -> Optional.ofNullable(i.getHostedby()).map(KeyValue::getKey).orElse("")))
.orElse(Stream.empty())
.filter(StringUtils::isNotBlank),
Optional
.ofNullable(r.getInstance())
.map(
instances -> instances
.stream()
.map(
i -> Optional
.ofNullable(i.getCollectedfrom())
.map(KeyValue::getKey)
.orElse("")))
.orElse(Stream.empty())
.filter(StringUtils::isNotBlank)))
.distinct() .distinct()
.filter(StringUtils::isNotBlank) .filter(StringUtils::isNotBlank)
.map(cfHb -> asIdCfHbMapping(r.getId(), cfHb)) .map(cfHb -> asIdCfHbMapping(r.getId(), cfHb))