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

common cache interface extracted for mirnas, drugs, chemicals|

parent 84312b31
No related branches found
No related tags found
1 merge request!101Common cache interface
package lcsb.mapviewer.services.search.db;
import java.util.HashSet;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.data.TargettingStructure;
import lcsb.mapviewer.annotation.services.PubmedParser;
import lcsb.mapviewer.annotation.services.PubmedSearchException;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
@Transactional(value = "txManager")
public abstract class DbSearchService {
/**
* Service accessing
* <a href="http://europepmc.org/RestfulWebService">pubmed</a>.
*/
@Autowired
private PubmedParser pubmedParser;
protected void cacheMiriamData(TargettingStructure targettingStructure) throws AnnotatorException {
Set<MiriamData> result = new HashSet<>();
result.addAll(targettingStructure.getSources());
for (Target target : targettingStructure.getTargets()) {
result.addAll(target.getGenes());
result.addAll(target.getReferences());
}
for (MiriamData miriamData : result) {
if (MiriamType.PUBMED.equals(miriamData.getDataType())) {
try {
pubmedParser.getPubmedArticleById(Integer.valueOf(miriamData.getResource()));
} catch (NumberFormatException | PubmedSearchException e) {
throw new AnnotatorException(e);
}
}
}
}
}
......@@ -17,12 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.data.Chemical;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.data.TargettingStructure;
import lcsb.mapviewer.annotation.services.ChemicalParser;
import lcsb.mapviewer.annotation.services.ChemicalSearchException;
import lcsb.mapviewer.annotation.services.PubmedParser;
import lcsb.mapviewer.annotation.services.PubmedSearchException;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.common.IProgressUpdater;
......@@ -38,6 +34,7 @@ import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.statistics.SearchType;
import lcsb.mapviewer.services.interfaces.ISearchHistoryService;
import lcsb.mapviewer.services.search.db.DbSearchCriteria;
import lcsb.mapviewer.services.search.db.DbSearchService;
/**
* Implementation of the service that allows access information about chemicals.
......@@ -46,7 +43,7 @@ import lcsb.mapviewer.services.search.db.DbSearchCriteria;
*
*/
@Transactional(value = "txManager")
public class ChemicalService implements IChemicalService {
public class ChemicalService extends DbSearchService implements IChemicalService {
/**
* Default class logger.
......@@ -70,13 +67,6 @@ public class ChemicalService implements IChemicalService {
@Autowired
private HgncAnnotator hgncAnnotator;
/**
* Service accessing
* <a href="http://europepmc.org/RestfulWebService">pubmed</a>.
*/
@Autowired
private PubmedParser pubmedParser;
/**
* Service that manages search history.
*/
......@@ -323,25 +313,4 @@ public class ChemicalService implements IChemicalService {
}
}
private void cacheMiriamData(TargettingStructure targettingStructure) throws AnnotatorException {
Set<MiriamData> result = new HashSet<>();
result.addAll(targettingStructure.getSources());
for (Target target : targettingStructure.getTargets()) {
result.addAll(target.getGenes());
result.addAll(target.getReferences());
}
for (MiriamData miriamData : result) {
if (miriamData.getDataType().equals(MiriamType.PUBMED)) {
try {
pubmedParser.getPubmedArticleById(Integer.valueOf(miriamData.getResource()));
} catch (NumberFormatException | PubmedSearchException e) {
throw new AnnotatorException(e);
}
}
}
}
}
......@@ -13,12 +13,9 @@ import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.data.Drug;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.data.TargettingStructure;
import lcsb.mapviewer.annotation.services.ChEMBLParser;
import lcsb.mapviewer.annotation.services.DrugSearchException;
import lcsb.mapviewer.annotation.services.DrugbankHTMLParser;
import lcsb.mapviewer.annotation.services.PubmedParser;
import lcsb.mapviewer.annotation.services.PubmedSearchException;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.common.IProgressUpdater;
......@@ -33,6 +30,7 @@ import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.statistics.SearchType;
import lcsb.mapviewer.services.interfaces.ISearchHistoryService;
import lcsb.mapviewer.services.search.db.DbSearchCriteria;
import lcsb.mapviewer.services.search.db.DbSearchService;
/**
* Implementation of the service that allows access information about drugs.
......@@ -41,7 +39,7 @@ import lcsb.mapviewer.services.search.db.DbSearchCriteria;
*
*/
@Transactional(value = "txManager")
public class DrugService implements IDrugService {
public class DrugService extends DbSearchService implements IDrugService {
/**
* Default class logger.
......@@ -67,13 +65,6 @@ public class DrugService implements IDrugService {
@Autowired
private HgncAnnotator hgncAnnotator;
/**
* Service accessing
* <a href="http://europepmc.org/RestfulWebService">pubmed</a>.
*/
@Autowired
private PubmedParser pubmedParser;
/**
* Service that manages search history.
*/
......@@ -348,23 +339,6 @@ public class DrugService implements IDrugService {
this.searchHistoryService = searchHistoryService;
}
/**
* @return the pubmedParser
* @see #pubmedParser
*/
public PubmedParser getPubmedParser() {
return pubmedParser;
}
/**
* @param pubmedParser
* the pubmedParser to set
* @see #pubmedParser
*/
public void setPubmedParser(PubmedParser pubmedParser) {
this.pubmedParser = pubmedParser;
}
@Override
public void cacheDataForModel(Model originalModel, IProgressUpdater iProgressUpdater) {
logger.debug("Caching drug queries...");
......@@ -410,26 +384,4 @@ public class DrugService implements IDrugService {
}
}
}
private void cacheMiriamData(TargettingStructure targettingStructure) throws AnnotatorException {
Set<MiriamData> result = new HashSet<>();
result.addAll(targettingStructure.getSources());
for (Target target : targettingStructure.getTargets()) {
result.addAll(target.getGenes());
result.addAll(target.getReferences());
}
for (MiriamData miriamData : result) {
if (miriamData.getDataType().equals(MiriamType.PUBMED)) {
try {
pubmedParser.getPubmedArticleById(Integer.valueOf(miriamData.getResource()));
} catch (NumberFormatException | PubmedSearchException e) {
throw new AnnotatorException(e);
}
}
}
}
}
......@@ -15,11 +15,8 @@ import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.data.MiRNA;
import lcsb.mapviewer.annotation.data.Target;
import lcsb.mapviewer.annotation.data.TargettingStructure;
import lcsb.mapviewer.annotation.services.MiRNAParser;
import lcsb.mapviewer.annotation.services.MiRNASearchException;
import lcsb.mapviewer.annotation.services.PubmedParser;
import lcsb.mapviewer.annotation.services.PubmedSearchException;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator;
import lcsb.mapviewer.common.IProgressUpdater;
......@@ -34,6 +31,7 @@ import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.statistics.SearchType;
import lcsb.mapviewer.services.interfaces.ISearchHistoryService;
import lcsb.mapviewer.services.search.db.DbSearchCriteria;
import lcsb.mapviewer.services.search.db.DbSearchService;
/**
* Implementation of the service that allows access information about che.
......@@ -42,7 +40,7 @@ import lcsb.mapviewer.services.search.db.DbSearchCriteria;
*
*/
@Transactional(value = "txManager")
public class MiRNAService implements IMiRNAService {
public class MiRNAService extends DbSearchService implements IMiRNAService {
/**
* Default class logger.
......@@ -68,13 +66,6 @@ public class MiRNAService implements IMiRNAService {
@Autowired
private ISearchHistoryService searchHistoryService;
/**
* Service accessing
* <a href="http://europepmc.org/RestfulWebService">pubmed</a>.
*/
@Autowired
private PubmedParser pubmedParser;
/**
* Default constructor.
*/
......@@ -243,25 +234,4 @@ public class MiRNAService implements IMiRNAService {
}
}
private void cacheMiriamData(TargettingStructure targettingStructure) throws AnnotatorException {
Set<MiriamData> result = new HashSet<>();
result.addAll(targettingStructure.getSources());
for (Target target : targettingStructure.getTargets()) {
result.addAll(target.getGenes());
result.addAll(target.getReferences());
}
for (MiriamData miriamData : result) {
if (miriamData.getDataType().equals(MiriamType.PUBMED)) {
try {
pubmedParser.getPubmedArticleById(Integer.valueOf(miriamData.getResource()));
} catch (NumberFormatException | PubmedSearchException e) {
throw new AnnotatorException(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