Skip to content
Snippets Groups Projects
Commit e4aca2f4 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

ReferenceGenomeView class removed

parent 7b19c040
No related branches found
No related tags found
1 merge request!286Resolve "Remove View objects from service"
Showing
with 85 additions and 608 deletions
package lcsb.mapviewer.api.genomics;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CookieValue;
......@@ -8,26 +10,26 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javassist.tools.rmi.ObjectNotFoundException;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.view.ReferenceGenomeView;
@RestController
public class ReferenceGenomeController extends BaseController {
@Autowired
private ReferenceGenomeRestImpl referenceGenomeController;
@Autowired
private ReferenceGenomeRestImpl referenceGenomeController;
@RequestMapping(value = "/genomics/taxonomies/{organismId}/genomeTypes/{type}/versions/{version}/", method = { RequestMethod.GET },
produces = { MediaType.APPLICATION_JSON_VALUE })
public ReferenceGenomeView getDrugsByQuery(//
@CookieValue(value = Configuration.AUTH_TOKEN) String token, //
@PathVariable(value = "organismId") String organism, //
@PathVariable(value = "type") String type, //
@PathVariable(value = "version") String version//
) throws SecurityException, QueryException {
return referenceGenomeController.getReferenceGenome(token, organism, type, version);
}
@RequestMapping(value = "/genomics/taxonomies/{organismId}/genomeTypes/{type}/versions/{version}/", method = {
RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public Map<String, Object> getGenomesByQuery(//
@CookieValue(value = Configuration.AUTH_TOKEN) String token, //
@PathVariable(value = "organismId") String organism, //
@PathVariable(value = "type") String type, //
@PathVariable(value = "version") String version//
) throws SecurityException, QueryException, ObjectNotFoundException {
return referenceGenomeController.getReferenceGenome(token, organism, type, version);
}
}
\ No newline at end of file
package lcsb.mapviewer.api.genomics;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.cache.BigFileCache;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.ObjectNotFoundException;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.layout.ReferenceGenome;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeType;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.interfaces.IReferenceGenomeService;
import lcsb.mapviewer.services.view.ReferenceGenomeView;
@Transactional(value = "txManager")
public class ReferenceGenomeRestImpl {
public class ReferenceGenomeRestImpl extends BaseRestImpl {
/**
* Default class logger.
......@@ -27,25 +37,68 @@ public class ReferenceGenomeRestImpl {
@Autowired
private IReferenceGenomeService referenceGenomeService;
public ReferenceGenomeView getReferenceGenome(String token, String organismId, String type, String version)
throws SecurityException, QueryException {
@Autowired
private BigFileCache bigFileCache;
public Map<String, Object> getReferenceGenome(String token, String organismId, String type, String version)
throws SecurityException, QueryException, ObjectNotFoundException {
MiriamData organism = null;
if (organismId != null && !organismId.isEmpty()) {
organism = new MiriamData(MiriamType.TAXONOMY, organismId);
} else {
throw new QueryException("Unknown taxonomy organism: " + organismId);
}
ReferenceGenomeView result = null;
try {
ReferenceGenomeType genomeType = ReferenceGenomeType.valueOf(type);
version = version.replaceAll("\\*", "");
result = referenceGenomeService.getReferenceGenomeViewByParams(organism, genomeType, version, token);
if (result == null) {
throw new QueryException("Cannot find requested reference genome");
ReferenceGenome genome = referenceGenomeService.getReferenceGenomeViewByParams(organism, genomeType, version,
token);
if (genome == null) {
throw new ObjectNotFoundException("Cannot find requested reference genome");
}
return genomeToMap(genome);
} catch (IllegalArgumentException e) {
throw new QueryException("Cannot find type: " + type);
}
}
private Map<String, Object> genomeToMap(ReferenceGenome genome) {
Map<String, Object> result = new TreeMap<>();
result.put("organism", super.createAnnotation(genome.getOrganism()));
result.put("version", genome.getVersion());
result.put("downloadProgress", genome.getDownloadProgress());
result.put("sourceUrl", genome.getSourceUrl());
result.put("localUrl", getLocalUrl(genome.getSourceUrl()));
result.put("geneMapping", geneMappingToMaps(genome.getGeneMapping()));
return null;
}
private String getLocalUrl(String sourceUrl) {
String url = null;
try {
url = "../" + bigFileCache.getLocalPathForFile(sourceUrl);
} catch (FileNotFoundException e) {
logger.warn("Cannot find local file", e);
}
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());
return result;
}
......
......@@ -10,6 +10,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.api.ObjectNotFoundException;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.api.RestTestFunctions;
......@@ -49,7 +50,7 @@ public class ReferenceGenomeControllerTest extends RestTestFunctions {
try {
referenceGenomeRestImpl.getReferenceGenome(token, "960000", "UCSC", "ver");
fail("Exception expected");
} catch (QueryException e2) {
} catch (ObjectNotFoundException e2) {
assertTrue(e2.getMessage().contains("Cannot find requested reference genome"));
} catch (Exception e) {
e.printStackTrace();
......
......@@ -21,8 +21,6 @@ import lcsb.mapviewer.model.map.layout.ReferenceGenomeType;
import lcsb.mapviewer.persist.dao.map.layout.ReferenceGenomeDao;
import lcsb.mapviewer.services.interfaces.IReferenceGenomeService;
import lcsb.mapviewer.services.utils.ReferenceGenomeExistsException;
import lcsb.mapviewer.services.view.ReferenceGenomeView;
import lcsb.mapviewer.services.view.ReferenceGenomeViewFactory;
/**
* Service managing reference genomes.
......@@ -52,12 +50,6 @@ public class ReferenceGenomeService implements IReferenceGenomeService {
@Autowired
private ReferenceGenomeDao referenceGenomeDao;
/**
* Factory that creates {@link ReferenceGenomeView}.
*/
@Autowired
private ReferenceGenomeViewFactory factory;
@Override
public void addReferenceGenome(ReferenceGenomeType type, MiriamData organism, String version, String customUrl)
throws IOException, URISyntaxException, ReferenceGenomeConnectorException {
......@@ -140,21 +132,15 @@ public class ReferenceGenomeService implements IReferenceGenomeService {
}
@Override
public ReferenceGenomeView getReferenceGenomeViewByParams(MiriamData miriamData, ReferenceGenomeType genomeType,
String version) {
public ReferenceGenome getReferenceGenomeViewByParams(MiriamData miriamData, ReferenceGenomeType genomeType,
String version, String authenticationToken) {
List<ReferenceGenome> list = referenceGenomeDao.getByType(genomeType);
for (ReferenceGenome referenceGenome : list) {
if (referenceGenome.getOrganism().equals(miriamData) && referenceGenome.getVersion().equals(version)) {
return factory.create(referenceGenome);
return referenceGenome;
}
}
return null;
}
@Override
public ReferenceGenomeView getReferenceGenomeViewByParams(MiriamData organism, ReferenceGenomeType genomeType,
String version, String authenticationToken) {
return this.getReferenceGenomeViewByParams(organism, genomeType, version);
}
}
......@@ -9,7 +9,6 @@ import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.layout.ReferenceGenome;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeType;
import lcsb.mapviewer.services.view.ReferenceGenomeView;
/**
* Service used to maintain referemce genome data.
......@@ -131,7 +130,7 @@ public interface IReferenceGenomeService {
void removeReferenceGenomeGeneMapping(ReferenceGenomeGeneMapping mapping) throws IOException;
/**
* Returns {@link ReferenceGenomeView} for specific reference genome.
* Returns {@link ReferenceGenome} for specific reference genome.
*
* @param organism
* organism of reference genome
......@@ -139,11 +138,8 @@ public interface IReferenceGenomeService {
* reference genome type
* @param version
* version of the reference genome
* @return {@link ReferenceGenomeView} for specific reference genome
* @return {@link ReferenceGenome} for specific reference genome
*/
ReferenceGenomeView getReferenceGenomeViewByParams(MiriamData organism, ReferenceGenomeType genomeType,
String version);
ReferenceGenomeView getReferenceGenomeViewByParams(MiriamData organism, ReferenceGenomeType genomeType,
String version, String authenticationToken);
ReferenceGenome getReferenceGenomeViewByParams(MiriamData organism, ReferenceGenomeType genomeType, String version,
String authenticationToken);
}
package lcsb.mapviewer.services.view;
import java.io.Serializable;
import lcsb.mapviewer.model.map.layout.ReferenceGenome;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping;
/**
* View representation of the {@link ReferenceGenome}.
*
* @author Piotr Gawron
*
*/
public class ReferenceGenomeGeneMappingView extends AbstractView<ReferenceGenomeGeneMapping> implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* {@link ReferenceGenomeGeneMapping#name}.
*/
private String name;
/**
* Url from which reference genome was downloaded.
*/
private String sourceUrl;
/**
* Local url where reference genome file can be accessed.
*/
private String localUrl;
/**
* Progess of downloading process (100 means file is downloaded).
*/
private double downloadProgress;
/**
* Default constructor.
*
* @param object
* {@link ReferenceGenome} which this view should visualize
*/
protected ReferenceGenomeGeneMappingView(ReferenceGenomeGeneMapping object) {
super(object);
}
/**
* Default constructor. Should be used only for deserialization.
*/
protected ReferenceGenomeGeneMappingView() {
}
/**
* @return the name
* @see #name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
* @see #name
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the sourceUrl
* @see #sourceUrl
*/
public String getSourceUrl() {
return sourceUrl;
}
/**
* @param sourceUrl
* the sourceUrl to set
* @see #sourceUrl
*/
public void setSourceUrl(String sourceUrl) {
this.sourceUrl = sourceUrl;
}
/**
* @return the localUrl
* @see #localUrl
*/
public String getLocalUrl() {
return localUrl;
}
/**
* @param localUrl
* the localUrl to set
* @see #localUrl
*/
public void setLocalUrl(String localUrl) {
this.localUrl = localUrl;
}
/**
* @return the downloadProgress
* @see #downloadProgress
*/
public double getDownloadProgress() {
return downloadProgress;
}
/**
* @param downloadProgress
* the downloadProgress to set
* @see #downloadProgress
*/
public void setDownloadProgress(double downloadProgress) {
this.downloadProgress = downloadProgress;
}
}
package lcsb.mapviewer.services.view;
import java.io.FileNotFoundException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.gson.Gson;
import lcsb.mapviewer.annotation.cache.BigFileCache;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping;
/**
* Factory class for {@link AnnotationView} class.
*
* @author Piotr Gawron
*
*/
public class ReferenceGenomeGeneMappingViewFactory extends AbstractViewFactory<ReferenceGenomeGeneMapping, ReferenceGenomeGeneMappingView> {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(ReferenceGenomeGeneMappingViewFactory.class);
/**
* Service that allows to access big files (reference genome is stored as a
* big file on the server).
*/
@Autowired
private BigFileCache bigFileCache;
@Override
public ReferenceGenomeGeneMappingView create(ReferenceGenomeGeneMapping object) {
ReferenceGenomeGeneMappingView result = new ReferenceGenomeGeneMappingView();
result.setDownloadProgress(object.getDownloadProgress());
try {
result.setLocalUrl("../" + bigFileCache.getLocalPathForFile(object.getSourceUrl()));
} catch (FileNotFoundException e) {
result.setLocalUrl(null);
}
result.setSourceUrl(object.getSourceUrl());
result.setName(object.getName());
return result;
}
@Override
public String createGson(ReferenceGenomeGeneMappingView object) {
return new Gson().toJson(object);
}
@Override
public ReferenceGenomeGeneMapping viewToObject(ReferenceGenomeGeneMappingView view) {
throw new NotImplementedException();
}
}
package lcsb.mapviewer.services.view;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.layout.ReferenceGenome;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeType;
/**
* View representation of the {@link ReferenceGenome}.
*
* @author Piotr Gawron
*
*/
public class ReferenceGenomeView extends AbstractView<ReferenceGenome> implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* {@link ReferenceGenome#organism}.
*/
private MiriamData organism;
/**
* {@link ReferenceGenome#type}.
*/
private ReferenceGenomeType type;
/**
* {@link ReferenceGenome#version}.
*/
private String version;
/**
* Progress of download process (100 means that file is complete).
*/
private double downloadProgress;
/**
* Url from which reference genome file was downloaded.
*/
private String sourceUrl;
/**
* Url to local copy of reference genome file.
*/
private String localUrl;
/**
* List of gene mappings for reference genome.
*/
private List<ReferenceGenomeGeneMappingView> geneMapping = new ArrayList<>();
/**
* Default constructor.
*
* @param object
* {@link ReferenceGenome} which this view should visualize
*/
protected ReferenceGenomeView(ReferenceGenome object) {
super(object);
}
/**
* Default constructor. Should be used only for deserialization.
*/
protected ReferenceGenomeView() {
}
/**
* @return the organism
* @see #organism
*/
public MiriamData getOrganism() {
return organism;
}
/**
* @param organism
* the organism to set
* @see #organism
*/
public void setOrganism(MiriamData organism) {
this.organism = organism;
}
/**
* @return the type
* @see #type
*/
public ReferenceGenomeType getType() {
return type;
}
/**
* @param type
* the type to set
* @see #type
*/
public void setType(ReferenceGenomeType type) {
this.type = type;
}
/**
* @return the version
* @see #version
*/
public String getVersion() {
return version;
}
/**
* @param version
* the version to set
* @see #version
*/
public void setVersion(String version) {
this.version = version;
}
/**
* @return the downloadProgress
* @see #downloadProgress
*/
public double getDownloadProgress() {
return downloadProgress;
}
/**
* @param downloadProgress
* the downloadProgress to set
* @see #downloadProgress
*/
public void setDownloadProgress(double downloadProgress) {
this.downloadProgress = downloadProgress;
}
/**
* @return the sourceUrl
* @see #sourceUrl
*/
public String getSourceUrl() {
return sourceUrl;
}
/**
* @param sourceUrl
* the sourceUrl to set
* @see #sourceUrl
*/
public void setSourceUrl(String sourceUrl) {
this.sourceUrl = sourceUrl;
}
/**
* @return the localUrl
* @see #localUrl
*/
public String getLocalUrl() {
return localUrl;
}
/**
* @param localUrl
* the localUrl to set
* @see #localUrl
*/
public void setLocalUrl(String localUrl) {
this.localUrl = localUrl;
}
/**
* @return the geneMapping
* @see #geneMapping
*/
public List<ReferenceGenomeGeneMappingView> getGeneMapping() {
return geneMapping;
}
/**
* @param geneMapping
* the geneMapping to set
* @see #geneMapping
*/
public void setGeneMapping(List<ReferenceGenomeGeneMappingView> geneMapping) {
this.geneMapping = geneMapping;
}
}
package lcsb.mapviewer.services.view;
import java.io.FileNotFoundException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.gson.Gson;
import lcsb.mapviewer.annotation.cache.BigFileCache;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.layout.ReferenceGenome;
/**
* Factory class for {@link AnnotationView} class.
*
* @author Piotr Gawron
*
*/
public class ReferenceGenomeViewFactory extends AbstractViewFactory<ReferenceGenome, ReferenceGenomeView> {
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(ReferenceGenomeViewFactory.class);
/**
* Access point for big files.
*/
@Autowired
private BigFileCache bigFileCache;
/**
* Factory that creates readable gene mappings.
*/
@Autowired
private ReferenceGenomeGeneMappingViewFactory referenceGenomeGeneMappingViewFactory;
@Override
public ReferenceGenomeView create(ReferenceGenome object) {
ReferenceGenomeView result = new ReferenceGenomeView();
result.setDownloadProgress(object.getDownloadProgress());
result.setGeneMapping(referenceGenomeGeneMappingViewFactory.createList(object.getGeneMapping()));
try {
result.setLocalUrl("../" + bigFileCache.getLocalPathForFile(object.getSourceUrl()));
} catch (FileNotFoundException e) {
logger.warn("Cannot find local file", e);
result.setLocalUrl(null);
}
result.setOrganism(object.getOrganism());
result.setSourceUrl(object.getSourceUrl());
result.setType(object.getType());
result.setVersion(object.getVersion());
return result;
}
@Override
public String createGson(ReferenceGenomeView object) {
return new Gson().toJson(object);
}
@Override
public ReferenceGenome viewToObject(ReferenceGenomeView view) {
throw new NotImplementedException();
}
}
......@@ -45,9 +45,6 @@
<bean id="PasswordEncoder" class="lcsb.mapviewer.services.impl.Md5PasswordEncoder"/>
<!-- View factories -->
<bean id="ReferenceGenomeViewFactory" class="lcsb.mapviewer.services.view.ReferenceGenomeViewFactory"/>
<bean id="ReferenceGenomeGeneMappingViewFactory" class="lcsb.mapviewer.services.view.ReferenceGenomeGeneMappingViewFactory"/>
<bean id="FullAliasViewFactory" class="lcsb.mapviewer.services.search.data.FullAliasViewFactory"/>
<bean id="FullReactionViewFactory" class="lcsb.mapviewer.services.search.data.FullReactionViewFactory"/>
<bean id="LightAliasViewFactory" class="lcsb.mapviewer.services.search.data.LightAliasViewFactory"/>
......
......@@ -6,8 +6,6 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ FrameworkVersionViewTest.class, //
ReferenceGenomeViewFactoryTest.class, //
ReferenceGenomeGeneMappingViewFactoryTest.class, //
})
public class AllViewTests {
......
package lcsb.mapviewer.services.view;
import static org.junit.Assert.assertNotNull;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeGeneMapping;
import lcsb.mapviewer.services.ServiceTestFunctions;
public class ReferenceGenomeGeneMappingViewFactoryTest extends ServiceTestFunctions {
@Autowired
ReferenceGenomeGeneMappingViewFactory factory;
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCreateEmpty() throws Exception {
try {
ReferenceGenomeGeneMapping referenceGenome = new ReferenceGenomeGeneMapping();
Object object = factory.create(referenceGenome);
assertNotNull(object);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCreateGson() throws Exception {
try {
ReferenceGenomeGeneMapping mapping = new ReferenceGenomeGeneMapping();
ReferenceGenomeGeneMappingView object = factory.create(mapping);
assertNotNull(factory.createGson(object));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
package lcsb.mapviewer.services.view;
import static org.junit.Assert.assertNotNull;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.model.map.layout.ReferenceGenome;
import lcsb.mapviewer.services.ServiceTestFunctions;
public class ReferenceGenomeViewFactoryTest extends ServiceTestFunctions {
@Autowired
ReferenceGenomeViewFactory factory;
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCreateEmpty() throws Exception {
try {
ReferenceGenome referenceGenome = new ReferenceGenome();
Object object = factory.create(referenceGenome);
assertNotNull(object);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCreateGson() throws Exception {
try {
ReferenceGenome referenceGenome = new ReferenceGenome();
ReferenceGenomeView object = factory.create(referenceGenome);
assertNotNull(factory.createGson(object));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
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