Search in sources :

Example 1 with ChromosomeNotFoundException

use of org.nextprot.api.commons.exception.ChromosomeNotFoundException in project nextprot-api by calipho-sib.

the class StreamEntryServiceImpl method streamAllChromosomeEntries.

@Override
public void streamAllChromosomeEntries(String chromosome, NextprotMediaType format, HttpServletResponse response) {
    if (!Chromosome.exists(chromosome)) {
        ChromosomeNotFoundException ex = new ChromosomeNotFoundException(chromosome);
        response.setStatus(HttpStatus.SC_NOT_FOUND);
        try {
            response.getWriter().print(ex.getMessage());
        } catch (IOException e) {
            throw new NextProtException(format.getExtension() + " streaming failed: " + ex.getMessage(), e);
        }
    } else {
        try {
            setResponseHeader(response, format, "nextprot_chromosome_" + chromosome + "." + format.getExtension());
            streamEntries(masterIdentifierService.findUniqueNamesOfChromosome(chromosome), format, "entry", response.getOutputStream(), "chromosome " + chromosome);
        } catch (IOException e) {
            throw new NextProtException(format.getExtension() + " streaming failed: cannot export all " + masterIdentifierService.findUniqueNames().size() + " entries from chromosome " + chromosome, e);
        }
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) ChromosomeNotFoundException(org.nextprot.api.commons.exception.ChromosomeNotFoundException) IOException(java.io.IOException)

Example 2 with ChromosomeNotFoundException

use of org.nextprot.api.commons.exception.ChromosomeNotFoundException in project nextprot-api by calipho-sib.

the class ChromosomeReportServiceImpl method reportChromosome.

@Cacheable("chromosome-reports")
@Override
public ChromosomeReport reportChromosome(String chromosome) {
    // TODO: if chromosome is not found throw an http error 404
    if (!Chromosome.exists(chromosome)) {
        throw new ChromosomeNotFoundException(chromosome);
    }
    ChromosomeReport report = new ChromosomeReport();
    report.setDataRelease(releaseInfoService.findReleaseVersions().getDatabaseRelease());
    List<String> allEntriesOnChromosome = masterIdentifierService.findUniqueNamesOfChromosome(chromosome);
    List<EntryReport> entryReports = allEntriesOnChromosome.stream().map(entryAccession -> entryGeneReportService.reportEntry(entryAccession)).flatMap(Collection::stream).filter(er -> er.getChromosome().equals(chromosome)).sorted(EntryReport.newByChromosomalPositionComparator()).collect(Collectors.toList());
    report.setEntryReports(entryReports);
    ChromosomeReport.Summary summary = newSummary(chromosome, entryReports);
    setByProteinEvidenceEntryCount(allEntriesOnChromosome, summary);
    report.setSummary(summary);
    return report;
}
Also used : ChromosomeNotFoundException(org.nextprot.api.commons.exception.ChromosomeNotFoundException) EntryReport(org.nextprot.api.core.domain.EntryReport) ChromosomeReport(org.nextprot.api.core.domain.ChromosomeReport) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

ChromosomeNotFoundException (org.nextprot.api.commons.exception.ChromosomeNotFoundException)2 IOException (java.io.IOException)1 NextProtException (org.nextprot.api.commons.exception.NextProtException)1 ChromosomeReport (org.nextprot.api.core.domain.ChromosomeReport)1 EntryReport (org.nextprot.api.core.domain.EntryReport)1 Cacheable (org.springframework.cache.annotation.Cacheable)1