Skip to content
Snippets Groups Projects
Commit 02b19ddb authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

refactored rest-api module to use new converter class

parent 4207a3d5
No related branches found
No related tags found
1 merge request!644Refactored IConverter and XmlParser across project
...@@ -222,7 +222,7 @@ final public class XmlParser { ...@@ -222,7 +222,7 @@ final public class XmlParser {
* @throws InvalidXmlSchemaException * @throws InvalidXmlSchemaException
* thrown when there is a problem with xml * thrown when there is a problem with xml
*/ */
private static Document getXmlDocumentFromString(final String text, boolean validate) throws InvalidXmlSchemaException { public static Document getXmlDocumentFromString(final String text, boolean validate) throws InvalidXmlSchemaException {
InputSource is = new InputSource(); InputSource is = new InputSource();
is.setCharacterStream(new StringReader(text)); is.setCharacterStream(new StringReader(text));
try { try {
......
...@@ -31,14 +31,11 @@ import lcsb.mapviewer.annotation.services.MiriamConnector; ...@@ -31,14 +31,11 @@ import lcsb.mapviewer.annotation.services.MiriamConnector;
import lcsb.mapviewer.annotation.services.PubmedParser; import lcsb.mapviewer.annotation.services.PubmedParser;
import lcsb.mapviewer.annotation.services.PubmedSearchException; import lcsb.mapviewer.annotation.services.PubmedSearchException;
import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator; import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.comparator.StringComparator; import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.IConverter; import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.ImageGenerators;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.converter.model.sbgnml.SbgnmlXmlConverter; import lcsb.mapviewer.converter.model.sbgnml.SbgnmlXmlConverter;
import lcsb.mapviewer.converter.model.sbml.SbmlParser; import lcsb.mapviewer.converter.model.sbml.SbmlParser;
...@@ -322,8 +319,8 @@ public abstract class BaseRestImpl { ...@@ -322,8 +319,8 @@ public abstract class BaseRestImpl {
this.projectService = projectService; this.projectService = projectService;
} }
protected IConverter getModelParser(String handlerClass) throws QueryException { protected Converter getModelParser(String handlerClass) throws QueryException {
for (IConverter converter : getModelConverters()) { for (Converter converter : getModelConverters()) {
if (converter.getClass().getCanonicalName().equals(handlerClass)) { if (converter.getClass().getCanonicalName().equals(handlerClass)) {
return converter; return converter;
} }
...@@ -331,8 +328,8 @@ public abstract class BaseRestImpl { ...@@ -331,8 +328,8 @@ public abstract class BaseRestImpl {
throw new QueryException("Unknown handlerClass: " + handlerClass); throw new QueryException("Unknown handlerClass: " + handlerClass);
} }
protected List<IConverter> getModelConverters() { protected List<Converter> getModelConverters() {
List<IConverter> result = new ArrayList<>(); List<Converter> result = new ArrayList<>();
result.add(new CellDesignerXmlParser()); result.add(new CellDesignerXmlParser());
result.add(new SbgnmlXmlConverter()); result.add(new SbgnmlXmlConverter());
result.add(new SbmlParser()); result.add(new SbmlParser());
......
...@@ -20,7 +20,7 @@ import lcsb.mapviewer.api.BaseRestImpl; ...@@ -20,7 +20,7 @@ import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.QueryException; import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.IConverter; import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator; import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.ImageGenerators; import lcsb.mapviewer.converter.graphics.ImageGenerators;
import lcsb.mapviewer.model.graphics.MapCanvasType; import lcsb.mapviewer.model.graphics.MapCanvasType;
...@@ -117,11 +117,11 @@ public class ConfigurationRestImpl extends BaseRestImpl { ...@@ -117,11 +117,11 @@ public class ConfigurationRestImpl extends BaseRestImpl {
public List<Map<String, Object>> getModelFormats(String token) throws SecurityException { public List<Map<String, Object>> getModelFormats(String token) throws SecurityException {
verifyToken(token); verifyToken(token);
List<IConverter> converters = getModelConverters(); List<Converter> converters = getModelConverters();
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
for (IConverter converter : converters) { for (Converter converter : converters) {
Map<String, Object> row = new TreeMap<>(); Map<String, Object> row = new TreeMap<>();
row.put("name", converter.getCommonName()); row.put("name", converter.getCommonName());
row.put("handler", converter.getClass().getCanonicalName()); row.put("handler", converter.getClass().getCanonicalName());
......
...@@ -24,7 +24,7 @@ import lcsb.mapviewer.api.QueryException; ...@@ -24,7 +24,7 @@ import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.converter.ConverterException; import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.IConverter; import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.InvalidInputDataExecption; import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator; import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.DrawingException; import lcsb.mapviewer.converter.graphics.DrawingException;
...@@ -49,8 +49,8 @@ public class ConvertRestImpl extends BaseRestImpl { ...@@ -49,8 +49,8 @@ public class ConvertRestImpl extends BaseRestImpl {
ConverterParams params = createConvertParams(input); ConverterParams params = createConvertParams(input);
Model model = getModelParserByNameOrClass(fromFormat).createModel(params); Model model = getModelParserByNameOrClass(fromFormat).createModel(params);
IConverter exporter = getModelParserByNameOrClass(toFormat); Converter exporter = getModelParserByNameOrClass(toFormat);
return IOUtils.toString(exporter.exportModelToInputStream(model)); return IOUtils.toString(exporter.model2InputStream(model));
} }
public ByteArrayOutputStream converToImage(String token, String fromFormat, String toFormat, String input, public ByteArrayOutputStream converToImage(String token, String fromFormat, String toFormat, String input,
...@@ -82,7 +82,7 @@ public class ConvertRestImpl extends BaseRestImpl { ...@@ -82,7 +82,7 @@ public class ConvertRestImpl extends BaseRestImpl {
List<Object> converters = new ArrayList<>(); List<Object> converters = new ArrayList<>();
for (IConverter converter: getModelConverters()) { for (Converter converter: getModelConverters()) {
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
names.add(removeWhiteSpaces(converter.getCommonName())); names.add(removeWhiteSpaces(converter.getCommonName()));
...@@ -119,7 +119,7 @@ public class ConvertRestImpl extends BaseRestImpl { ...@@ -119,7 +119,7 @@ public class ConvertRestImpl extends BaseRestImpl {
return info; return info;
} }
private IConverter getModelParserByNameOrClass(String id) throws QueryException { private Converter getModelParserByNameOrClass(String id) throws QueryException {
try { try {
return getModelParserByName(id); return getModelParserByName(id);
} catch (QueryException e) { } catch (QueryException e) {
...@@ -131,8 +131,8 @@ public class ConvertRestImpl extends BaseRestImpl { ...@@ -131,8 +131,8 @@ public class ConvertRestImpl extends BaseRestImpl {
return str.replace(' ', '_'); return str.replace(' ', '_');
} }
private IConverter getModelParserByName(String name) throws QueryException { private Converter getModelParserByName(String name) throws QueryException {
for (IConverter converter : getModelConverters()) { for (Converter converter : getModelConverters()) {
if (removeWhiteSpaces(converter.getCommonName()).equals(name)) { if (removeWhiteSpaces(converter.getCommonName()).equals(name)) {
return converter; return converter;
} }
......
package lcsb.mapviewer.api.projects; package lcsb.mapviewer.api.projects;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.security.MessageDigest; import java.security.MessageDigest;
...@@ -16,7 +15,6 @@ import java.util.Set; ...@@ -16,7 +15,6 @@ import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
...@@ -31,7 +29,7 @@ import lcsb.mapviewer.api.QueryException; ...@@ -31,7 +29,7 @@ import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.api.projects.models.publications.PublicationsRestImpl; import lcsb.mapviewer.api.projects.models.publications.PublicationsRestImpl;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.IConverter; import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.zip.ImageZipEntryFile; import lcsb.mapviewer.converter.zip.ImageZipEntryFile;
import lcsb.mapviewer.converter.zip.LayoutZipEntryFile; import lcsb.mapviewer.converter.zip.LayoutZipEntryFile;
import lcsb.mapviewer.converter.zip.ModelZipEntryFile; import lcsb.mapviewer.converter.zip.ModelZipEntryFile;
...@@ -379,7 +377,7 @@ public class ProjectRestImpl extends BaseRestImpl { ...@@ -379,7 +377,7 @@ public class ProjectRestImpl extends BaseRestImpl {
if (parserClass == null) { if (parserClass == null) {
throw new QueryException("parser is obligatory"); throw new QueryException("parser is obligatory");
} }
IConverter parser = getModelParser(parserClass); Converter parser = getModelParser(parserClass);
List<ZipEntryFile> zipEntries = extractZipEntries(data); List<ZipEntryFile> zipEntries = extractZipEntries(data);
params.complex(zipEntries.size() > 0); params.complex(zipEntries.size() > 0);
......
...@@ -244,7 +244,7 @@ public class ModelRestImpl extends BaseRestImpl { ...@@ -244,7 +244,7 @@ public class ModelRestImpl extends BaseRestImpl {
} }
Converter parser = getModelParser(handlerClass); Converter parser = getModelParser(handlerClass);
InputStream is = parser.exportModelToInputStream(part); InputStream is = parser.model2InputStream(part);
String fileExtension = parser.getFileExtension(); String fileExtension = parser.getFileExtension();
......
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