Skip to content
Snippets Groups Projects
Commit 3b904984 authored by David Hoksza's avatar David Hoksza
Browse files

Ability to call converters by common name with space replaced by underscores

parent 869a8f79
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",!418Formats conversion rest api
Pipeline #6462 failed
......@@ -322,6 +322,19 @@ public abstract class BaseRestImpl {
this.projectService = projectService;
}
private String removeWhiteSpaces(String str) {
return str.replace(' ', '_');
}
protected IConverter getModelParserByName(String name) throws QueryException {
for (IConverter converter : getModelConverters()) {
if (removeWhiteSpaces(converter.getCommonName()).equals(name)) {
return converter;
}
}
throw new QueryException("Unknown parser name: " + name);
}
protected IConverter getModelParser(String handlerClass) throws QueryException {
for (IConverter converter : getModelConverters()) {
if (converter.getClass().getCanonicalName().equals(handlerClass)) {
......
......@@ -41,9 +41,9 @@ public class ConvertRestImpl extends BaseRestImpl {
XMLStreamException, DrawingException, QueryException
{
ConverterParams params = createConvertParams(input);
Model model = getModelParser(fromFormat).createModel(params);
Model model = getModelParserByNameOrClass(fromFormat).createModel(params);
IConverter exporter = getModelParser(toFormat);
IConverter exporter = getModelParserByNameOrClass(toFormat);
return IOUtils.toString(exporter.exportModelToInputStream(model));
}
......@@ -53,7 +53,7 @@ public class ConvertRestImpl extends BaseRestImpl {
ConverterException,XMLStreamException, DrawingException,
QueryException
{
Model model = getModelParser(fromFormat).createModel(createConvertParams(input));
Model model = getModelParserByNameOrClass(fromFormat).createModel(createConvertParams(input));
AbstractImageGenerator generator = getImageGenerator(toFormat, createImageParams(model));
ByteArrayOutputStream os = new ByteArrayOutputStream();
......@@ -61,6 +61,14 @@ public class ConvertRestImpl extends BaseRestImpl {
return os;
}
private IConverter getModelParserByNameOrClass(String id) throws QueryException {
try {
return getModelParserByName(id);
} catch (QueryException e) {
return getModelParser(id);
}
}
private AbstractImageGenerator getImageGenerator(String extension, AbstractImageGenerator.Params params) throws QueryException{
for (Pair<String, Class<? extends AbstractImageGenerator>> element : new ImageGenerators().getAvailableImageGenerators()) {
......
......@@ -51,6 +51,21 @@ public class ConvertRestImplTest extends RestTestFunctions {
}
}
@Test
public void testCelDesigner2Sbml_2() throws Exception {
try {
File file = new File("testFiles/convert/sample-cd.xml");
String content = FileUtils.readFileToString(file);
String result = convertRestImpl.convert(token, "CellDesigner_SBML",
"SBGN-ML", content);
System.out.print(result);
assertTrue(result.length() > 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCelDesigner2Svg() throws Exception {
try {
......
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