Commit 0ce36e62 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

sometimes there was an error when looking for deprecated columns

parent 05f881c2
......@@ -820,13 +820,28 @@ public class ColorSchemaReader {
}
String[] columns = line.split("\t");
if (columns.length > 1) {
ColorSchemaType type = overlay.getColorSchemaType();
if (type == null) {
Map<String, String> params = TextFileUtils
.getHeaderParametersFromFile(new ByteArrayInputStream(overlay.getInputData().getFileContent()));
String typeString = params.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE);
if (typeString != null) {
type = ColorSchemaType.valueOf(typeString);
} else {
logger.warn("Undefined color schema type for overlay: " + overlay.getId());
type = ColorSchemaType.GENERIC;
}
}
Map<ColorSchemaColumn, Integer> schemaColumns = new HashMap<>();
parseColumns(columns, schemaColumns, ColorSchemaType.GENERIC);
parseColumns(columns, schemaColumns, type);
for (ColorSchemaColumn column : schemaColumns.keySet()) {
try {
Field f = ColorSchemaColumn.class.getField(column.name());
if (column.getDepractedColumnName() != null || f.isAnnotationPresent(Deprecated.class)) {
if (f.isAnnotationPresent(Deprecated.class)) {
result.add(column);
} else if (column.getDepractedColumnName() != null
&& column.getDepractedColumnName().equalsIgnoreCase(columns[schemaColumns.get(column)])) {
result.add(column);
}
} catch (NoSuchFieldException | SecurityException e) {
......
......@@ -15,12 +15,14 @@ import org.junit.*;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.commands.ColorModelCommand;
import lcsb.mapviewer.common.TextFileUtils;
import lcsb.mapviewer.converter.zip.ZipEntryFileFactory;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.layout.*;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.services.ServiceTestFunctions;
import lcsb.mapviewer.services.utils.data.ColorSchemaColumn;
public class ColorSchemaReaderTest extends ServiceTestFunctions {
Logger logger = LogManager.getLogger(ColorSchemaReaderTest.class);
......@@ -334,4 +336,35 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
overlay.setInputData(file);
assertEquals(0, reader.getDeprecatedColumns(overlay).size());
}
@Test
public void testGetDeprecatedColumnsForValidGeneticColumns() throws Exception {
Layout overlay = new Layout();
overlay.setColorSchemaType(ColorSchemaType.GENETIC_VARIANT);
UploadedFileEntry file = new UploadedFileEntry();
file.setFileContent((ColorSchemaColumn.POSITION.name() + "\tgene_name\n").getBytes("UTF-8"));
overlay.setInputData(file);
assertEquals(0, reader.getDeprecatedColumns(overlay).size());
}
@Test
public void testGetDeprecatedColumnsForDeprecatedGeneticColumns() throws Exception {
Layout overlay = new Layout();
overlay.setColorSchemaType(ColorSchemaType.GENETIC_VARIANT);
UploadedFileEntry file = new UploadedFileEntry();
file.setFileContent((ColorSchemaColumn.POSITION.name() + "\tname\n").getBytes("UTF-8"));
overlay.setInputData(file);
assertEquals(1, reader.getDeprecatedColumns(overlay).size());
}
@Test
public void testGetDeprecatedColumnsForOverlayWithHeader() throws Exception {
Layout overlay = new Layout();
UploadedFileEntry file = new UploadedFileEntry();
String content = "#" + ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE + "=" + ColorSchemaType.GENERIC + "\n" +
ColorSchemaColumn.VALUE.name() + "\tname\n";
file.setFileContent((content).getBytes("UTF-8"));
overlay.setInputData(file);
assertEquals(0, reader.getDeprecatedColumns(overlay).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