From a708652093a1e7e712d3fa81eeafc8774af6b3c5 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Wed, 18 Nov 2020 11:58:00 +0100 Subject: [PATCH] added check for empty(null) values --- .../constraints/LongerThanConstraints.java | 10 +++++++++- .../ShorterThanOrEqualToConstraints.java | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/authorpids/constraints/LongerThanConstraints.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/authorpids/constraints/LongerThanConstraints.java index 7187d099e2..7b432626a1 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/authorpids/constraints/LongerThanConstraints.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/authorpids/constraints/LongerThanConstraints.java @@ -3,6 +3,9 @@ package eu.dnetlib.dhp.oa.graph.clean.authorpids.constraints; import java.io.Serializable; +import org.apache.commons.lang3.StringUtils; + + @ConstraintClass("longer") public class LongerThanConstraints implements Serializable, Selection { @@ -12,7 +15,8 @@ public class LongerThanConstraints implements Serializable, Selection { this.param = param; } - public LongerThanConstraints(){}; + public LongerThanConstraints() { + }; public String getParam() { return param; @@ -24,6 +28,10 @@ public class LongerThanConstraints implements Serializable, Selection { @Override public boolean apply(String value) { + if (StringUtils.isEmpty(value)) { + return false; + } return value.length() > Integer.valueOf(param); + } } diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/authorpids/constraints/ShorterThanOrEqualToConstraints.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/authorpids/constraints/ShorterThanOrEqualToConstraints.java index 5699202ff5..0b0faedbf2 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/authorpids/constraints/ShorterThanOrEqualToConstraints.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/authorpids/constraints/ShorterThanOrEqualToConstraints.java @@ -3,18 +3,21 @@ package eu.dnetlib.dhp.oa.graph.clean.authorpids.constraints; import java.io.Serializable; -@ConstraintClass("shorter") +import org.apache.commons.lang3.StringUtils; + +@ConstraintClass("shorterorequal") public class ShorterThanOrEqualToConstraints implements Serializable, Selection { private String param; - public ShorterThanOrEqualToConstraints(){}; + public ShorterThanOrEqualToConstraints() { + }; - public ShorterThanOrEqualToConstraints(String param) { - this.param = param; - } + public ShorterThanOrEqualToConstraints(String param) { + this.param = param; + } - public String getParam() { + public String getParam() { return param; } @@ -24,6 +27,9 @@ public class ShorterThanOrEqualToConstraints implements Serializable, Selection @Override public boolean apply(String value) { + if (StringUtils.isEmpty(value)) + return true; return value.length() <= Integer.valueOf(param); + } }