Commit cc12f34d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

converter returns structured objects with serialization

parent ab944af9
......@@ -2,6 +2,7 @@ package lcsb.mapviewer.annotation.services.dapi;
import java.util.List;
import lcsb.mapviewer.annotation.services.dapi.dto.DapiDatabase;
import lcsb.mapviewer.annotation.services.dapi.dto.ReleaseDto;
import lcsb.mapviewer.annotation.services.dapi.dto.UserDto;
......@@ -20,7 +21,7 @@ public interface DapiConnector {
void resetConnection();
List<String> getDatabases() throws DapiConnectionException;
List<DapiDatabase> getDatabases() throws DapiConnectionException;
List<ReleaseDto> getReleases(String database) throws DapiConnectionException;
......
......@@ -32,6 +32,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
import lcsb.mapviewer.annotation.cache.CachableInterface;
import lcsb.mapviewer.annotation.services.dapi.dto.DapiDatabase;
import lcsb.mapviewer.annotation.services.dapi.dto.ListReleaseDto;
import lcsb.mapviewer.annotation.services.dapi.dto.ReleaseDto;
import lcsb.mapviewer.annotation.services.dapi.dto.UserDto;
......@@ -237,9 +238,9 @@ public class DapiConnectorImpl extends CachableInterface implements DapiConnecto
}
@Override
public List<String> getDatabases() throws DapiConnectionException {
public List<DapiDatabase> getDatabases() throws DapiConnectionException {
try {
List<String> result = new ArrayList<>();
List<DapiDatabase> result = new ArrayList<>();
String url = DAPI_BASE_URL + "database/";
String content = getWebPageDownloader().getFromNetwork(url);
JsonArray array = new JsonParser()
......@@ -249,7 +250,7 @@ public class DapiConnectorImpl extends CachableInterface implements DapiConnecto
.getAsJsonArray();
for (int i = 0; i < array.size(); i++) {
result.add(array.get(i).getAsJsonObject().get("name").getAsString());
result.add(new DapiDatabase(array.get(i).getAsJsonObject().get("name").getAsString()));
}
return result;
} catch (Exception e) {
......
package lcsb.mapviewer.annotation.services.dapi.dto;
public class DapiDatabase {
public String name;
public DapiDatabase(String name) {
this.name = name;
}
}
......@@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
import lcsb.mapviewer.annotation.services.ModelAnnotator;
import lcsb.mapviewer.annotation.services.dapi.DapiConnectionException;
import lcsb.mapviewer.annotation.services.dapi.DapiConnector;
import lcsb.mapviewer.annotation.services.dapi.dto.DapiDatabase;
import lcsb.mapviewer.annotation.services.dapi.dto.ReleaseDto;
import lcsb.mapviewer.annotation.services.dapi.dto.UserDto;
import lcsb.mapviewer.api.BaseController;
......@@ -143,18 +144,13 @@ public class ConfigurationController extends BaseController {
}
@GetMapping(value = "/dapi/database/")
public List<Map<String, Object>> getDapiDatabases() {
List<Map<String, Object>> result = new ArrayList<>();
public List<DapiDatabase> getDapiDatabases() {
try {
for (String string : dapiConnector.getDatabases()) {
Map<String, Object> entry = new HashMap<>();
entry.put("name", string);
result.add(entry);
}
return dapiConnector.getDatabases();
} catch (DapiConnectionException e) {
logger.error("Problem with dapi", e);
}
return result;
return new ArrayList<>();
}
@GetMapping(value = "/dapi/database/{database}/release/")
......
package lcsb.mapviewer.api.convert;
import java.io.IOException;
import java.util.Arrays;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.ImageGenerators;
public class AbstractImageGeneratorSerializer extends JsonSerializer<Class<? extends AbstractImageGenerator>> {
private static final ImageGenerators imageGenerators = new ImageGenerators();
@Override
public void serialize(final Class<? extends AbstractImageGenerator> clazz, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeObjectField("available_names", Arrays.asList(imageGenerators.getExtension(clazz), clazz.getCanonicalName()));
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.api.convert;
import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
......@@ -15,7 +20,13 @@ import org.sbml.jsbml.SBMLException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.commands.CreateHierarchyCommand;
......@@ -23,9 +34,13 @@ import lcsb.mapviewer.commands.MergeCommand;
import lcsb.mapviewer.common.MinervaLoggerAppender;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.converter.*;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.graphics.*;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.DrawingException;
import lcsb.mapviewer.converter.graphics.ImageGenerators;
import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.layout.graphics.Layer;
import lcsb.mapviewer.model.map.model.Model;
......@@ -218,46 +233,26 @@ public class ConvertController extends BaseController {
}
@RequestMapping(value = "/", method = { RequestMethod.GET, RequestMethod.POST })
public Map<String, List<Map<String, List<String>>>> getInformation() {
Map<String, List<Map<String, List<String>>>> info = new LinkedHashMap<>();
List<Map<String, List<String>>> converters = new ArrayList<>();
for (Converter converter : modelConverters) {
List<String> names = new ArrayList<>();
names.add(removeWhiteSpaces(converter.getCommonName()));
names.add(converter.getClass().getCanonicalName());
Map<String, List<String>> names_item = new LinkedHashMap<>();
names_item.put("available_names", names);
converters.add(names_item);
}
info.put("inputs", converters);
info.put("outputs", converters);
return info;
public ConverterInformation getInformation() {
ConverterInformation result = new ConverterInformation();
result.inputs = modelConverters;
result.outputs = modelConverters;
return result;
}
@RequestMapping(value = "/image/", method = { RequestMethod.GET, RequestMethod.POST })
public Map<String, ?> getInformationImage() {
Map<String, List<Map<String, List<String>>>> info = getInformation();
public GraphicsConverterInformation getInformationImage() {
GraphicsConverterInformation result = new GraphicsConverterInformation();
result.inputs = modelConverters;
result.outputs = new ArrayList<>();
List<Map<String, List<String>>> generators = new ArrayList<>();
ImageGenerators igs = new ImageGenerators();
for (Pair<String, Class<? extends AbstractImageGenerator>> generator : igs.getAvailableImageGenerators()) {
List<String> names = new ArrayList<>();
names.add(igs.getExtension(generator.getRight()));
names.add(generator.getRight().getCanonicalName());
Map<String, List<String>> names_item = new LinkedHashMap<>();
names_item.put("available_names", names);
generators.add(names_item);
result.outputs.add(generator.getRight());
}
info.remove("outputs");
info.put("outputs", generators);
return info;
return result;
}
private ConverterParams createConvertParams(byte[] input) {
......
package lcsb.mapviewer.api.convert;
import java.util.List;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.converter.Converter;
public class ConverterInformation {
@JsonSerialize(contentUsing = ConverterSerializer.class)
public List<Converter> inputs;
@JsonSerialize(contentUsing = ConverterSerializer.class)
public List<Converter> outputs;
}
package lcsb.mapviewer.api.convert;
import java.io.IOException;
import java.util.Arrays;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lcsb.mapviewer.converter.Converter;
public class ConverterSerializer extends JsonSerializer<Converter> {
@Override
public void serialize(final Converter converter, final JsonGenerator gen, final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeObjectField("available_names",
Arrays.asList(converter.getCommonName().replace(' ', '_'), converter.getClass().getCanonicalName()));
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.api.convert;
import java.util.List;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
public class GraphicsConverterInformation {
@JsonSerialize(contentUsing = ConverterSerializer.class)
public List<Converter> inputs;
@JsonSerialize(contentUsing = AbstractImageGeneratorSerializer.class)
public List<Class<? extends AbstractImageGenerator>> outputs;
}
Markdown is supported
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