Commit 99862451 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '822-color-parser-issue' into 'devel_13.1.x'

Resolve "MINERVANET - Error Report 72"

See merge request !798
parents 7aaace49 a43d12fa
minerva (12.3.1~beta.1) unstable; urgency=low
* Bug fix: invalid color in data overlay provides proper feedback to the user
(#822)
* Bug fix: tair locus identifiers were used improperly - instead of id the
name was used
* Bug fix: plugin tab header wasn't properly resized after adding plugins
......
......@@ -47,6 +47,10 @@ public class ColorParser {
* @return {@link Color} obtained from input text
*/
public Color parse(String string) {
if (string==null || string.isEmpty()) {
throw new InvalidArgumentException(
"Invalid color value: " + string + ". Correct format: #xxxxxx (where x is a hex value)");
}
if (string.charAt(0) != '#') {
string = "#" + string;
}
......
......@@ -64,6 +64,18 @@ public class ColorParserTest {
}
}
@Test(expected=InvalidArgumentException.class)
public void testParseNull() throws Exception {
ColorParser parser = new ColorParser();
parser.parse(null);
}
@Test(expected=InvalidArgumentException.class)
public void testParseEmpty() throws Exception {
ColorParser parser = new ColorParser();
parser.parse("");
}
@Test
public void testSetColorToHtmlString() throws Exception {
try {
......
......@@ -229,7 +229,11 @@ public class ColorSchemaReader {
}
}
if (colorColumn != null) {
schema.setColor(colorParser.parse(values[colorColumn]));
try {
schema.setColor(colorParser.parse(values[colorColumn]));
} catch (InvalidArgumentException e) {
throw new InvalidColorSchemaException(errorPrefix + e.getMessage(), e);
}
}
if (identifierColumn != null && !values[identifierColumn].equals("")) {
processGeneralIdentifier(values[identifierColumn], schema, errorPrefix);
......@@ -535,7 +539,11 @@ public class ColorSchemaReader {
schema.setValue(parseValueColumn(values[valueColumn], errorPrefix));
}
if (colorColumn != null && !values[colorColumn].isEmpty()) {
schema.setColor(colorParser.parse(values[colorColumn]));
try {
schema.setColor(colorParser.parse(values[colorColumn]));
} catch (InvalidArgumentException e) {
throw new InvalidColorSchemaException(errorPrefix + e.getMessage(), e);
}
}
if (schema.getValue() != null && schema.getColor() != null) {
throw new InvalidColorSchemaException(errorPrefix + "Either color or value can be defined but found both");
......
......@@ -378,6 +378,23 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
}
}
@Test
public void testColoringWithEmptyColor() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
String input = "name\tcolor\ns1\tx";
reader.readColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), params);
fail("Exception expected");
} catch (InvalidColorSchemaException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testColoringWithInvalidValueAndColor2() throws Exception {
try {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment