Search in sources :

Example 11 with ApiMethod

use of org.jsondoc.core.annotation.ApiMethod in project nextprot-api by calipho-sib.

the class DbXrefController method findAllXrefs.

@ApiMethod(path = "/rdf/xrefs", verb = ApiVerb.GET, description = "Exports list of xrefs", produces = { "text/turtle" })
@RequestMapping("/rdf/xrefs")
public void findAllXrefs(Model model, HttpServletResponse response, HttpServletRequest request) throws Exception {
    // too many data, memory errors... should stream rather than list...
    List<Long> ids = this.xrService.getAllDbXrefsIds();
    // for (Long id : ids) System.out.println("fulllist - id: " + id);
    int idx = 0;
    int bunchSize = 100000;
    int bunchCount = 0;
    NextprotMediaType format = getRequestedFormat(request);
    String fileName = "nextprot-xrefs" + "." + format.getExtension();
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    View v = viewResolver.resolveViewName("prefix", Locale.ENGLISH);
    v.render(model.asMap(), request, response);
    while (true) {
        bunchCount++;
        int idx2 = idx + bunchSize;
        if (idx2 > ids.size())
            idx2 = ids.size();
        System.out.println("bunch: " + bunchCount + " - indices: " + idx + " - " + idx2);
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        // do the job
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        List<Long> someIds = ids.subList(idx, idx2);
        List<DbXref> refs = this.xrService.findDbXRefByIds(someIds);
        model.addAttribute("bunch", bunchCount);
        model.addAttribute("xrefIds", refs);
        model.addAttribute("StringUtils", StringUtils.class);
        v = viewResolver.resolveViewName("xref-all", Locale.ENGLISH);
        v.render(model.asMap(), request, response);
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        idx = idx2;
        if (idx == ids.size())
            break;
    }
}
Also used : DbXref(org.nextprot.api.core.domain.DbXref) NextprotMediaType(org.nextprot.api.core.service.export.format.NextprotMediaType) View(org.springframework.web.servlet.View) ApiMethod(org.jsondoc.core.annotation.ApiMethod) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with ApiMethod

use of org.jsondoc.core.annotation.ApiMethod in project nextprot-api by calipho-sib.

the class RdfPublicationController method findOnePublicationByMd5.

@ApiMethod(path = "/rdf/publication/{md5}", verb = ApiVerb.GET, description = "Exports one neXtProt publication.", produces = { "text/turtle" })
@RequestMapping("/rdf/publication/{md5}")
public String findOnePublicationByMd5(@ApiPathParam(name = "md5", description = "The md5 of the publication", allowedvalues = { "b240aea6411ebd3cc49099009359df1f" }) @PathVariable("md5") String md5, Model model) {
    Publication publication = publicationService.findPublicationByMD5(md5);
    model.addAttribute("publication", publication);
    model.addAttribute("prefix", true);
    model.addAttribute("StringUtils", StringUtils.class);
    model.addAttribute("isLargeScale", publicationService.getPublicationStatistics(publication.getPublicationId()).isLargeScale());
    return "publication";
}
Also used : Publication(org.nextprot.api.core.domain.Publication) ApiMethod(org.jsondoc.core.annotation.ApiMethod) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with ApiMethod

use of org.jsondoc.core.annotation.ApiMethod in project nextprot-api by calipho-sib.

the class ChromosomeReportController method exportChromosomeEntryCountByProteinEvidenceFile.

@ApiMethod(path = "/chromosome-report/export/hpp/entry-count-by-pe", verb = ApiVerb.GET, description = "Export number of entries grouped by protein existence for all chromosomes", produces = { NextprotMediaType.TSV_MEDIATYPE_VALUE })
@RequestMapping(value = "/chromosome-report/export/hpp/entry-count-by-pe", method = { RequestMethod.GET })
public void exportChromosomeEntryCountByProteinEvidenceFile(HttpServletResponse response) {
    try (OutputStream os = response.getOutputStream()) {
        response.setHeader("Content-Disposition", "attachment; filename=\"count-of-pe12345-by-chromosome.tsv\"");
        chromosomeReportExportService.exportHPPChromosomeEntryReportCountByProteinExistence(os);
    } catch (IOException e) {
        throw new NextProtException(e.getMessage() + ": cannot export entry count by protein existence for all chromosomes");
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ApiMethod(org.jsondoc.core.annotation.ApiMethod) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with ApiMethod

use of org.jsondoc.core.annotation.ApiMethod in project nextprot-api by calipho-sib.

the class ChromosomeReportController method exportHPPChromosomeEntriesReportFile.

@ApiMethod(path = "/chromosome-report/export/hpp/{chromosome}", verb = ApiVerb.GET, description = "Export informations of neXtProt entries located on a given chromosome by accession", produces = { MediaType.TEXT_PLAIN_VALUE, NextprotMediaType.TSV_MEDIATYPE_VALUE })
@RequestMapping(value = "/chromosome-report/export/hpp/{chromosome}", method = { RequestMethod.GET })
public void exportHPPChromosomeEntriesReportFile(@ApiPathParam(name = "chromosome", description = "The chromosome number or name (X,Y..)", allowedvalues = { "Y" }) @PathVariable("chromosome") String chromosome, HttpServletRequest request, HttpServletResponse response) {
    NextprotMediaType mediaType = NextprotMediaType.valueOf(request);
    try (OutputStream os = response.getOutputStream()) {
        String filename = "HPP_chromosome_" + chromosome + "." + mediaType.getExtension();
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        chromosomeReportExportService.exportHPPChromosomeEntryReport(chromosome, NextprotMediaType.valueOf(request), os);
    } catch (IOException e) {
        throw new NextProtException(e.getMessage() + ": cannot export HPP chromosome " + chromosome + " as " + mediaType);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) OutputStream(java.io.OutputStream) NextprotMediaType(org.nextprot.api.core.service.export.format.NextprotMediaType) IOException(java.io.IOException) ApiMethod(org.jsondoc.core.annotation.ApiMethod) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with ApiMethod

use of org.jsondoc.core.annotation.ApiMethod 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)

Aggregations

ApiMethod (org.jsondoc.core.annotation.ApiMethod)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 NextProtException (org.nextprot.api.commons.exception.NextProtException)8 IOException (java.io.IOException)7 OutputStream (java.io.OutputStream)6 NextprotMediaType (org.nextprot.api.core.service.export.format.NextprotMediaType)4 CvTerm (org.nextprot.api.core.domain.CvTerm)2 CvTermGraph (org.nextprot.api.core.domain.CvTermGraph)2 UserProteinList (org.nextprot.api.user.domain.UserProteinList)2 UserQuery (org.nextprot.api.user.domain.UserQuery)2 SearchQueryException (org.nextprot.api.commons.exception.SearchQueryException)1 DbXref (org.nextprot.api.core.domain.DbXref)1 Publication (org.nextprot.api.core.domain.Publication)1 SlimIsoformTSVWriter (org.nextprot.api.core.service.export.io.SlimIsoformTSVWriter)1 Query (org.nextprot.api.solr.Query)1 QueryRequest (org.nextprot.api.solr.QueryRequest)1 SearchResult (org.nextprot.api.solr.SearchResult)1 JSONObjectsWriter (org.nextprot.api.web.service.impl.writer.JSONObjectsWriter)1 View (org.springframework.web.servlet.View)1