Commit 2f55dc97 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '785-entrez' into 'devel_12.2.x'

Resolve "annotating protein created model that cannot be exported properly"

See merge request minerva/core!729
parents 118e0068 5be880e4
Pipeline #9647 passed with stage
in 10 minutes and 5 seconds
......@@ -10,6 +10,8 @@ minerva (12.2.2) stable; urgency=medium
* Bug fix: removing project without full control in the system (but with
enough privileges to remove project) caused "Not enough privileges" error
(#778)
* Bug fix: export of custom properties (like synonyms) are properly encoded
in CellDesigner xml (#785)
minerva (12.2.1) stable; urgency=medium
* Bug fix: export of reaction colorsi in SBML is properly encoded (COPASI can
......
package lcsb.mapviewer.annotation.services.annotators;
import java.io.IOException;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.Collections;
......@@ -9,15 +8,11 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.SourceNotAvailable;
......@@ -300,7 +295,7 @@ public class EntrezAnnotator extends ElementAnnotator implements IExternalServic
Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equals("Gene-ref_syn_E")) {
synonyms.add(node.getTextContent());
synonyms.add(StringEscapeUtils.unescapeHtml4(node.getTextContent()));
}
}
}
......
......@@ -343,6 +343,23 @@ public class EntrezAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testAnnotateElementWithEncodedSynonyms() throws Exception {
try {
Species proteinAlias = new GenericProtein("id");
proteinAlias.addMiriamData(new MiriamData(MiriamType.ENTREZ, "834106"));
entrezAnnotator.annotateElement(proteinAlias);
for (String synonym : proteinAlias.getSynonyms()) {
assertFalse("Invalid character found in synonym: " + synonym, synonym.contains("&"));
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testParseEntrezResponse() throws Exception {
WebPageDownloader downloader = entrezAnnotator.getWebPageDownloader();
......
......@@ -160,8 +160,9 @@ public class RestAnnotationParser extends XmlParser {
return "";
}
} else if (value instanceof String) {
if (!((String) value).trim().isEmpty() || forceFullInfo) {
return type.getCommonName() + ": " + value + "\n";
String string =(String) value;
if (!(string.trim().isEmpty()) || forceFullInfo) {
return type.getCommonName() + ": " + super.escapeXml(string) + "\n";
} else {
return "";
}
......@@ -178,7 +179,7 @@ public class RestAnnotationParser extends XmlParser {
if (object instanceof MiriamData) {
result += ((MiriamData) object).getResource();
} else {
result += object;
result += super.escapeXml(object.toString());
}
}
......
......@@ -54,6 +54,8 @@ import lcsb.mapviewer.model.map.species.Species;
public class CellDesignerXmlParserTest extends CellDesignerTestFunctions {
Logger logger = Logger.getLogger(CellDesignerXmlParserTest.class);
ModelComparator modelComparator = new ModelComparator();
@Before
public void setUp() throws Exception {
}
......@@ -422,8 +424,6 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions {
InputStream is = new ByteArrayInputStream(xmlString.getBytes());
Model model2 = parser.createModel(new ConverterParams().inputStream(is).sizeAutoAdjust(false));
ModelComparator modelComparator = new ModelComparator();
assertEquals(0, modelComparator.compare(model, model2));
} catch (Exception e) {
......@@ -1012,6 +1012,34 @@ public class CellDesignerXmlParserTest extends CellDesignerTestFunctions {
}
}
@Test
public void testSpeciesWithSpecialSynonym() throws Exception {
try {
Model model = new ModelFullIndexed(null);
model.setIdModel("as");
model.setWidth(10);
model.setHeight(10);
Species protein = new GenericProtein("id1");
protein.setWidth(10);
protein.setHeight(10);
protein.setName("ROS");
protein.addSynonym("&");
model.addElement(protein);
CellDesignerXmlParser parser = new CellDesignerXmlParser();
String xmlString = parser.toXml(model);
InputStream is = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
Model model2 = parser.createModel(new ConverterParams().inputStream(is));
assertEquals(0, modelComparator.compare(model, model2));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testReactionCoordsEqual() throws Exception {
try {
......
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