Search in sources :

Example 31 with CvTerm

use of org.nextprot.api.core.domain.CvTerm in project nextprot-api by calipho-sib.

the class TerminologyDaoImpl method findTerminologyByAccession.

@Override
// SHOULD USE findTermByAccessionAndTerminology
@Cacheable("terminology-by-accession")
public CvTerm findTerminologyByAccession(String accession) {
    Set<String> acs = new HashSet<>();
    acs.add(accession);
    SqlParameterSource params = new MapSqlParameterSource("accessions", acs);
    List<CvTerm> terms = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("terminology-by-acs"), params, new DbTermRowMapper());
    if (terms.size() == 0)
        return null;
    else if (terms.size() > 1) {
        throw new NextProtException("Found " + terms.size() + " terms that corresponds to the same accession. Use the method findTerminologyByAccessionForTerminology (accession, terminology) instead");
    }
    return terms.get(0);
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) CvTerm(org.nextprot.api.core.domain.CvTerm) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) HashSet(java.util.HashSet) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 32 with CvTerm

use of org.nextprot.api.core.domain.CvTerm in project nextprot-api by calipho-sib.

the class TermController method getAncestorGraph.

@ApiMethod(path = "/term/{term}/ancestor-graph", verb = ApiVerb.GET, description = "Get the ancestor graph of the given term", produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/term/{term}/ancestor-graph", method = { RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, CvTermGraph.View> getAncestorGraph(@ApiPathParam(name = "term", description = "The accession of the cv term", allowedvalues = { "TS-0079" }) @PathVariable("term") String term) {
    CvTerm cvTerm = terminologyService.findCvTermByAccession(term);
    CvTermGraph graph = cvTermGraphService.findCvTermGraph(TerminologyCv.getTerminologyOf(cvTerm.getOntology()));
    return Collections.singletonMap("ancestor-graph", graph.calcAncestorSubgraph(cvTerm.getId().intValue()).toView());
}
Also used : CvTerm(org.nextprot.api.core.domain.CvTerm) CvTermGraph(org.nextprot.api.core.domain.CvTermGraph) ApiMethod(org.jsondoc.core.annotation.ApiMethod) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with CvTerm

use of org.nextprot.api.core.domain.CvTerm in project nextprot-api by calipho-sib.

the class TermController method getDescendantGraph.

@ApiMethod(path = "/term/{term}/descendant-graph", verb = ApiVerb.GET, description = "Get the descendant graph of the given term", produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/term/{term}/descendant-graph", method = { RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, CvTermGraph.View> getDescendantGraph(@ApiPathParam(name = "term", description = "The accession of the cv term", allowedvalues = { "TS-0079" }) @PathVariable("term") String term) {
    CvTerm cvTerm = terminologyService.findCvTermByAccession(term);
    CvTermGraph graph = cvTermGraphService.findCvTermGraph(TerminologyCv.getTerminologyOf(cvTerm.getOntology()));
    return Collections.singletonMap("descendant-graph", graph.calcDescendantSubgraph(cvTerm.getId().intValue()).toView());
}
Also used : CvTerm(org.nextprot.api.core.domain.CvTerm) CvTermGraph(org.nextprot.api.core.domain.CvTermGraph) ApiMethod(org.jsondoc.core.annotation.ApiMethod) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 34 with CvTerm

use of org.nextprot.api.core.domain.CvTerm in project nextprot-api by calipho-sib.

the class SeoTagsServiceImpl method getTermSeoTags.

@Override
public SeoTags getTermSeoTags(String url) {
    String[] urlElements = RelativeUrlUtils.getPathElements(url);
    String ac = urlElements[1];
    // default subpage
    String subpage = "proteins";
    if (urlElements.length > 2)
        subpage = urlElements[2];
    String prettySubpage = getPrettyName(subpage);
    CvTerm term = terminologyService.findCvTermByAccession(ac);
    String title = term.getAccession() + " - " + getPrettyName(term.getName()) + " - " + prettySubpage;
    String h1 = title;
    // TODO: NullPointerException below
    String descr = term.getOntology() + " " + term.getAccession() + " - " + term.getName() + " - " + prettySubpage;
    return new SeoTags(title, descr, h1);
}
Also used : CvTerm(org.nextprot.api.core.domain.CvTerm) SeoTags(org.nextprot.api.web.seo.domain.SeoTags)

Aggregations

CvTerm (org.nextprot.api.core.domain.CvTerm)34 Test (org.junit.Test)9 CoreUnitBaseTest (org.nextprot.api.core.test.base.CoreUnitBaseTest)8 AnnotationEvidence (org.nextprot.api.core.domain.annotation.AnnotationEvidence)5 NextProtException (org.nextprot.api.commons.exception.NextProtException)4 CvTermGraph (org.nextprot.api.core.domain.CvTermGraph)4 Annotation (org.nextprot.api.core.domain.annotation.Annotation)4 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)4 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)4 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)4 Publication (org.nextprot.api.core.domain.Publication)3 Supplier (com.google.common.base.Supplier)2 Instant (java.time.Instant)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Collectors (java.util.stream.Collectors)2 Logger (org.apache.log4j.Logger)2 ApiMethod (org.jsondoc.core.annotation.ApiMethod)2 ConsoleProgressBar (org.nextprot.api.commons.app.ConsoleProgressBar)2