Commit 1f1faeb6 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

gene mapping should contain file so serializer does not need to call service

parent a977ccba
Pipeline #52373 failed with stage
in 62 minutes and 19 seconds
......@@ -751,7 +751,7 @@ public class UcscReferenceGenomeConnector extends CachableInterface implements R
mapping.setSourceUrl(url);
referenceGenome.addReferenceGenomeGeneMapping(mapping);
self.update(referenceGenome);
getBigFileCache().downloadFile(url, new IProgressUpdater() {
BigFileEntry entry = getBigFileCache().downloadFile(url, new IProgressUpdater() {
@Override
public void setProgress(final double progress) {
if (updater != null) {
......@@ -765,6 +765,7 @@ public class UcscReferenceGenomeConnector extends CachableInterface implements R
});
ReferenceGenomeGeneMapping temp = self.getReferenceGenomeGeneMappingById(mapping.getId());
temp.setDownloadProgress(100.0);
temp.setFile(entry);
self.update(temp);
return null;
} catch (final Exception e) {
......
......@@ -10,6 +10,11 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.model.cache.BigFileEntry;
import lcsb.mapviewer.modelutils.serializer.model.map.layout.ReferenceGenomeGeneMappingSerializer;
/**
* This object defines information about mapping genes to gene. This data is
* stored in external file (from some database, server, etc.). For now this file
......@@ -21,6 +26,7 @@ import javax.persistence.ManyToOne;
*
*/
@Entity
@JsonSerialize(using = ReferenceGenomeGeneMappingSerializer.class)
public class ReferenceGenomeGeneMapping implements Serializable {
/**
*
......@@ -35,11 +41,15 @@ public class ReferenceGenomeGeneMapping implements Serializable {
private int id;
/**
* {@link ReferenceGenome Reference genome} for which gene mapping is provided.
* {@link ReferenceGenome Reference genome} for which gene mapping is
* provided.
*/
@ManyToOne(fetch = FetchType.LAZY, optional = false)
private ReferenceGenome referenceGenome;
@ManyToOne(optional = true)
private BigFileEntry file;
/**
* Name of the mapping.
*/
......@@ -141,4 +151,13 @@ public class ReferenceGenomeGeneMapping implements Serializable {
public void setDownloadProgress(final double downloadProgress) {
this.downloadProgress = downloadProgress;
}
public BigFileEntry getFile() {
return file;
}
public void setFile(final BigFileEntry file) {
this.file = file;
}
}
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;
......@@ -10,20 +9,17 @@ 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(final 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()));
String localUrl = mapping.getSourceUrl();
if (mapping.getFile() != null && mapping.getFile().getDownloadProgress() >= 100) {
localUrl = "../" + mapping.getFile().getLocalPath();
}
gen.writeStringField("localUrl", localUrl);
gen.writeStringField("sourceUrl", mapping.getSourceUrl());
gen.writeStringField("name", mapping.getName());
gen.writeNumberField("idObject", mapping.getId());
......
......@@ -8,3 +8,16 @@ update reference_genome_table set file_id =
select id from file_entry_table where
file_entry_table.url=reference_genome_table.source_url and
file_entry_table.download_progress>90;
alter table reference_genome_gene_mapping_table add column file_id integer;
ALTER TABLE reference_genome_gene_mapping_table
ADD CONSTRAINT reference_genome_gene_mapping_table_file_fk FOREIGN KEY (file_id) REFERENCES public.file_entry_table(id)
ON DELETE SET NULL;
update reference_genome_gene_mapping_table set file_id =
select id from file_entry_table where
file_entry_table.url=reference_genome_gene_mapping_table.source_url and
file_entry_table.download_progress>90;
\ No newline at end of file
alter table reference_genome_table add column file_id integer;
ALTER TABLE reference_genome_table
ADD CONSTRAINT reference_genome_table_file_fk FOREIGN KEY (file_id) REFERENCES public.file_entry_table(id)
ON DELETE SET NULL;
update reference_genome_table set file_id =
select id from file_entry_table where
file_entry_table.url=reference_genome_table.source_url and
file_entry_table.download_progress>90;
alter table reference_genome_gene_mapping_table add column file_id integer;
ALTER TABLE reference_genome_gene_mapping_table
ADD CONSTRAINT reference_genome_gene_mapping_table_file_fk FOREIGN KEY (file_id) REFERENCES public.file_entry_table(id)
ON DELETE SET NULL;
update reference_genome_gene_mapping_table set file_id =
select id from file_entry_table where
file_entry_table.url=reference_genome_gene_mapping_table.source_url and
file_entry_table.download_progress>90;
\ No newline at end of file
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;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
......@@ -30,11 +26,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import lcsb.mapviewer.api.SpringRestApiConfig;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping;
import lcsb.mapviewer.modelutils.serializer.CalendarSerializer;
import lcsb.mapviewer.modelutils.serializer.ColorSerializer;
import lcsb.mapviewer.modelutils.serializer.model.map.layout.ReferenceGenomeGeneMappingSerializer;
import lcsb.mapviewer.services.interfaces.IFileService;
@Configuration
@EnableWebMvc
......@@ -43,16 +36,11 @@ import lcsb.mapviewer.services.interfaces.IFileService;
@ComponentScan(basePackages = { "lcsb.mapviewer.web" })
public class SpringWebConfig implements WebMvcConfigurer {
private static final Logger logger = LogManager.getLogger();
private List<HandlerInterceptor> interceptors;
private IFileService fileService;
@Autowired
public SpringWebConfig(final List<HandlerInterceptor> interceptors, final IFileService fileService) {
public SpringWebConfig(final List<HandlerInterceptor> interceptors) {
this.interceptors = interceptors;
this.fileService = fileService;
}
@Override
......@@ -63,19 +51,6 @@ public class SpringWebConfig implements WebMvcConfigurer {
SimpleModule module = new SimpleModule();
module.addSerializer(Calendar.class, new CalendarSerializer());
module.addSerializer(Color.class, new ColorSerializer());
module.addSerializer(ReferenceGenomeGeneMapping.class, new ReferenceGenomeGeneMappingSerializer(
new Function<String, String>() {
@Override
public String apply(final String sourceUrl) {
String url = null;
try {
url = "../" + fileService.getLocalPathForFile(sourceUrl);
} catch (final FileNotFoundException e) {
logger.warn("Cannot find local file", e);
}
return url;
}
}));
m.getObjectMapper().registerModule(module);
}
......
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