Commit 26dc4763 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when parsing miriam uri info about bioentity is provided to logger

parent 264c8d02
......@@ -88,7 +88,7 @@ public class CopyPasteAbstractAction {
*/
protected String getCopyString(String annotationString, String notesString) throws InvalidXmlSchemaException {
XmlAnnotationParser xap = new XmlAnnotationParser();
Set<MiriamData> set = xap.parse(annotationString);
Set<MiriamData> set = xap.parse(annotationString, null);
StringBuilder result = new StringBuilder();
for (MiriamData md : set) {
result.append(serialize(md) + "\n");
......
......@@ -395,7 +395,7 @@ public class CellDesignerXmlParser extends Converter {
private void processModelRdfNode(Model model, Node node) throws InvalidXmlSchemaException {
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(
CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
model.addMiriamData(xmlAnnotationParser.parseRdfNode(node));
model.addMiriamData(xmlAnnotationParser.parseRdfNode(node, null));
model.addAuthors(xmlAnnotationParser.getAuthorsFromRdf(node));
model.setCreationDate(xmlAnnotationParser.getCreateDateFromRdf(node));
model.addModificationDates(xmlAnnotationParser.getModificationDatesFromRdf(node));
......
......@@ -885,7 +885,8 @@ public class RestAnnotationParser {
Matcher nodeMatcher = rdfNodePattern.matcher(notes);
if (nodeMatcher.find()) {
String rdfString = "<rdf:RDF" + nodeMatcher.group(1) + "</rdf:RDF>";
element.addMiriamData(xmlAnnotationParser.parse(rdfString));
element.addMiriamData(
xmlAnnotationParser.parse(rdfString, new LogMarker(ProjectLogEntryType.PARSING_ISSUE, element)));
notes = notes.substring(0, nodeMatcher.start() - "<rdf:RDF".length())
+ notes.substring(nodeMatcher.end() + "</rdf:RDF>".length());
......
......@@ -15,6 +15,8 @@ import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationPars
import lcsb.mapviewer.converter.model.celldesigner.species.AbstractElementXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerCompartment;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.PathwayCompartment;
......@@ -144,7 +146,9 @@ public class CompartmentXmlParser extends AbstractElementXmlParser<CellDesignerC
Node node = annotationNodes.item(y);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equalsIgnoreCase("rdf:RDF")) {
compartment.addMiriamData(xmlAnnotationParser.parseRdfNode(node));
compartment.addMiriamData(xmlAnnotationParser.parseRdfNode(node,
new LogMarker(ProjectLogEntryType.PARSING_ISSUE, compartment.getClass().getSimpleName(),
compartment.getElementId(), "")));
} else if (node.getNodeName().equalsIgnoreCase("celldesigner:extension")) {
parseExtensionNode(compartment, node);
} else if (node.getNodeName().equalsIgnoreCase("celldesigner:name")) {
......
......@@ -19,6 +19,8 @@ import lcsb.mapviewer.converter.model.celldesigner.geometry.ReactionCellDesigner
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.*;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.*;
import lcsb.mapviewer.converter.model.celldesigner.types.*;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.graphics.*;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
......@@ -313,7 +315,8 @@ public class ReactionFromXml {
try {
XmlAnnotationParser xmlParser = new XmlAnnotationParser(
CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
result.addMiriamData(xmlParser.parseRdfNode(node));
result.addMiriamData(xmlParser.parseRdfNode(node, new LogMarker(ProjectLogEntryType.PARSING_ISSUE,
result.getClass().getSimpleName(), result.getElementId(), model.getName())));
} catch (InvalidXmlSchemaException e) {
throw new ReactionParserException("Problem with parsing RDF", result, e);
}
......
......@@ -17,6 +17,8 @@ import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationPars
import lcsb.mapviewer.converter.model.celldesigner.structure.*;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerModificationResidue;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.SpeciesState;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.PathwayCompartment;
import lcsb.mapviewer.model.map.kinetics.SbmlUnit;
......@@ -198,7 +200,8 @@ public class SpeciesSbmlParser extends AbstractElementXmlParser<CellDesignerSpec
if (rdfNode != null) {
XmlAnnotationParser xmlAnnotationParser = new XmlAnnotationParser(
CommonXmlParser.RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER);
species.addMiriamData(xmlAnnotationParser.parseRdfNode(rdfNode));
species.addMiriamData(xmlAnnotationParser.parseRdfNode(rdfNode, new LogMarker(ProjectLogEntryType.PARSING_ISSUE,
species.getClass().getSimpleName(), species.getElementId(), "")));
}
return result;
......
......@@ -984,7 +984,8 @@ public class SbgnmlXmlParser {
"No rdf node provided in annotation extension");
} else {
try {
element.addMiriamData(new XmlAnnotationParser().parseRdfNode(rdf));
element.addMiriamData(
new XmlAnnotationParser().parseRdfNode(rdf, new LogMarker(ProjectLogEntryType.PARSING_ISSUE, element)));
} catch (InvalidXmlSchemaException e) {
logger.error(e, e);
}
......@@ -1677,7 +1678,7 @@ public class SbgnmlXmlParser {
List<Line2D> lines = new ArrayList<>(product.getLine().getLines());
product.getLine().removeLines();
Collections.reverse(lines);
for (Line2D l: lines) {
for (Line2D l : lines) {
product.getLine().addLine(l.getP2(), l.getP1());
}
}
......
......@@ -18,6 +18,8 @@ import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.converter.model.sbml.species.ElementColorEnum;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.compartment.Compartment;
......@@ -68,13 +70,13 @@ public class SbmlBioEntityParser {
this.layout = getSbmlLayout(sbmlModel);
}
protected Set<MiriamData> extractMiriamDataFromAnnotation(Annotation annotation) throws InvalidInputDataExecption {
protected Set<MiriamData> extractMiriamDataFromAnnotation(Annotation annotation, LogMarker marker) throws InvalidInputDataExecption {
XmlAnnotationParser parser = new XmlAnnotationParser();
Set<MiriamData> result = new HashSet<>();
try {
Node rdfNode = getRdfNodeFromAnnotation(annotation);
if (rdfNode != null) {
result.addAll(parser.parseRdfNode(rdfNode));
result.addAll(parser.parseRdfNode(rdfNode, marker));
}
} catch (InvalidXmlSchemaException e) {
throw new InvalidInputDataExecption(e);
......@@ -136,7 +138,7 @@ public class SbmlBioEntityParser {
protected void assignBioEntityData(AbstractNamedSBase sbmlElement, BioEntity result)
throws InvalidInputDataExecption {
result.addMiriamData(extractMiriamDataFromAnnotation(sbmlElement.getAnnotation()));
result.addMiriamData(extractMiriamDataFromAnnotation(sbmlElement.getAnnotation(), new LogMarker(ProjectLogEntryType.PARSING_ISSUE, result)));
result.setName(sbmlElement.getName());
String notes = NotesUtility.extractNotes(sbmlElement);
result.setNotes(notes);
......
......@@ -72,7 +72,7 @@ public class SbmlParser extends Converter {
SbmlParameterParser parameterParser = new SbmlParameterParser(sbmlModel, model);
SbmlFunctionParser functionParser = new SbmlFunctionParser(sbmlModel, model);
model.addMiriamData(compartmentParser.extractMiriamDataFromAnnotation(sbmlModel.getAnnotation()));
model.addMiriamData(compartmentParser.extractMiriamDataFromAnnotation(sbmlModel.getAnnotation(), null));
model.addAuthors(compartmentParser.extractAuthorsFromAnnotation(sbmlModel.getAnnotation()));
model.addModificationDates(compartmentParser.extractModificationDatesFromAnnotation(sbmlModel.getAnnotation()));
model.setCreationDate(compartmentParser.extractCreationDateFromAnnotation(sbmlModel.getAnnotation()));
......
......@@ -11,6 +11,8 @@ import org.w3c.dom.*;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.model.Author;
......@@ -66,14 +68,14 @@ public class XmlAnnotationParser {
* @throws InvalidXmlSchemaException
* thrown when there is a problem with xml
*/
public Set<MiriamData> parse(String data) throws InvalidXmlSchemaException {
public Set<MiriamData> parse(String data, LogMarker marker) throws InvalidXmlSchemaException {
// start from creating a DOM parser and parse the whole document
Document doc = XmlParser.getXmlDocumentFromString(data);
NodeList root = doc.getChildNodes();
// process the whole schema
return parseRdfNode(root);
return parseRdfNode(root, marker);
}
/**
......@@ -85,9 +87,9 @@ public class XmlAnnotationParser {
* @throws InvalidXmlSchemaException
* thrown when there is a problem with xml
*/
private Set<MiriamData> parseRdfNode(NodeList root) throws InvalidXmlSchemaException {
private Set<MiriamData> parseRdfNode(NodeList root, LogMarker marker) throws InvalidXmlSchemaException {
Node rdf = XmlParser.getNode("rdf:RDF", root);
return parseRdfNode(rdf);
return parseRdfNode(rdf, marker);
}
/**
......@@ -99,7 +101,7 @@ public class XmlAnnotationParser {
* @throws InvalidXmlSchemaException
* thrown when there is a problem with xml
*/
public Set<MiriamData> parseRdfNode(Node rdf) throws InvalidXmlSchemaException {
public Set<MiriamData> parseRdfNode(Node rdf, LogMarker marker) throws InvalidXmlSchemaException {
Set<MiriamData> miriamDataSet = new HashSet<>();
if (rdf != null) {
Node description = XmlParser.getNode("rdf:Description", rdf.getChildNodes());
......@@ -111,7 +113,7 @@ public class XmlAnnotationParser {
String relationTypeString = node.getNodeName();
MiriamRelationType relationType = MiriamRelationType.getTypeByStringRepresentation(relationTypeString);
if (relationType != null) {
miriamDataSet.addAll(parseMiriamNode(node));
miriamDataSet.addAll(parseMiriamNode(node, marker));
} else if (relationTypeString.equals("dc:creator")) {
} else if (relationTypeString.equals("dcterms:created")) {
} else if (relationTypeString.equals("dcterms:modified")) {
......@@ -239,7 +241,7 @@ public class XmlAnnotationParser {
* @throws InvalidXmlSchemaException
* thrown when there is a problem with xml
*/
public Set<MiriamData> parseMiriamNode(Node node) throws InvalidXmlSchemaException {
public Set<MiriamData> parseMiriamNode(Node node, LogMarker logMarker) throws InvalidXmlSchemaException {
Set<MiriamData> result = new HashSet<>();
NodeList list = node.getChildNodes();
String relationTypeString = node.getNodeName();
......@@ -259,7 +261,8 @@ public class XmlAnnotationParser {
try {
MiriamData md = MiriamType.getMiriamByUri(dataTypeUri);
if (relationType == null) {
logger.warn("Unknown relation type: " + relationTypeString + ". For miriam uri: " + dataTypeUri + ".");
logger.warn(logMarker,
"Unknown relation type: " + relationTypeString + ". For miriam uri: " + dataTypeUri + ".");
} else {
if (!MiriamType.PUBMED.equals(md.getDataType())) {
md.setRelationType(relationType);
......@@ -267,7 +270,7 @@ public class XmlAnnotationParser {
result.add(md);
}
} catch (InvalidArgumentException e) {
logger.warn(e.getMessage());
logger.warn(logMarker, e.getMessage());
}
}
return result;
......
......@@ -28,7 +28,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
String xml = readFile("testFiles/annotation/rdf.xml");
Set<MiriamData> set = xap.parse(xml);
Set<MiriamData> set = xap.parse(xml, null);
assertEquals(2, set.size());
}
......@@ -38,7 +38,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
String xml = readFile("testFiles/annotation/rdf_has_property.xml");
Set<MiriamData> set = xap.parse(xml);
Set<MiriamData> set = xap.parse(xml, null);
assertEquals(0, super.getWarnings().size());
assertEquals(7, set.size());
}
......@@ -49,7 +49,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
XmlAnnotationParser parser = new XmlAnnotationParser();
String xml = parser.miriamDataToXmlString(md);
assertNotNull(xml);
Set<MiriamData> set = parser.parseMiriamNode(super.getNodeFromXmlString(xml));
Set<MiriamData> set = parser.parseMiriamNode(super.getNodeFromXmlString(xml), null);
assertNotNull(set);
assertEquals(1, set.size());
MiriamData md1 = set.iterator().next();
......@@ -63,7 +63,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
public void testParseInvalidRdf() throws Exception {
XmlAnnotationParser xap = new XmlAnnotationParser();
xap.parseRdfNode((Node) null);
xap.parseRdfNode((Node) null, null);
}
@Test
......@@ -71,7 +71,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
XmlAnnotationParser xap = new XmlAnnotationParser();
String xml = readFile("testFiles/annotation/rdf_with_creator_tag.xml");
Set<MiriamData> set = xap.parse(xml);
Set<MiriamData> set = xap.parse(xml, null);
assertTrue(set.size() > 0);
}
......@@ -81,7 +81,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
String xml = readFile("testFiles/annotation/invalid_rdf2.xml");
xap.parse(xml);
xap.parse(xml, null);
}
@Test
......@@ -90,7 +90,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
String xml = readFile("testFiles/annotation/invalid_rdf3.xml");
xap.parse(xml);
xap.parse(xml, null);
assertEquals(1, getWarnings().size());
}
......@@ -101,7 +101,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
String xml = readFile("testFiles/annotation/invalid_rdf4.xml");
xap.parse(xml);
xap.parse(xml, null);
assertEquals(1, getWarnings().size());
}
......@@ -111,7 +111,7 @@ public class XmlAnnotationParserTest extends ConverterTestFunctions {
MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CHEBI, "e:f");
XmlAnnotationParser parser = new XmlAnnotationParser(Arrays.asList(MiriamRelationType.BQ_BIOL_ENCODES));
String xml = parser.miriamDataToXmlString(md);
Set<MiriamData> set = parser.parseMiriamNode(super.getNodeFromXmlString(xml));
Set<MiriamData> set = parser.parseMiriamNode(super.getNodeFromXmlString(xml), null);
assertNotNull(set);
MiriamData md1 = set.iterator().next();
assertNotEquals(md.getRelationType(), md1.getRelationType());
......
Supports Markdown
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