Skip to content
Snippets Groups Projects
Commit e4b86014 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

export/import of model notes added

parent 225dbf0e
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!560Resolve "add support for modifications and states in sbml export/import"
package lcsb.mapviewer.converter.model.sbml;
import javax.xml.stream.XMLStreamException;
import org.sbml.jsbml.AbstractNamedSBase;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
public class NotesUtility {
public static String extractNotes(AbstractNamedSBase sbmlElement) throws InvalidInputDataExecption {
String notes = "";
try {
notes = sbmlElement.getNotesString();
} catch (XMLStreamException e) {
throw new InvalidInputDataExecption(sbmlElement.getId() + " Invalid notes", e);
}
if (sbmlElement.getNotes() != null) {
if (sbmlElement.getNotes().getChildCount() > 1) {
if (sbmlElement.getNotes().getChild(1).getChildCount() > 1) {
if (sbmlElement.getNotes().getChild(1).getChild(1).getChildCount() > 0) {
notes = sbmlElement.getNotes().getChild(1).getChild(1).getChild(0).getCharacters();
} else {
notes = sbmlElement.getNotes().getChild(1).getChild(1).getCharacters();
}
}
}
}
return notes;
}
}
......@@ -95,7 +95,7 @@ public class SbmlBioEntityParser extends XmlParser {
if (result.getName() == null || result.getName().isEmpty()) {
result.setName(result.getElementId());
}
String notes = extractNotes(sbmlElement);
String notes = NotesUtility.extractNotes(sbmlElement);
result.setNotes(notes);
if (result instanceof Element) {
......@@ -104,27 +104,6 @@ public class SbmlBioEntityParser extends XmlParser {
}
}
private String extractNotes(AbstractNamedSBase sbmlElement) throws InvalidInputDataExecption {
String notes = "";
try {
notes = sbmlElement.getNotesString();
} catch (XMLStreamException e) {
throw new InvalidInputDataExecption(sbmlElement.getId() + " Invalid notes", e);
}
if (sbmlElement.getNotes() != null) {
if (sbmlElement.getNotes().getChildCount() > 1) {
if (sbmlElement.getNotes().getChild(1).getChildCount() > 1) {
if (sbmlElement.getNotes().getChild(1).getChild(1).getChildCount() > 0) {
notes = sbmlElement.getNotes().getChild(1).getChild(1).getChild(0).getCharacters();
} else {
notes = sbmlElement.getNotes().getChild(1).getChild(1).getCharacters();
}
}
}
}
return notes;
}
protected String getNextId() {
return (idCounter++) + "";
}
......
......@@ -9,6 +9,7 @@ import java.util.Set;
import javax.xml.stream.XMLStreamException;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.log4j.Logger;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.SBMLDocument;
......@@ -78,6 +79,12 @@ public class SbmlExporter {
SBMLDocument doc = new SBMLDocument(3, 2);
Model result = doc.createModel(model.getIdModel());
result.setName(model.getName());
try {
result.setNotes(StringEscapeUtils.escapeXml(model.getNotes()));
} catch (XMLStreamException e) {
throw new InvalidStateException(e);
}
if (usedExtensions.contains(SbmlExtension.LAYOUT)) {
createSbmlLayout(model, result);
}
......
......@@ -68,6 +68,7 @@ public class SbmlParser implements IConverter {
org.sbml.jsbml.Model sbmlModel = sbmlDocument.getModel();
model.setIdModel(sbmlModel.getId());
model.setName(sbmlModel.getName());
model.setNotes(NotesUtility.extractNotes(sbmlModel));
checkAvailableExtensions(sbmlModel);
Layout layout = getSbmlLayout(sbmlModel);
......
......@@ -614,4 +614,14 @@ public class SbmlExporterTest {
}
@Test
public void testExportNotes() throws Exception {
Model model = createEmptyModel();
model.setNotes("XX");
Model deserializedModel = getModelAfterSerializing(model);
assertEquals("Notes weren't exported/imported properly", model.getNotes(), deserializedModel.getNotes());
}
}
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