Commit 14b67122 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1264-sbgn-file-with-bom-cannot-be-converted-to-image-by-api-converter' into 'master'

Resolve "SBGN file with BOM cannot be converted to image by API converter"

Closes #1264

See merge request !1162
parents fa0d8ac8 58d16875
Pipeline #27676 passed with stage
in 15 minutes and 28 seconds
......@@ -4,6 +4,7 @@ minerva (15.0.0~beta.5) unstable; urgency=medium
(#1262)
* Bug fix: there is a bug in PathVisio that breaks short segments being the
end of catalist therefore short segments are removed from export (#1263)
* Bug fix: conversion of file containing BOM did not work (#1264)
-- Piotr Gawron <piotr.gawron@uni.lu> Tue, 2 Jun 2020 16:00:00 +0200
......
......@@ -35,7 +35,7 @@ public class ConvertController extends BaseController {
@PostMapping(value = "/{fromFormat}:{toFormat}", produces = MediaType.APPLICATION_XML_VALUE)
public String convertInput(@PathVariable(value = "fromFormat") String fromFormat,
@PathVariable(value = "toFormat") String toFormat,
@RequestBody String body)
@RequestBody byte[] body)
throws IOException, QueryException, SBMLException,
InvalidInputDataExecption, InconsistentModelException, ConverterException {
return convertController.convert(fromFormat, toFormat, body);
......@@ -45,7 +45,7 @@ public class ConvertController extends BaseController {
public @ResponseBody ResponseEntity<byte[]> convertInputToImage(
@PathVariable(value = "fromFormat") String fromFormat,
@PathVariable(value = "toFormat") String toFormat,
@RequestBody String body)
@RequestBody byte[] body)
throws IOException, QueryException, SBMLException, InvalidInputDataExecption, ConverterException,
DrawingException {
ByteArrayOutputStream os = convertController.converToImage(fromFormat, toFormat, body);
......
......@@ -35,7 +35,7 @@ public class ConvertRestImpl extends BaseRestImpl {
private Logger logger = LogManager.getLogger(ConvertRestImpl.class);
public String convert(String fromFormat, String toFormat, String input)
public String convert(String fromFormat, String toFormat, byte[] input)
throws InvalidInputDataExecption, SBMLException, InconsistentModelException, IOException, ConverterException,
QueryException {
ConverterParams params = createConvertParams(input);
......@@ -57,7 +57,7 @@ public class ConvertRestImpl extends BaseRestImpl {
return IOUtils.toString(exporter.model2InputStream(model), StandardCharsets.UTF_8);
}
public ByteArrayOutputStream converToImage(String fromFormat, String toFormat, String input,
public ByteArrayOutputStream converToImage(String fromFormat, String toFormat, byte[] input,
Double targetWidth, Double targetHeight)
throws InvalidInputDataExecption, SBMLException, IOException, ConverterException, DrawingException,
QueryException {
......@@ -69,7 +69,7 @@ public class ConvertRestImpl extends BaseRestImpl {
return os;
}
public ByteArrayOutputStream converToImage(String fromFormat, String toFormat, String input)
public ByteArrayOutputStream converToImage(String fromFormat, String toFormat, byte[] input)
throws IOException, DrawingException, QueryException {
try {
return converToImage(fromFormat, toFormat, input, 0.0, 0.0);
......@@ -246,9 +246,9 @@ public class ConvertRestImpl extends BaseRestImpl {
}
private ConverterParams createConvertParams(String input) {
private ConverterParams createConvertParams(byte[] input) {
ConverterParams params = new ConverterParams();
InputStream is = new ByteArrayInputStream(input.getBytes());
InputStream is = new ByteArrayInputStream(input);
params.inputStream(is);
......
......@@ -73,7 +73,7 @@ public class ConvertRestImplTest extends RestTestFunctions {
@Test
public void testCelDesigner2Sbml1() throws Exception {
String content = readFile("testFiles/convert/sample-cd.xml");
byte[] content = readFile("testFiles/convert/sample-cd.xml").getBytes();
String result = convertRestImpl.convert(
"lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser",
"lcsb.mapviewer.converter.model.sbml.SbmlParser", content);
......@@ -84,16 +84,16 @@ public class ConvertRestImplTest extends RestTestFunctions {
@Test
public void testCelDesigner2Svg() throws Exception {
String content = readFile("testFiles/convert/sample-cd.xml");
String result = convertRestImpl.converToImage("CellDesigner_SBML", "svg", content).toString();
String result = convertRestImpl.converToImage("CellDesigner_SBML", "svg", content.getBytes()).toString();
assertTrue(result.contains("<rect"));
}
@Test
public void testCellDesigner2Sbml2Svg() throws Exception {
String content = readFile("testFiles/convert/neuron_cd.xml");
byte[] content = readFile("testFiles/convert/neuron_cd.xml").getBytes();
String resultSbml = convertRestImpl.convert("CellDesigner_SBML", "SBML", content).toString();
String resultSvg = convertRestImpl.converToImage("SBML", "svg", resultSbml).toString();
String resultSvg = convertRestImpl.converToImage("SBML", "svg", resultSbml.getBytes()).toString();
assertTrue(resultSvg.contains("<rect"));
}
......@@ -101,10 +101,10 @@ public class ConvertRestImplTest extends RestTestFunctions {
@Test
public void testCellDesigner2Sbml2CellDesignerSvg() throws Exception {
String content = readFile("testFiles/convert/neuron_cd.xml");
String resultSbml = convertRestImpl.convert("CellDesigner_SBML", "SBML", content).toString();
String resultCellDesignerSbml = convertRestImpl.convert("SBML", "CellDesigner_SBML", resultSbml)
String resultSbml = convertRestImpl.convert("CellDesigner_SBML", "SBML", content.getBytes()).toString();
String resultCellDesignerSbml = convertRestImpl.convert("SBML", "CellDesigner_SBML", resultSbml.getBytes())
.toString();
String resultSvg = convertRestImpl.converToImage("CellDesigner_SBML", "svg", resultCellDesignerSbml)
String resultSvg = convertRestImpl.converToImage("CellDesigner_SBML", "svg", resultCellDesignerSbml.getBytes())
.toString();
assertTrue(resultSvg.contains("<rect"));
......@@ -113,8 +113,8 @@ public class ConvertRestImplTest extends RestTestFunctions {
@Test
public void testScaling() throws Exception {
String content = readFile("testFiles/convert/sample-cd.xml");
String result1 = convertRestImpl.converToImage("CellDesigner_SBML", "svg", content, 50.0, 50.0).toString();
String result2 = convertRestImpl.converToImage("CellDesigner_SBML", "svg", content, 100.0, 100.0)
String result1 = convertRestImpl.converToImage("CellDesigner_SBML", "svg", content.getBytes(), 50.0, 50.0).toString();
String result2 = convertRestImpl.converToImage("CellDesigner_SBML", "svg", content.getBytes(), 100.0, 100.0)
.toString();
Pattern pattern = Pattern.compile(".*scale\\(([0-9]+\\.[0-9]+),([0-9]+\\.[0-9]+)\\).*");
......@@ -131,8 +131,8 @@ public class ConvertRestImplTest extends RestTestFunctions {
public void test1() throws Exception {
String content = readFile("testFiles/convert/glycolysis2.xml");
String result = convertRestImpl.convert("CellDesigner_SBML", "SBML", content);
ByteArrayOutputStream result1 = convertRestImpl.converToImage("SBML", "svg", result);
String result = convertRestImpl.convert("CellDesigner_SBML", "SBML", content.getBytes());
ByteArrayOutputStream result1 = convertRestImpl.converToImage("SBML", "svg", result.getBytes());
File output = new File("testFiles/convert/glycolysis2.svg");
......@@ -147,8 +147,8 @@ public class ConvertRestImplTest extends RestTestFunctions {
public void test2() throws Exception {
String content = readFile("testFiles/convert/glycolysis2.xml");
String result = convertRestImpl.convert("CellDesigner_SBML", "SBML", content);
String result1 = convertRestImpl.convert("SBML", "CellDesigner_SBML", result);
String result = convertRestImpl.convert("CellDesigner_SBML", "SBML", content.getBytes());
String result1 = convertRestImpl.convert("SBML", "CellDesigner_SBML", result.getBytes());
assertNotNull(result);
assertNotNull(result1);
......@@ -157,7 +157,7 @@ public class ConvertRestImplTest extends RestTestFunctions {
@Test
public void testCelDesigner2Sbgn() throws Exception {
String content = readFile("testFiles/convert/sample-cd.xml");
String result = convertRestImpl.convert("CellDesigner_SBML", "SBGN-ML", content).toString();
String result = convertRestImpl.convert("CellDesigner_SBML", "SBGN-ML", content.getBytes()).toString();
assertTrue(result.contains("glyph class=\"complex\""));
}
......@@ -181,14 +181,14 @@ public class ConvertRestImplTest extends RestTestFunctions {
targets.addAll(extractIdsFromOutputs(info));
for (String target : targets) {
String result = convertRestImpl.convert(converter, target, content).toString();
String result = convertRestImpl.convert(converter, target, content.getBytes()).toString();
assertTrue(result.length() > 0);
}
targets.clear();
targets.addAll(extractIdsFromOutputs(infoImage));
for (String target : targets) {
String result = convertRestImpl.converToImage(converter, target, content).toString();
String result = convertRestImpl.converToImage(converter, target, content.getBytes()).toString();
assertTrue(result.length() > 0);
}
}
......
......@@ -4,10 +4,11 @@ import static org.junit.Assert.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.*;
import java.nio.file.Files;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.http.MediaType;
......@@ -22,6 +23,8 @@ import lcsb.mapviewer.model.map.species.Element;
@RunWith(SpringJUnit4ClassRunner.class)
public class ConvertControllerIntegrationTest extends ControllerIntegrationTest {
Logger logger = LogManager.getLogger();
@Test
public void testConvertInvalidFile() throws Exception {
String body = "invalid content";
......@@ -33,6 +36,23 @@ public class ConvertControllerIntegrationTest extends ControllerIntegrationTest
.andExpect(status().isBadRequest());
}
@Test
public void convertWithBOM() throws Exception {
FileReader fr = new FileReader(new File("src/test/resources/SBGN_with_BOM.sbgn"));
BufferedReader br = new BufferedReader(fr);
StringBuilder tmp = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
tmp.append(line + System.getProperty("line.separator"));
}
RequestBuilder request = post("/convert/image/SBGN-ML:svg")
.content(tmp.toString().getBytes("UTF-8")).characterEncoding("UTF-8");
br.close();
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
}
@Test
public void testConvertInvalidMapFormat() throws Exception {
String body = "invalid content";
......
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<sbgn xmlns="http://sbgn.org/libsbgn/0.2">
<map language="process description">
<glyph id="nwtN_74c3dbfb-02b1-4e28-9d43-0cae011acf2a" class="simple chemical">
<label text="el2"/>
<bbox x="866.8349084372152" y="296.1973717584831" w="136.82486912403263" h="73.70108282346791"/>
</glyph>
<glyph id="nwtN_dea3dbde-02e4-40f9-8c27-963282d20de2" class="process">
<bbox x="1126.3443211534611" y="311.68061284687263" w="34.22866874880496" h="34.22866874880496"/>
<port id="nwtN_dea3dbde-02e4-40f9-8c27-963282d20de2.1" x="1119.4985874037002" y="328.7949472212751"/>
<port id="nwtN_dea3dbde-02e4-40f9-8c27-963282d20de2.2" x="1167.418723652027" y="328.7949472212751"/>
</glyph>
<glyph id="nwtN_ffaa36d2-067e-4eaa-81b0-8bf83d7e8e81" class="macromolecule">
<label text="el1"/>
<bbox x="1335.0238493448692" y="304.694418205774" w="117.05419146397195" h="78.55675869274216"/>
</glyph>
<glyph id="nwtN_c9c80149-ba98-44fe-a40c-e2ebb098d21a" class="omitted process">
<bbox x="1132.2447485580458" y="207.098961267922" w="39.43117860874146" h="39.43117860874146"/>
<port id="nwtN_c9c80149-ba98-44fe-a40c-e2ebb098d21a.1" x="1124.3585128362975" y="226.81455057229272"/>
<port id="nwtN_c9c80149-ba98-44fe-a40c-e2ebb098d21a.2" x="1179.5621628885356" y="226.81455057229272"/>
</glyph>
<arc id="nwtE_bce73d75-967b-4473-9028-bfc10d8af4eb" class="consumption" source="nwtN_74c3dbfb-02b1-4e28-9d43-0cae011acf2a" target="nwtN_dea3dbde-02e4-40f9-8c27-963282d20de2.1">
<start x="1004.2359525482459" y="331.6387380215975"/>
<end x="1118.8735874037002" y="328.7949472212751"/>
</arc>
<arc id="nwtE_d0911b94-b9b8-4115-b475-4d43894de402" class="production" source="nwtN_dea3dbde-02e4-40f9-8c27-963282d20de2.2" target="nwtN_ffaa36d2-067e-4eaa-81b0-8bf83d7e8e81">
<start x="1168.043723652027" y="328.7949472212751"/>
<end x="1331.2795884250613" y="340.1936113450629"/>
</arc>
</map>
</sbgn>
\ No newline at end of file
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