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);
}
}
}
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;
}
Aggregations