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

gpml parser provides structured logs

parent 41a9a832
......@@ -32,6 +32,14 @@ public class LogMarker implements Marker {
entry = new ProjectLogEntry(marker.getEntry());
}
public LogMarker(ProjectLogEntryType type, String objectClass, String objectIdentifier, String mapName) {
entry = new ProjectLogEntry();
entry.setType(type);
entry.setObjectIdentifier(objectIdentifier);
entry.setObjectClass(objectClass);
entry.setMapName(mapName);
}
@Override
public Marker addParents(Marker... markers) {
throw new NotImplementedException();
......
......@@ -9,5 +9,6 @@ public enum ProjectLogEntryType {
MISSING_ANNOTATION,
MISSING_REQUIRED_ANNOTATION,
OUT_OF_MEMORY,
OTHER,
OTHER,
PARSING_ISSUE,
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>lcsb.mapviewer</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>pathvisio</artifactId>
<name>Pathvisio plugin</name>
<!-- <packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.0.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>lcsb.mapviewer.wikipathway.Activator</Bundle-Activator>
<Bundle-Name>CellDesigner plugin v.${svnversion}</Bundle-Name>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Import-Package>!org.relaxng.datatype,
!org.slf4j,
!org.slf4j.spi,
!com.fasterxml.classmate,
!com.fasterxml.classmate.members,
!com.ibm.uvm.tools,
!com.sun.jdi,
!com.sun.jdi.connect,
!com.sun.jdi.event,
!com.sun.jdi.request,
!com.sun.jdmk.comm,
!com.sun.msv.datatype,
!com.sun.msv.datatype.xsd,
!com.google.gson,
!javax.imageio,
!javax.jmdns,
!javax.jms,
!javax.mail,
!javax.mail.internet,
!javax.management,
!javax.naming,
!javax.naming.event,
!javax.naming.spi,
!javax.security.auth,
!javax.security.jacc,
!javax.sql,
!javax.swing,
!javax.swing.border,
!javax.swing.event,
!javax.swing.filechooser,
!javax.swing.plaf,
!javax.swing.table,
!javax.swing.text,
!javax.swing.text.html,
!javax.swing.tree,
!javax.validation,
!javax.validation.constraints,
!javax.validation.groups,
!javax.validation.metadata,
!javax.xml,
!javax.xml.bind,
!javax.xml.bind.annotation,
!javax.xml.bind.annotation.adapters,
!javax.xml.namespace,
!javax.xml.parsers,
!javax.xml.stream,
!javax.xml.stream.events,
!javax.xml.stream.util,
!javax.xml.transform,
!javax.xml.transform.dom,
!javax.xml.transform.sax,
!javax.xml.transform.stream,
!javax.xml.validation,
!oracle.xml.parser,
!oracle.xml.parser.v2,
!org.apache.batik.dom,
!org.apache.batik.svggen,
!org.apache.batik.transcoder,
!org.apache.batik.transcoder.image,
!org.apache.commons.math,
!org.apache.commons.math.stat,
!org.apache.commons.math.stat.inference,
!org.apache.commons.vfs2,
!org.apache.fop.svg,
!org.apache.tools.ant,
!org.apache.tools.ant.taskdefs,
!org.apache.tools.ant.types,
!org.bridgedb,
!org.bridgedb.bio,
!org.bridgedb.gui,
!org.bridgedb.rdb.construct,
!org.gjt.xpp,
!org.jaxen,
!org.jaxen.jdom,
!org.jaxen.dom4j,
!org.jaxen.pattern,
!org.jaxen.saxpath,
!org.jboss.jandex,
!org.jboss.logmanager,
!org.jdom,
!org.jdom.input,
!org.jdom.output,
!org.pathvisio.data,
!org.w3c.dom,
!org.w3c.dom.events,
!org.w3c.dom.ranges,
!org.w3c.dom.traversal,
!org.xml.sax,
!org.xml.sax.ext,
!org.xml.sax.helpers,
!org.xmlpull.v1,
!sun.io,
!sun.misc,
org.osgi.framework;version=1.3.0,*</Import-Package>
<Require-Bundle>org.pathvisio.core;bundle-version=3.0.0,
org.pathvisio.desktop;bundle-version=3.0.0,
org.pathvisio.gui;bundle-version=3.0.0
</Require-Bundle>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>lcsb.mapviewer</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>pathvisio</artifactId>
<name>Pathvisio plugin</name>
<!-- <packaging>bundle</packaging> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId> <version>4.0.0</version> <extensions>true</extensions>
<configuration> <instructions> <Bundle-Activator>lcsb.mapviewer.wikipathway.Activator</Bundle-Activator>
<Bundle-Name>CellDesigner plugin v.${svnversion}</Bundle-Name> <Embed-Transitive>true</Embed-Transitive>
<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Import-Package>!org.relaxng.datatype, !org.slf4j, !org.slf4j.spi, !com.fasterxml.classmate,
!com.fasterxml.classmate.members, !com.ibm.uvm.tools, !com.sun.jdi, !com.sun.jdi.connect,
!com.sun.jdi.event, !com.sun.jdi.request, !com.sun.jdmk.comm, !com.sun.msv.datatype,
!com.sun.msv.datatype.xsd, !com.google.gson, !javax.imageio, !javax.jmdns,
!javax.jms, !javax.mail, !javax.mail.internet, !javax.management, !javax.naming,
!javax.naming.event, !javax.naming.spi, !javax.security.auth, !javax.security.jacc,
!javax.sql, !javax.swing, !javax.swing.border, !javax.swing.event, !javax.swing.filechooser,
!javax.swing.plaf, !javax.swing.table, !javax.swing.text, !javax.swing.text.html,
!javax.swing.tree, !javax.validation, !javax.validation.constraints, !javax.validation.groups,
!javax.validation.metadata, !javax.xml, !javax.xml.bind, !javax.xml.bind.annotation,
!javax.xml.bind.annotation.adapters, !javax.xml.namespace, !javax.xml.parsers,
!javax.xml.stream, !javax.xml.stream.events, !javax.xml.stream.util, !javax.xml.transform,
!javax.xml.transform.dom, !javax.xml.transform.sax, !javax.xml.transform.stream,
!javax.xml.validation, !oracle.xml.parser, !oracle.xml.parser.v2, !org.apache.batik.dom,
!org.apache.batik.svggen, !org.apache.batik.transcoder, !org.apache.batik.transcoder.image,
!org.apache.commons.math, !org.apache.commons.math.stat, !org.apache.commons.math.stat.inference,
!org.apache.commons.vfs2, !org.apache.fop.svg, !org.apache.tools.ant, !org.apache.tools.ant.taskdefs,
!org.apache.tools.ant.types, !org.bridgedb, !org.bridgedb.bio, !org.bridgedb.gui,
!org.bridgedb.rdb.construct, !org.gjt.xpp, !org.jaxen, !org.jaxen.jdom, !org.jaxen.dom4j,
!org.jaxen.pattern, !org.jaxen.saxpath, !org.jboss.jandex, !org.jboss.logmanager,
!org.jdom, !org.jdom.input, !org.jdom.output, !org.pathvisio.data, !org.w3c.dom,
!org.w3c.dom.events, !org.w3c.dom.ranges, !org.w3c.dom.traversal, !org.xml.sax,
!org.xml.sax.ext, !org.xml.sax.helpers, !org.xmlpull.v1, !sun.io, !sun.misc,
org.osgi.framework;version=1.3.0,*</Import-Package> <Require-Bundle>org.pathvisio.core;bundle-version=3.0.0,
org.pathvisio.desktop;bundle-version=3.0.0, org.pathvisio.gui;bundle-version=3.0.0
</Require-Bundle> </instructions> </configuration> </plugin> </plugins> </build> -->
<repositories>
<repository>
<id>repo</id>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/repo</url>
<id>repo</id>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
......@@ -149,39 +61,39 @@
<artifactId>core</artifactId>
<version>${pathvisio.version}</version>
</dependency>
<dependency>
<groupId>org.pathvisio</groupId>
<artifactId>desktop</artifactId>
<version>${pathvisio.version}</version>
</dependency>
<dependency>
<groupId>org.pathvisio</groupId>
<artifactId>gui</artifactId>
<version>${pathvisio.version}</version>
</dependency>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>model</artifactId>
<version>1.0</version>
</dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>model</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>converter-CellDesigner</artifactId>
<version>1.0</version>
</dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>converter-CellDesigner</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>converter-graphics</artifactId>
<scope>test</scope>
<version>1.0</version>
</dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>converter-graphics</artifactId>
<scope>test</scope>
<version>1.0</version>
</dependency>
<!-- Log4J2-->
<!-- Log4J2 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
......@@ -193,11 +105,11 @@
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>${osgi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>${osgi.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
......@@ -206,5 +118,14 @@
<scope>test</scope>
</dependency>
<!-- mockito used for testing -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -35,7 +35,7 @@ public class GpmlParser extends Converter {
@Override
public String model2String(Model model) throws InconsistentModelException, ConverterException {
ModelToGPML modelToGPML = new ModelToGPML();
ModelToGPML modelToGPML = new ModelToGPML(model.getName());
return modelToGPML.getGPML(model);
}
......
......@@ -112,7 +112,7 @@ public class ImportExport implements Plugin {
CellDesignerXmlParser parser = new CellDesignerXmlParser();
Model model = (Model) parser.createModel(new ConverterParams().filename(fileName).sizeAutoAdjust(false));
String tmp = new ModelToGPML().getGPML(model);
String tmp = new ModelToGPML(model.getName()).getGPML(model);
InputStream stream = new ByteArrayInputStream(tmp.getBytes(StandardCharsets.UTF_8));
Boolean validate = false;
pathway.readFromXml(stream, validate);
......
......@@ -8,12 +8,14 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.wikipathway.model.biopax.*;
/**
* Parser of Biopax data from the gpml file.
* Parser of Biopax data from the GPML file.
*
* @author Piotr Gawron
*
......@@ -34,7 +36,13 @@ public class BiopaxParser {
* Mapping between {@link MiriamData} and hash value.
*/
private Map<MiriamData, String> miriamHash = new HashMap<>();
private String mapName;
public BiopaxParser(String mapName) {
this.mapName = mapName;
}
/**
* Creates data structure from BioPax xml node.
*
......@@ -51,7 +59,7 @@ public class BiopaxParser {
if ("bp:PublicationXref".equalsIgnoreCase(node.getNodeName())) {
BiopaxPublication publication = parsePublication(node);
if (publication.getId() == null || publication.getId().isEmpty()) {
logger.warn("No pubmed identifier defined for publication: title: " + publication.getTitle());
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, publication.getId(), "BioPax", mapName), "No pubmed identifier defined for publication: title: " + publication.getTitle());
}
result.addPublication(publication);
} else if ("bp:openControlledVocabulary".equalsIgnoreCase(node.getNodeName())) {
......
package lcsb.mapviewer.wikipathway.XML;
import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.wikipathway.model.Edge;
/**
* Exception that shold be thrown when edges create a cycle. Consider an example
......@@ -25,14 +27,24 @@ public class CyclicEdgeException extends ConverterException {
*/
private static final long serialVersionUID = 1L;
private Edge edge;
/**
* Default constructor with message passed in the argument.
*
* @param string
* message of this exception
*/
public CyclicEdgeException(String string) {
public CyclicEdgeException(String string, Edge edge) {
super(string);
this.edge = edge;
}
public LogMarker getLogMarker() {
if (edge != null) {
return edge.getLogMarker();
}
return null;
}
}
......@@ -24,21 +24,26 @@ import lcsb.mapviewer.wikipathway.model.*;
public class DataNodeParser extends GraphicalPathwayElementParser<DataNode> {
/**
* Default claass logger.
* Default class logger.
*/
private final Logger logger = LogManager.getLogger(DataNodeParser.class);
/**
* PArser used to process references.
*/
private final ReferenceParser referenceParser = new ReferenceParser();
private final ReferenceParser referenceParser;
public DataNodeParser(String mapName) {
super(mapName);
referenceParser = new ReferenceParser(mapName);
}
@Override
public DataNode parse(Element eElement) throws UnknownTypeException {
if (!eElement.getNodeName().equals("DataNode")) {
throw new InvalidArgumentException(ShapeParser.class.getSimpleName() + " can parse only DataNode xml nodes");
}
DataNode node = new DataNode(eElement.getAttribute("GraphId"));
DataNode node = new DataNode(eElement.getAttribute("GraphId"), getMapName());
for (Pair<String, String> entry : getAttributes(eElement)) {
switch (entry.getLeft()) {
......@@ -184,12 +189,12 @@ public class DataNodeParser extends GraphicalPathwayElementParser<DataNode> {
case ("org.pathvisio.model.GenMAPP-Xref"):
// skip it when it's empty
if (!value.isEmpty()) {
logger.warn(shape.getWarningPrefix() + "Unknown attribute of node. Key: " + key + "; value: " + value);
logger.warn(shape.getLogMarker() + "Unknown attribute of node. Key: " + key + "; value: " + value);
break;
}
break;
default:
logger.warn(shape.getWarningPrefix() + "Unknown attribute of node. Key: " + key + "; value: " + value);
logger.warn(shape.getLogMarker() + "Unknown attribute of node. Key: " + key + "; value: " + value);
break;
}
}
......
......@@ -14,7 +14,7 @@ import lcsb.mapviewer.wikipathway.model.Edge;
/**
* Parser class that creates {@link Edge} objects from Xml {@link Element node}.
* However the xml node is not typica edge node , but line node.
* However the xml node is not typical edge node , but line node.
*
* @author Piotr Gawron
*
......@@ -24,12 +24,17 @@ public class EdgeLineParser extends ElementGpmlParser<Edge> {
/**
* Default class logger.
*/
private final Logger logger = LogManager.getLogger(EdgeLineParser.class);
private final Logger logger = LogManager.getLogger();
/**
* Parser used to parse typical {@link Edge} xml nodes.
*/
private final EdgeParser edgeParser = new EdgeParser();
private final EdgeParser edgeParser;
public EdgeLineParser(String mapName) {
super(mapName);
this.edgeParser = new EdgeParser(mapName);
}
/**
* Creates {@link Edge} from xml line node.
......
......@@ -13,6 +13,7 @@ import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.wikipathway.model.*;
......@@ -29,13 +30,13 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
*/
private static final int INITIAL_ID_VALUE = 10000;
/**
* This is default lenght of lines when lines are drawn in
* {@link GpmlLineConnectorType#ELBOW} mode, but without specifing coordinates.
* This is default length of lines when lines are drawn in
* {@link GpmlLineConnectorType#ELBOW} mode, but without specifying coordinates.
*/
private static final double DEFAULT_DISTNACE = 20;
/**
* Counter used for generating identifiers if identifiers aren't provided by the
* gpml model.
* GPML model.
*/
private static int idCounter = INITIAL_ID_VALUE;
/**
......@@ -46,11 +47,11 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
* Parser used for extracting {@link lcsb.mapviewer.model.map.MiriamData
* references} from GPML model.
*/
private ReferenceParser referenceParser = new ReferenceParser();
private ReferenceParser referenceParser;
/**
* Parser used for extracting {@link PointData points} from GPML xml nodes.
*/
private PointDataParser pointParser = new PointDataParser();
private PointDataParser pointParser;
/**
* This function get new id for interactions that don't have id.
......@@ -62,6 +63,12 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
return "id" + idCounter;
}
public EdgeParser(String mapName) {
super(mapName);
pointParser = new PointDataParser(mapName);
referenceParser = new ReferenceParser(mapName);
}
/**
* Creates {@link Edge} from xml node.
*
......@@ -76,7 +83,7 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
if (graphId == null || graphId.equals("")) {
graphId = getNewId();
}
Edge edge = new Edge(graphId);
Edge edge = new Edge(graphId, getMapName());
for (Pair<String, String> entry : getAttributes(eElement)) {
switch (entry.getLeft()) {
......@@ -120,13 +127,13 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
parseAttribute(element, edge);
break;
default:
logger.warn(edge.getWarningPrefix() + "Unknown edge node: " + node.getNodeName() + ".");
logger.warn(edge.getLogMarker(), "Unknown edge node: " + node.getNodeName() + ".");
break;
}
}
}
if (!graphicsParsed) {
throw new ConverterException(edge.getWarningPrefix() + "No Graphics information found for edge.");
throw new ConverterException(edge.getLogMarker() + "No Graphics information found for edge.");
}
return edge;
}
......@@ -191,7 +198,7 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
} else if ("Anchor".equalsIgnoreCase(node.getNodeName())) {
anchors.add((Element) node);
} else {
logger.warn(edge.getWarningPrefix() + "Unknown graphics edge node: " + node.getNodeName() + ".");
logger.warn(edge.getLogMarker(), "Unknown graphics edge node: " + node.getNodeName() + ".");
}
}
}
......@@ -216,17 +223,17 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
}
edge.setReversibleReaction(pointDataList.get(0).getType() == GpmlInteractionType.ARROW);
edge.getLine().setPoints(getPoints(edge.getWarningPrefix(), pointDataList, connectorType));
edge.getLine().setPoints(getPoints(edge.getLogMarker(), pointDataList, connectorType));
if (edge.getLine().getPoints().size() < 2) {
throw new ConverterException(
edge.getWarningPrefix() + "Contains too less points. At least two points are required in a line.");
edge.getLogMarker() + "Contains too less points. At least two points are required in a line.");
}
double lineLength = 0;
for (Line2D line : edge.getLine().getLines()) {
lineLength += line.getP1().distance(line.getP2());
}
if (lineLength <= Configuration.EPSILON) {
throw new ConverterException(edge.getWarningPrefix() + "Line cannot have 0 length.");
throw new ConverterException(edge.getLogMarker() + "Line cannot have 0 length.");
}
// anchors
......@@ -268,7 +275,7 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
* @throws UnknownTypeException
* throw when connector type is invalid
*/
List<Point2D> getPoints(String warningPrefix, List<PointData> pointDataList,
List<Point2D> getPoints(LogMarker warningPrefix, List<PointData> pointDataList,
GpmlLineConnectorType connectorType)
throws InvalidElbowConnectorException, UnknownTypeException {
List<Point2D> result = new ArrayList<>();
......@@ -371,7 +378,7 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
// if line is curved then inform user that we don't support it and create
// a default one
case CURVED:
logger.warn(warningPrefix + "Curved connections are not supported.");
logger.warn(warningPrefix, "Curved connections are not supported.");
for (PointData pointData : pointDataList) {
result.add(pointData.toPoint());
}
......@@ -397,7 +404,7 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
* @throws InvalidElbowConnectorException
* thrown when output cannot be computed because input data is invalid
*/
private int computeNumberOfPerpendicularSegments(String warningPrefix, PointData start, PointData end)
private int computeNumberOfPerpendicularSegments(LogMarker warningPrefix, PointData start, PointData end)
throws InvalidElbowConnectorException {
Point2D fromPoint = start.toPoint();