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

identifier column name contains from 'identifier_' string and name of the enum field

parent 374f6a98
...@@ -501,8 +501,10 @@ public class ColorSchemaReader { ...@@ -501,8 +501,10 @@ public class ColorSchemaReader {
if (nameColumn == null && identifierColumn == null && customIdentifiers.size() == 0 if (nameColumn == null && identifierColumn == null && customIdentifiers.size() == 0
&& elementIdentifierColumn == null) { && elementIdentifierColumn == null) {
throw new InvalidColorSchemaException("One of these columns is obligatory: " + ColorSchemaColumn.NAME.getColumnName() throw new InvalidColorSchemaException(
+ "," + ColorSchemaColumn.IDENTIFIER.getColumnName() + "," + ColorSchemaColumn.ELEMENT_IDENTIFIER.getColumnName()); "One of these columns is obligatory: " + ColorSchemaColumn.NAME.getColumnName()
+ "," + ColorSchemaColumn.IDENTIFIER.getColumnName() + ","
+ ColorSchemaColumn.ELEMENT_IDENTIFIER.getColumnName());
} }
if (valueColumn == null && colorColumn == null) { if (valueColumn == null && colorColumn == null) {
...@@ -680,16 +682,18 @@ public class ColorSchemaReader { ...@@ -680,16 +682,18 @@ public class ColorSchemaReader {
*/ */
public void parseColumns(String[] columns, Map<ColorSchemaColumn, Integer> schemaColumns, public void parseColumns(String[] columns, Map<ColorSchemaColumn, Integer> schemaColumns,
List<Pair<MiriamType, Integer>> customIdentifiers, ColorSchemaType type) throws InvalidColorSchemaException { List<Pair<MiriamType, Integer>> customIdentifiers, ColorSchemaType type) throws InvalidColorSchemaException {
Map<String, MiriamType> acceptableIdentifiers = new HashMap<String, MiriamType>(); Map<String, MiriamType> acceptableIdentifiers = new HashMap<>();
Map<String, MiriamType> deprecatedIdentifiers = new HashMap<>();
for (MiriamType miriamType : MiriamType.values()) { for (MiriamType miriamType : MiriamType.values()) {
acceptableIdentifiers.put(miriamType.getCommonName().toLowerCase(), miriamType); acceptableIdentifiers.put("identifier_" + miriamType.name().toLowerCase(), miriamType);
deprecatedIdentifiers.put(miriamType.getCommonName().toLowerCase(), miriamType);
} }
for (int i = 0; i < columns.length; i++) { for (int i = 0; i < columns.length; i++) {
boolean found = false; boolean found = false;
for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) { for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) {
if ((columns[i].trim().equalsIgnoreCase(schemaColumn.getColumnName()) || if ((columns[i].trim().equalsIgnoreCase(schemaColumn.getColumnName()) ||
columns[i].trim().equalsIgnoreCase(schemaColumn.getDepractedColumnName())) columns[i].trim().equalsIgnoreCase(schemaColumn.getDepractedColumnName()))
&& schemaColumn.getTypes().contains(type)) { && schemaColumn.getTypes().contains(type)) {
schemaColumns.put(schemaColumn, i); schemaColumns.put(schemaColumn, i);
found = true; found = true;
...@@ -698,6 +702,8 @@ public class ColorSchemaReader { ...@@ -698,6 +702,8 @@ public class ColorSchemaReader {
if (!found) { if (!found) {
if (acceptableIdentifiers.keySet().contains(columns[i].toLowerCase())) { if (acceptableIdentifiers.keySet().contains(columns[i].toLowerCase())) {
customIdentifiers.add(new Pair<>(acceptableIdentifiers.get(columns[i].toLowerCase()), i)); customIdentifiers.add(new Pair<>(acceptableIdentifiers.get(columns[i].toLowerCase()), i));
} else if (deprecatedIdentifiers.keySet().contains(columns[i].toLowerCase())) {
customIdentifiers.add(new Pair<>(deprecatedIdentifiers.get(columns[i].toLowerCase()), i));
} else { } else {
String columnNames = ""; String columnNames = "";
for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) { for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) {
......
...@@ -412,6 +412,25 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { ...@@ -412,6 +412,25 @@ 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");
for (ColorSchema colorSchema : schemas) {
for (MiriamData md : colorSchema.getMiriamData()) {
assertNotNull(md.getResource());
assertFalse(md.getResource().isEmpty());
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test @Test
public void testSchemasWithEmptyNameAndId() throws Exception { public void testSchemasWithEmptyNameAndId() throws Exception {
try { try {
......
name identifier_Entrez identifier_Chebi identifier_go value
120892 1
CHEBI:26523 1
GO:0036489 1
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