Skip to content
Snippets Groups Projects
Commit d0b91be8 authored by kaloyane's avatar kaloyane
Browse files

[LMS-2531] 1) revert previous changes.

2) Imports should treat Gene SYMBOLS as a whitespace-separated list of values (not a single code)

SVN: 22972
parent 2eefa025
No related branches found
No related tags found
No related merge requests found
......@@ -109,7 +109,7 @@ public class QiagenScreeningLibraryColumnExtractor extends AbstractColumnExtract
public String getGeneSymbol(String[] row)
{
return getCodeValue(row, GENE_SYMBOL);
return getValue(row, GENE_SYMBOL);
}
public String getGeneDescription(String[] row)
......
......@@ -193,44 +193,36 @@ class LibraryRegistrationTask implements IASyncAction
return;
}
String normalizedValue = normalizeGeneValue(newGeneProp.getValue());
String mergedGeneType = mergeGeneTypes(existingGene, normalizedValue);
newGeneProp.setValue(mergedGeneType);
String mergedGeneSymbols = mergeGeneSymbols(existingGene, newGeneProp.getValue());
newGeneProp.setValue(mergedGeneSymbols);
}
private String mergeGeneTypes(String existingType, String newType)
private String mergeGeneSymbols(String existingSymbols, String newSymbolString)
{
if (StringUtils.isBlank(newType) || newType.equals(existingType))
if (StringUtils.isBlank(newSymbolString) || newSymbolString.equals(existingSymbols))
{
return existingType;
return existingSymbols;
}
boolean ignoreNewType =
existingType.startsWith(newType + DELIM) || existingType.endsWith(DELIM + newType)
|| (existingType.indexOf(DELIM + newType + DELIM) > 0);
if (ignoreNewType)
String[] newSymbols = newSymbolString.split("\\s+");
StringBuilder result = new StringBuilder(existingSymbols);
for (String newSymbol : newSymbols)
{
return existingType;
} else
{
return existingType + DELIM + newType;
}
}
if (StringUtils.isBlank(newSymbol))
{
continue;
}
boolean alreadyExisting =
existingSymbols.startsWith(newSymbol + DELIM) || existingSymbols.endsWith(DELIM + newSymbol)
|| (existingSymbols.indexOf(DELIM + newSymbol + DELIM) > 0);
/**
* Remove leading and trailing underscores.
*/
private String normalizeGeneValue(String value)
{
final String UNDERSCORE = "_";
if (value.startsWith(UNDERSCORE) || value.endsWith(UNDERSCORE))
{
String normalized = value.replaceAll("_*$", "");
normalized = normalized.replaceAll("^_*", "");
return normalized;
if (false == alreadyExisting)
{
result.append(DELIM);
result.append(newSymbol);
}
}
return value;
return result.toString();
}
public boolean doAction(Writer messageWriter)
......
......@@ -89,15 +89,15 @@ public class LibraryRegistrationTaskTest extends AssertJUnit
{
NewMaterial g1 = createNewGene("G1", "AB");
NewMaterial g2 = createNewGene("G2", "AB");
NewMaterial g3 = createNewGene("G3", "AB");
NewMaterial g4 = createNewGene("G4", "AB");
NewMaterial g5 = createNewGene("G5", "AB");
NewMaterial g3 = createNewGene("G3", "BC AB");
NewMaterial g4 = createNewGene("G4", "AB AB");
NewMaterial g5 = createNewGene("G5", "AB DDD");
final List<NewMaterial> newGenes = Arrays.asList(g1, g2, g3, g4, g5);
final List<Material> existingGenes =
Arrays.asList(createExistingGene("G1", "ABC A"), createExistingGene("G2", "AB"),
createExistingGene("G3", "AB BC"), createExistingGene("G4", "XY AB"),
createExistingGene("G5", "XY AB YZ"));
createExistingGene("G5", "XY AB YZ DDD"));
final RecordingMatcher<List<NewMaterialsWithTypes>> materialsWithTypesMatcher =
new RecordingMatcher<List<NewMaterialsWithTypes>>();
......@@ -130,7 +130,7 @@ public class LibraryRegistrationTaskTest extends AssertJUnit
assertEquals("AB", extractGeneSymbol(g2));
assertEquals("AB BC", extractGeneSymbol(g3));
assertEquals("XY AB", extractGeneSymbol(g4));
assertEquals("XY AB YZ", extractGeneSymbol(g5));
assertEquals("XY AB YZ DDD", extractGeneSymbol(g5));
List<NewMaterialsWithTypes> materialsWithTypes =
LibraryRegistrationTask.createMaterialsWithTypes(
......@@ -147,54 +147,6 @@ public class LibraryRegistrationTaskTest extends AssertJUnit
}
}
@Test
public void testUpdateWithUnderscores()
{
NewMaterial g1 = createNewGene("G1", "_AB_");
NewMaterial g2 = createNewGene("G2", "_AB_");
NewMaterial g3 = createNewGene("G3", "_AB_");
NewMaterial g4 = createNewGene("G4", "_AB_");
NewMaterial g5 = createNewGene("G5", "_AB_");
final List<NewMaterial> newGenes = Arrays.asList(g1, g2, g3, g4, g5);
final List<Material> existingGenes =
Arrays.asList(createExistingGene("G1", "ABC A"), createExistingGene("G2", "AB"),
createExistingGene("G3", "AB BC"), createExistingGene("G4", "XY AB"),
createExistingGene("G5", "XY AB YZ"));
final RecordingMatcher<List<NewMaterialsWithTypes>> materialsWithTypesMatcher =
new RecordingMatcher<List<NewMaterialsWithTypes>>();
task =
new LibraryRegistrationTask(SESSION_TOKEN, newGenes, null, null, commonServer,
genericServer, daoFactory);
context.checking(new Expectations()
{
{
one(daoFactory).getEntityTypeDAO(EntityKind.MATERIAL);
will(returnValue(entityTypeDAO));
one(entityTypeDAO).tryToFindEntityTypeByCode(
ScreeningConstants.GENE_PLUGIN_TYPE_CODE);
will(returnValue(new MaterialTypePE()));
one(commonServer).listMaterials(with(SESSION_TOKEN),
with(any(ListMaterialCriteria.class)), with(true));
will(returnValue(existingGenes));
one(genericServer).registerOrUpdateMaterials(with(SESSION_TOKEN),
with(materialsWithTypesMatcher));
}
});
task.doAction(new StringWriter());
assertEquals("ABC A AB", extractGeneSymbol(g1));
assertEquals("AB", extractGeneSymbol(g2));
assertEquals("AB BC", extractGeneSymbol(g3));
assertEquals("XY AB", extractGeneSymbol(g4));
assertEquals("XY AB YZ", extractGeneSymbol(g5));
}
private NewMaterial createNewGene(String code, String geneSymbol)
{
IEntityProperty geneSymbolProperty = createGeneSymbolProperty(geneSymbol);
......
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