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

allow empty type for data overlay

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