Commit 19686b15 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

ReferenceGenomeGeneMappingSerializer implemented

parent f6abcd6f
package lcsb.mapviewer.modelutils.serializer.model.map.layout;
import java.io.IOException;
import java.util.function.Function;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping;
public class ReferenceGenomeGeneMappingSerializer extends JsonSerializer<ReferenceGenomeGeneMapping> {
private Function<String, String> getLocalUrl;
public ReferenceGenomeGeneMappingSerializer(Function<String, String> getLocalUrl) {
this.getLocalUrl = getLocalUrl;
}
@Override
public void serialize(final ReferenceGenomeGeneMapping mapping, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeNumberField("downloadProgress", mapping.getDownloadProgress());
gen.writeStringField("localUrl", getLocalUrl.apply(mapping.getSourceUrl()));
gen.writeStringField("sourceUrl", mapping.getSourceUrl());
gen.writeStringField("name", mapping.getName());
gen.writeNumberField("idObject", mapping.getId());
gen.writeEndObject();
}
}
\ No newline at end of file
......@@ -84,7 +84,7 @@ public class ReferenceGenomeController extends BaseController {
result.put("sourceUrl", genome.getSourceUrl());
result.put("localUrl", getLocalUrl(genome.getSourceUrl()));
result.put("idObject", genome.getId());
result.put("geneMapping", geneMappingToMaps(genome.getGeneMapping()));
result.put("geneMapping", genome.getGeneMapping());
return result;
}
......@@ -99,25 +99,6 @@ public class ReferenceGenomeController extends BaseController {
return url;
}
private List<Map<String, Object>> geneMappingToMaps(List<ReferenceGenomeGeneMapping> geneMapping) {
List<Map<String, Object>> result = new ArrayList<>();
for (ReferenceGenomeGeneMapping referenceGenomeGeneMapping : geneMapping) {
result.add(geneMappingToMap(referenceGenomeGeneMapping));
}
return result;
}
private Map<String, Object> geneMappingToMap(ReferenceGenomeGeneMapping mapping) {
Map<String, Object> result = new TreeMap<>();
result.put("downloadProgress", mapping.getDownloadProgress());
result.put("localUrl", getLocalUrl(mapping.getSourceUrl()));
result.put("sourceUrl", mapping.getSourceUrl());
result.put("name", mapping.getName());
result.put("idObject", mapping.getId());
return result;
}
static class RemoteUrl {
public String url;
}
......
package lcsb.mapviewer.web.config;
import java.awt.Color;
import java.io.FileNotFoundException;
import java.util.Calendar;
import java.util.List;
import java.util.function.Function;
......@@ -36,13 +37,16 @@ import lcsb.mapviewer.api.SpringRestApiConfig;
import lcsb.mapviewer.model.Article;
import lcsb.mapviewer.model.map.Comment;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.modelutils.serializer.CalendarSerializer;
import lcsb.mapviewer.modelutils.serializer.ColorSerializer;
import lcsb.mapviewer.modelutils.serializer.model.map.CommentSerializer;
import lcsb.mapviewer.modelutils.serializer.model.map.MiriamDataSerializer;
import lcsb.mapviewer.modelutils.serializer.model.map.layout.ReferenceGenomeGeneMappingSerializer;
import lcsb.mapviewer.services.interfaces.IElementService;
import lcsb.mapviewer.services.interfaces.IFileService;
import lcsb.mapviewer.services.interfaces.IMeshService;
import lcsb.mapviewer.services.interfaces.IMiriamService;
import lcsb.mapviewer.services.interfaces.IReactionService;
......@@ -61,15 +65,17 @@ public class SpringWebConfig implements WebMvcConfigurer {
private IMeshService meshService;
private IElementService elementService;
private IReactionService reactionService;
private IFileService fileService;
@Autowired
public SpringWebConfig(List<HandlerInterceptor> interceptors, IMiriamService miriamConnector, IMeshService meshService,
IElementService elementService, IReactionService reactionService) {
IElementService elementService, IReactionService reactionService, IFileService fileService) {
this.interceptors = interceptors;
this.miriamService = miriamConnector;
this.meshService = meshService;
this.elementService = elementService;
this.reactionService = reactionService;
this.fileService = fileService;
}
@Override
......@@ -129,6 +135,20 @@ public class SpringWebConfig implements WebMvcConfigurer {
}
}));
module.addSerializer(ReferenceGenomeGeneMapping.class, new ReferenceGenomeGeneMappingSerializer(
new Function<String, String>() {
@Override
public String apply(String sourceUrl) {
String url = null;
try {
url = "../" + fileService.getLocalPathForFile(sourceUrl);
} catch (FileNotFoundException e) {
logger.warn("Cannot find local file", e);
}
return url;
}
}));
m.getObjectMapper().registerModule(module);
}
}
......
......@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.RequestBuilder;
......@@ -244,6 +245,11 @@ public class GenomicsControllerIntegrationTest extends ControllerIntegrationTest
genome.setDownloadProgress(100.0);
genome.setType(ReferenceGenomeType.UCSC);
genome.setVersion("eboVir3");
ReferenceGenomeGeneMapping mapping = new ReferenceGenomeGeneMapping();
mapping.setName("xy");
mapping.setSourceUrl("https://minerva-dev.lcsb.uni.lu/tmp/refGene.bb");
genome.addReferenceGenomeGeneMapping(mapping);
return callInSeparateThread(() -> {
referenceGenomeDao.add(genome);
return genome;
......@@ -296,22 +302,36 @@ public class GenomicsControllerIntegrationTest extends ControllerIntegrationTest
.type("double"),
fieldWithPath("geneMapping")
.description("list of available gene mappings for given genome")
.type("array"),
.type(JsonFieldType.ARRAY),
fieldWithPath("geneMapping[].name")
.description("name of the gene mapping")
.type(JsonFieldType.STRING),
fieldWithPath("geneMapping[].sourceUrl")
.description("source url of the gene mapping")
.type(JsonFieldType.STRING),
fieldWithPath("geneMapping[].localUrl")
.description("url with local copy of the mapping")
.type(JsonFieldType.STRING),
fieldWithPath("geneMapping[].downloadProgress")
.description("download progress")
.type(JsonFieldType.NUMBER),
fieldWithPath("geneMapping[].idObject")
.ignored(),
fieldWithPath("idObject")
.description("unique id of genome in minerva")
.type("number"),
.type(JsonFieldType.NUMBER),
fieldWithPath("localUrl")
.description("url on minerva where local copy of genome can be accessed")
.type("string"),
.type(JsonFieldType.STRING),
fieldWithPath("organism")
.description("organism identifier")
.type("object"),
.type(JsonFieldType.OBJECT),
fieldWithPath("organism.resource")
.description("organism identifier")
.type("string"),
.type(JsonFieldType.STRING),
fieldWithPath("organism.type")
.description("organism identifier type (usually " + MiriamType.TAXONOMY + ")")
.type("string"),
.type(JsonFieldType.STRING),
fieldWithPath("organism.annotatorClassName")
.ignored(),
fieldWithPath("organism.id")
......@@ -320,13 +340,13 @@ public class GenomicsControllerIntegrationTest extends ControllerIntegrationTest
.ignored(),
fieldWithPath("sourceUrl")
.description("genome source url")
.type("string"),
.type(JsonFieldType.STRING),
fieldWithPath("type")
.description("type of genome (database from which it was downloaded)")
.type("string"),
.type(JsonFieldType.STRING),
fieldWithPath("version")
.description("genome version")
.type("string"));
.type(JsonFieldType.STRING));
}
@Test
......
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