diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java index 145be78c..4cc325b2 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java @@ -15,6 +15,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -247,14 +248,20 @@ public class POSTMapper { .map(ts -> { try { final String[] split = StringUtils.split(ts, Constants.EMBEDDED_LIST_SEPARATOR); - return new Threshold(Double.parseDouble( - split[0]), - (split.length > 1) ? split[1] : null, - (split.length > 2) ? split[2] : null); + Double val = null; + try { + val = Double.parseDouble(split[0]); + } catch (final Exception e) { + } + return new Threshold( + val, + (split.length > 1) ? Utils.parseColorString(Utils.parseRGB(split[1])) : null, + (split.length > 2 && "null".equals(split[2])) ? split[2] : null); } catch (final Exception e) { return null; } }) + .filter(Objects::nonNull) .collect(Collectors.toList()); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java index 73687a48..2f1bd980 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java @@ -578,6 +578,9 @@ public final class Utils { * @param rgb foreground or text color * @return true of the background color for given foreground color shall be dark or false if it shall be light */ public static boolean darkColorContrast(final RGB rgb) { + if (rgb == null) { + return true; + } return rgb.red + rgb.green + rgb.blue > DARK_COLOR_THRESHOLD; } @@ -592,15 +595,16 @@ public final class Utils { } public static RGB parseRGB(final String colorString) { - if (StringUtils.isBlank(colorString)) { + try { + + final int r = Integer.parseInt(colorString.substring(0, 2), 16); + final int g = Integer.parseInt(colorString.substring(2, 4), 16); + final int b = Integer.parseInt(colorString.substring(4, 6), 16); + + return new RGB(r, g, b); + } catch (final Exception e) { return null; } - - final int r = Integer.parseInt(colorString.substring(0, 2), 16); - final int g = Integer.parseInt(colorString.substring(2, 4), 16); - final int b = Integer.parseInt(colorString.substring(4, 6), 16); - - return new RGB(r, g, b); } public static String toColorFractionString(final int fraction) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/ThresholdList.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/ThresholdList.java index dcdfc08f..14bf03b5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/ThresholdList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/ThresholdList.java @@ -121,11 +121,12 @@ public final class ThresholdList extends Composite { public Collection getThresholds() { removeInvalidListEntries(); - return this.thresholds + final List collect = this.thresholds .stream() .map(entry -> new Threshold(entry.getValue(), entry.getColor(), null /* TODO add icon selection here */)) .collect(Collectors.toList()); + return collect; } private void removeInvalidListEntries() {