Skip to content
Snippets Groups Projects
Commit b7067b12 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

allow empty type for data overlay

parent 4682e4b0
No related branches found
No related tags found
2 merge requests!805Merge 13.1.0 beta.1,!801Resolve "Overlay data columns - review"
...@@ -19,6 +19,7 @@ minerva (12.3.1~beta.1) unstable; urgency=low ...@@ -19,6 +19,7 @@ minerva (12.3.1~beta.1) unstable; urgency=low
info/submap panel (#824) info/submap panel (#824)
* Bug fix: when changing data in edit user dialog there was a need to click * Bug fix: when changing data in edit user dialog there was a need to click
close button twice (#818) close button twice (#818)
* Bug fix: empty type for data overlay is allowed (#827)
minerva (13.1.0~beta.0) unstable; urgency=low minerva (13.1.0~beta.0) unstable; urgency=low
* Feature: annotators are more flexible - you can define set of input and * Feature: annotators are more flexible - you can define set of input and
......
...@@ -591,21 +591,23 @@ public class ColorSchemaReader { ...@@ -591,21 +591,23 @@ public class ColorSchemaReader {
return result; return result;
} }
private List<Class<? extends Element>> parseSpeciesTypes(String typesString, String errorPrefix) List<Class<? extends Element>> parseSpeciesTypes(String typesString, String errorPrefix)
throws InvalidColorSchemaException { throws InvalidColorSchemaException {
List<Class<? extends Element>> result = new ArrayList<>(); List<Class<? extends Element>> result = new ArrayList<>();
String[] types = typesString.split(","); String[] types = typesString.split(",");
for (String string : types) { for (String string : types) {
SpeciesMapping mapping = SpeciesMapping.getMappingByString(string); if (!string.isEmpty()) {
if (mapping != null) { SpeciesMapping mapping = SpeciesMapping.getMappingByString(string);
result.add(mapping.getModelClazz()); if (mapping != null) {
} else { result.add(mapping.getModelClazz());
String validStrings = ""; } else {
for (SpeciesMapping speciesMapping : SpeciesMapping.values()) { String validStrings = "";
validStrings += speciesMapping.getCellDesignerString() + ", "; for (SpeciesMapping speciesMapping : SpeciesMapping.values()) {
validStrings += speciesMapping.getCellDesignerString() + ", ";
}
throw new InvalidColorSchemaException(
errorPrefix + "Unknown class type: " + string + ". Valid values are: " + validStrings);
} }
throw new InvalidColorSchemaException(
errorPrefix + "Unknown class type: " + string + ". Valid values are: " + validStrings);
} }
} }
return result; return result;
......
...@@ -17,6 +17,7 @@ import java.io.InputStream; ...@@ -17,6 +17,7 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.commons.io.output.ByteArrayOutputStream;
...@@ -28,19 +29,24 @@ import org.junit.Test; ...@@ -28,19 +29,24 @@ import org.junit.Test;
import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.commands.ColorModelCommand; import lcsb.mapviewer.commands.ColorModelCommand;
import lcsb.mapviewer.common.TextFileUtils; import lcsb.mapviewer.common.TextFileUtils;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.layout.ColorSchema; import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.layout.GeneVariation; import lcsb.mapviewer.model.map.layout.GeneVariation;
import lcsb.mapviewer.model.map.layout.GeneVariationColorSchema; import lcsb.mapviewer.model.map.layout.GeneVariationColorSchema;
import lcsb.mapviewer.model.map.layout.InvalidColorSchemaException; import lcsb.mapviewer.model.map.layout.InvalidColorSchemaException;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.services.ServiceTestFunctions; import lcsb.mapviewer.services.ServiceTestFunctions;
public class ColorSchemaReaderTest extends ServiceTestFunctions { public class ColorSchemaReaderTest extends ServiceTestFunctions {
Logger logger = Logger.getLogger(ColorSchemaReaderTest.class); Logger logger = Logger.getLogger(ColorSchemaReaderTest.class);
ColorSchemaReader reader;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
reader = new ColorSchemaReader();
} }
@After @After
...@@ -50,8 +56,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -50,8 +56,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testReadSchema() throws Exception { public void testReadSchema() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/enricoData/ageing.txt"); Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/enricoData/ageing.txt");
assertNotNull(schemas); assertNotNull(schemas);
...@@ -81,8 +85,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -81,8 +85,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
ByteArrayInputStream bin = new ByteArrayInputStream(data); ByteArrayInputStream bin = new ByteArrayInputStream(data);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema(bin, Collection<ColorSchema> schemas = reader.readColorSchema(bin,
TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data))); TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data)));
assertNotNull(schemas); assertNotNull(schemas);
...@@ -101,8 +103,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -101,8 +103,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
ByteArrayInputStream bin = new ByteArrayInputStream(data); ByteArrayInputStream bin = new ByteArrayInputStream(data);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema(bin, Collection<ColorSchema> schemas = reader.readColorSchema(bin,
TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data))); TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data)));
assertNotNull(schemas); assertNotNull(schemas);
...@@ -140,8 +140,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -140,8 +140,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
ByteArrayInputStream bin = new ByteArrayInputStream(data); ByteArrayInputStream bin = new ByteArrayInputStream(data);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema(bin, Collection<ColorSchema> schemas = reader.readColorSchema(bin,
TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data))); TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data)));
assertNotNull(schemas); assertNotNull(schemas);
...@@ -168,8 +166,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -168,8 +166,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
ByteArrayInputStream bin = new ByteArrayInputStream(data); ByteArrayInputStream bin = new ByteArrayInputStream(data);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema(bin, Collection<ColorSchema> schemas = reader.readColorSchema(bin,
TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data))); TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data)));
assertNotNull(schemas); assertNotNull(schemas);
...@@ -188,8 +184,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -188,8 +184,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
ByteArrayInputStream bin = new ByteArrayInputStream(data); ByteArrayInputStream bin = new ByteArrayInputStream(data);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema(bin, Collection<ColorSchema> schemas = reader.readColorSchema(bin,
TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data))); TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data)));
assertNotNull(schemas); assertNotNull(schemas);
...@@ -203,8 +197,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -203,8 +197,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testReadInvalidGeneVariantsSchema() throws Exception { public void testReadInvalidGeneVariantsSchema() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
reader.readColorSchema("testFiles/coloring/gene_variants_invalid_genome.txt"); reader.readColorSchema("testFiles/coloring/gene_variants_invalid_genome.txt");
fail("Exception expected"); fail("Exception expected");
} catch (InvalidColorSchemaException e) { } catch (InvalidColorSchemaException e) {
...@@ -217,8 +209,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -217,8 +209,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testReadSchema2() throws Exception { public void testReadSchema2() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/goodSchema.txt"); Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/goodSchema.txt");
assertNotNull(schemas); assertNotNull(schemas);
...@@ -234,7 +224,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -234,7 +224,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
public void testReadSchema3() throws Exception { public void testReadSchema3() throws Exception {
try { try {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
reader.readColorSchema("testFiles/coloring/wrongSchema.txt"); reader.readColorSchema("testFiles/coloring/wrongSchema.txt");
fail("Excepion expected"); fail("Excepion expected");
} catch (InvalidColorSchemaException e) { } catch (InvalidColorSchemaException e) {
...@@ -248,7 +237,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -248,7 +237,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testProblematicStephanSchema3() throws Exception { public void testProblematicStephanSchema3() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
reader.readColorSchema("testFiles/coloring/problematicSchema.txt"); reader.readColorSchema("testFiles/coloring/problematicSchema.txt");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -259,7 +247,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -259,7 +247,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testReadReactionSchema() throws Exception { public void testReadReactionSchema() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> collection = reader.readColorSchema("testFiles/coloring/reactionSchema.txt"); Collection<ColorSchema> collection = reader.readColorSchema("testFiles/coloring/reactionSchema.txt");
assertEquals(1, collection.size()); assertEquals(1, collection.size());
ColorSchema schema = collection.iterator().next(); ColorSchema schema = collection.iterator().next();
...@@ -275,8 +262,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -275,8 +262,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test(timeout = 15000) @Test(timeout = 15000)
public void testNextVersionReadSchema() throws Exception { public void testNextVersionReadSchema() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/goodLayout.v=1.0.txt"); Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/goodLayout.v=1.0.txt");
assertNotNull(schemas); assertNotNull(schemas);
...@@ -295,8 +280,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -295,8 +280,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
Model model = getModelForFile("testFiles/coloring/protein_to_color.xml", false); Model model = getModelForFile("testFiles/coloring/protein_to_color.xml", false);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/problematicSchema.txt"); Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/problematicSchema.txt");
ColorModelCommand factory = new ColorModelCommand(model, schemas, colorExtractor); ColorModelCommand factory = new ColorModelCommand(model, schemas, colorExtractor);
factory.execute(); factory.execute();
...@@ -312,7 +295,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -312,7 +295,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testColoringWithValueOrColor() throws Exception { public void testColoringWithValueOrColor() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3"); params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
...@@ -331,7 +313,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -331,7 +313,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testElementsByType() throws Exception { public void testElementsByType() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3"); params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
...@@ -349,7 +330,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -349,7 +330,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testColoringWithInvalidValueAndColor() throws Exception { public void testColoringWithInvalidValueAndColor() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3"); params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
...@@ -366,7 +346,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -366,7 +346,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testColoringWithEmptyColor() throws Exception { public void testColoringWithEmptyColor() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3"); params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
...@@ -383,7 +362,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -383,7 +362,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testColoringWithInvalidValueAndColor2() throws Exception { public void testColoringWithInvalidValueAndColor2() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3"); params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
...@@ -398,8 +376,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -398,8 +376,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testSchemasWithId() throws Exception { public void testSchemasWithId() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schemaWithIdentifiers.txt"); Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schemaWithIdentifiers.txt");
for (ColorSchema colorSchema : schemas) { for (ColorSchema colorSchema : schemas) {
for (MiriamData md : colorSchema.getMiriamData()) { for (MiriamData md : colorSchema.getMiriamData()) {
...@@ -417,9 +393,8 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -417,9 +393,8 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testSchemasWithIdSnakeCase() throws Exception { public void testSchemasWithIdSnakeCase() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader(); Collection<ColorSchema> schemas = reader
.readColorSchema("testFiles/coloring/schema_with_identifiers_in_snake_case.txt");
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schema_with_identifiers_in_snake_case.txt");
for (ColorSchema colorSchema : schemas) { for (ColorSchema colorSchema : schemas) {
for (MiriamData md : colorSchema.getMiriamData()) { for (MiriamData md : colorSchema.getMiriamData()) {
assertNotNull(md.getResource()); assertNotNull(md.getResource());
...@@ -436,8 +411,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -436,8 +411,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testSchemasWithEmptyNameAndId() throws Exception { public void testSchemasWithEmptyNameAndId() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schemaIdWithoutName.txt"); Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schemaIdWithoutName.txt");
for (ColorSchema colorSchema : schemas) { for (ColorSchema colorSchema : schemas) {
for (MiriamData md : colorSchema.getMiriamData()) { for (MiriamData md : colorSchema.getMiriamData()) {
...@@ -455,7 +428,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -455,7 +428,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test @Test
public void testSimpleNameSchemas() throws Exception { public void testSimpleNameSchemas() throws Exception {
try { try {
ColorSchemaReader reader = new ColorSchemaReader();
String input = "#header\ns1\ns2\n"; String input = "#header\ns1\ns2\n";
Collection<ColorSchema> schemas = reader Collection<ColorSchema> schemas = reader
.readSimpleNameColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8))); .readSimpleNameColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)));
...@@ -466,4 +438,10 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -466,4 +438,10 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
} }
} }
@Test
public void testParseSpeciesTypesForEmptyString() throws Exception {
List<Class<? extends Element>> classes = reader.parseSpeciesTypes("", null);
assertEquals(0, classes.size());
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment