Commit e3faa81c authored by Piotr Gawron's avatar Piotr Gawron

Merge branch 'gpml-logging' into 'master'

Gpml logging added

See merge request !992
parents a5d86a8f 0d1f5e85
Pipeline #16060 passed with stage
in 13 minutes and 18 seconds
......@@ -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,
}
This diff is collapsed.
......@@ -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();
Point2D toPoint = end.toPoint();
......@@ -548,7 +555,7 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
* @return new {@link Edge} object with unique identifier
*/
public Edge createEmpty() {
return new Edge(getNewId());
return new Edge(getNewId(), getMapName());
}
/**
......@@ -564,13 +571,13 @@ public class EdgeParser extends ElementGpmlParser<Edge> {
String value = eTmp.getAttribute("Value");
switch (key) {
case ("org.pathvisio.core.ds"):
// skip for now (no idea what des it mean)
// skip for now (no idea what does it mean)
break;
case ("org.pathvisio.core.id"):
// skip for now (no idea what des it mean)
// skip for now (no idea what does it mean)
break;
default:
logger.warn(edge.getWarningPrefix() + "Unknown attribute of node. Key: " + key + "; value: " + value);
logger.warn(edge.getLogMarker(), "Unknown attribute of node. Key: " + key + "; value: " + value);
break;
}
}
......
package lcsb.mapviewer.wikipathway.XML;
import java.awt.*;
import java.awt.Color;
import java.util.*;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -18,7 +17,7 @@ import lcsb.mapviewer.converter.ConverterException;
* @author Piotr Gawron
*
* @param <T>
* class for which this parser aplies
* class for which this parser applies
*/
public abstract class ElementGpmlParser<T> {
......@@ -32,6 +31,12 @@ public abstract class ElementGpmlParser<T> {
@SuppressWarnings("unused")
private final Logger logger = LogManager.getLogger(ElementGpmlParser.class);
private String mapName;
public ElementGpmlParser(String mapName) {
this.mapName = mapName;
}
/**
* Creates object from xml node given in parameter.
*
......@@ -44,7 +49,7 @@ public abstract class ElementGpmlParser<T> {
public abstract T parse(Element node) throws ConverterException;
/**
* Converts object into xml string (in gpml format).
* Converts object into xml string (in GPML format).
*
* @param object
* object to transform
......@@ -55,7 +60,7 @@ public abstract class ElementGpmlParser<T> {
public abstract String toXml(T object) throws ConverterException;
/**
* Converts list of objects into xml string (in gpml format) representing this
* Converts list of objects into xml string (in GPML format) representing this
* list.
*
* @param list
......@@ -131,4 +136,7 @@ public abstract class ElementGpmlParser<T> {
return result;
}
public String getMapName() {
return mapName;
}
}
......@@ -15,11 +15,11 @@ import lcsb.mapviewer.wikipathway.model.Graph;
public class GPMLToModel {
/**
* This function creates model from gpml input stream.
* This function creates model from GPML input stream.
*
* @param stream
* input stream that contains gpml data
* @return {@link Model} created from gpml file
* input stream that contains GPML data
* @return {@link Model} created from GPML file
* @throws IOException
* thrown when there is a problem with input file
* @throws ConverterException
......@@ -27,7 +27,7 @@ public class GPMLToModel {
*/
public Model getModel(InputStream stream) throws IOException, ConverterException {
Graph graph = new GpmlParser().createGraph(stream);
Model model = new ModelContructor().getModel(graph);
Model model = new ModelContructor(graph.getMapName()).getModel(graph);
return model;
}
......
......@@ -22,7 +22,11 @@ public abstract class GraphicalPathwayElementParser<T extends GraphicalPathwayEl
/**
* Default class logger.
*/
private final Logger logger = LogManager.getLogger(GraphicalPathwayElementParser.class);
private final Logger logger = LogManager.getLogger();
public GraphicalPathwayElementParser(String mapName) {
super(mapName);
}
/**
* Parse font attributes that might appear.
......
......@@ -29,14 +29,19 @@ public class LabelParser extends GraphicalPathwayElementParser<Label> {
*/
private final Logger logger = LogManager.getLogger();
private ReferenceParser referenceParser = new ReferenceParser();
private ReferenceParser referenceParser;
public LabelParser(String mapName) {
super(mapName);
referenceParser = new ReferenceParser(mapName);
}
@Override
public Label parse(Element eElement) throws UnknownTypeException {
if (!eElement.getNodeName().equals("Label")) {
throw new InvalidArgumentException(ShapeParser.class.getSimpleName() + " can parse only Label xml nodes");
}
Label label = new Label(eElement.getAttribute("GraphId"));
Label label = new Label(eElement.getAttribute("GraphId"), getMapName());
for (Pair<String, String> entry : getAttributes(eElement)) {
switch (entry.getLeft()) {
......@@ -176,12 +181,12 @@ public class LabelParser extends GraphicalPathwayElementParser<Label> {
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;
}
}
......
......@@ -10,13 +10,16 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.*;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.converter.model.celldesigner.geometry.CellDesignerAliasConverter;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.PolylineDataFactory;
import lcsb.mapviewer.converter.model.celldesigner.reaction.ReactionLineData;
import lcsb.mapviewer.converter.model.celldesigner.types.ModifierType;
import lcsb.mapviewer.converter.model.celldesigner.types.ModifierTypeUtils;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.Drawable;
import lcsb.mapviewer.model.map.MiriamData;
......@@ -77,11 +80,16 @@ public class ModelContructor {
/**
* Default class logger.
*/
private Logger logger = LogManager.getLogger(ModelContructor.class);
private Logger logger = LogManager.getLogger();
/**
* Parser used for extracting {@link MiriamData references} from GPML model.
*/
private BiopaxFactory biopaxFactory = new BiopaxFactory();
private BiopaxFactory biopaxFactory;
public ModelContructor(String mapName) {
biopaxFactory = new BiopaxFactory(mapName);
}
/**
* This function creates Species from DataNode.
......@@ -242,7 +250,7 @@ public class ModelContructor {
((Gene) species).addModificationSite((ModificationSite) mr);
} else {
logger.warn(
state.getWarningPrefix() + "state for " + species.getClass().getSimpleName() + " is not supported.");
state.getLogMarker(), "state for " + species.getClass().getSimpleName() + " is not supported.");
}
if (mr != null) {
mr.setIdModificationResidue(state.getGraphId());
......@@ -259,10 +267,10 @@ public class ModelContructor {
if (protein.getStructuralState() == null) {
protein.setStructuralState(createStructuralState(state, protein));
} else {
logger.warn(state.getWarningPrefix() + " tries to override another state: " + protein.getStructuralState());
logger.warn(state.getLogMarker(), " tries to override another state: " + protein.getStructuralState());
}
} else {
logger.warn(state.getWarningPrefix() + "structural state for " + species.getClass().getSimpleName()
logger.warn(state.getLogMarker(), "structural state for " + species.getClass().getSimpleName()
+ " is not supported.");
}
}
......@@ -321,7 +329,7 @@ public class ModelContructor {
public LayerRect createRectangle(Shape shape) {
LayerRect rect = new LayerRect();
Rectangle2D rec;
if (shouldRotate90degrees(shape.getRotation())) {
if (shouldRotate90degrees(shape)) {
rec = rotate90degrees(shape.getRectangle());
} else {
rec = shape.getRectangle();
......@@ -339,7 +347,15 @@ public class ModelContructor {
rectangle.getCenterY() - rectangle.getWidth() / 2, rectangle.getHeight(), rectangle.getWidth());
}
boolean shouldRotate90degrees(Shape shape) {
return shouldRotate90degrees(shape.getRotation(), shape);
}
boolean shouldRotate90degrees(Double rot) {
return shouldRotate90degrees(rot, null);
}
boolean shouldRotate90degrees(Double rot, Shape shape) {
if (rot == null) {
return false;
}
......@@ -352,12 +368,20 @@ public class ModelContructor {
}
if (Math.abs(rotation) < Math.PI / 4) {
if (Math.abs(rotation) > Configuration.EPSILON) {
logger.warn("Rotation of objects is not supported. Rotation=" + rot);
LogMarker marker = null;
if (shape != null) {
marker = shape.getLogMarker();
}
logger.warn(marker, "Rotation of objects is not supported. Rotation=" + rot);
}
return false;
}
if ((Math.PI / 2 - Math.abs(rotation)) > Configuration.EPSILON) {
logger.warn("Rotation of objects is not supported. Rotation=" + rot);
LogMarker marker = null;
if (shape != null) {
marker = shape.getLogMarker();
}
logger.warn(marker, "Rotation of objects is not supported. Rotation=" + rot);
}
return true;
}
......@@ -483,7 +507,7 @@ public class ModelContructor {
* @return {@link Unknown} object created from input {@link Label}
*/
private Species createSpecies(Label label) {
logger.warn(label.getWarningPrefix() + " Label cannot be part of reaction. Tranforming to Unknown");
logger.warn(label.getLogMarker(), " Label cannot be part of reaction. Tranforming to Unknown");
Species res = new Unknown(label.getGraphId());
res.addMiriamData(label.getReferences());
......@@ -504,7 +528,7 @@ public class ModelContructor {
* @return {@link Unknown} object created from input {@link Label}
*/
private Species createSpecies(Shape shape) {
logger.warn(shape.getWarningPrefix() + " Shape can not be part of reaction. Tranforming to Unknown");
logger.warn(shape.getLogMarker(), " Shape can not be part of reaction. Tranforming to Unknown");
Species res = new Unknown(shape.getGraphId());
StringBuilder notes = new StringBuilder();
......@@ -550,7 +574,7 @@ public class ModelContructor {
} else if (graph.getShapeByGraphId(pe.getGraphId()) != null) {
Shape shape = graph.getShapeByGraphId(pe.getGraphId());
if (INALID_COMPLEX_SHAPE_CHILDREN.contains(shape.getShape())) {
logger.warn(shape.getWarningPrefix() + shape.getShape() + " cannot be part of a complex. Skipping.");
logger.warn(shape.getLogMarker(), shape.getShape() + " cannot be part of a complex. Skipping.");
} else {
throw new UnknownChildClassException("Unknown class type with id \"" + pe.getGraphId() + "\": "
+ shape.getShape() + ". Group id: " + group.getGraphId());
......@@ -653,7 +677,7 @@ public class ModelContructor {
reaction.addNode(splitOperator);
} else {
PolylineData operatorLine = lines.get(SplitOperator.class);
for (int i = 0; i < operatorLine.getPoints().size()-1; i++) {
for (int i = 0; i < operatorLine.getPoints().size() - 1; i++) {
productLine.addPoint(i, operatorLine.getPoints().get(i));
}
product.setLine(PolylineDataFactory.removeCollinearPoints(productLine));
......@@ -664,12 +688,14 @@ public class ModelContructor {
reaction.addModifier(mod);
}
if (reaction instanceof TwoReactantReactionInterface && reaction.getReactants().size() < 2) {
logger.warn("Reaction should contain at least 2 reactants. GraphId: " + interaction.getGraphId());
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, reaction),