use of org.nextprot.api.core.service.export.format.NextprotMediaType in project nextprot-api by calipho-sib.
the class ChromosomeReportController method exportChromosomeEntriesReportFile.
@ApiMethod(path = "/chromosome-report/export/{chromosome}", verb = ApiVerb.GET, description = "Export informations of neXtProt entries located on a given chromosome", produces = { MediaType.TEXT_PLAIN_VALUE, NextprotMediaType.TSV_MEDIATYPE_VALUE })
@RequestMapping(value = "/chromosome-report/export/{chromosome}", method = { RequestMethod.GET })
public void exportChromosomeEntriesReportFile(@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 = "nextprot_chromosome_" + chromosome + "." + mediaType.getExtension();
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
chromosomeReportExportService.exportChromosomeEntryReport(chromosome, NextprotMediaType.valueOf(request), os);
} catch (IOException e) {
throw new NextProtException(e.getMessage() + ": cannot export chromosome " + chromosome + " as " + mediaType);
}
}
use of org.nextprot.api.core.service.export.format.NextprotMediaType in project nextprot-api by calipho-sib.
the class EntryController method getListOfIsoformAcMd5Sequence.
@ApiMethod(path = "/isoforms", verb = ApiVerb.GET, description = "Retrieves all isoforms", produces = { MediaType.APPLICATION_JSON_VALUE, NextprotMediaType.TSV_MEDIATYPE_VALUE })
@RequestMapping(value = "/isoforms", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE, NextprotMediaType.TSV_MEDIATYPE_VALUE })
public void getListOfIsoformAcMd5Sequence(HttpServletRequest request, HttpServletResponse response) {
NextprotMediaType mediaType = NextprotMediaType.valueOf(request);
try {
List<SlimIsoform> isoforms = isoformService.findListOfIsoformAcMd5Sequence();
if (mediaType == NextprotMediaType.JSON) {
JSONObjectsWriter<SlimIsoform> writer = new JSONObjectsWriter<>(response.getOutputStream());
writer.write(isoforms);
} else if (mediaType == NextprotMediaType.TSV) {
SlimIsoformTSVWriter writer = new SlimIsoformTSVWriter(response.getOutputStream());
writer.write(isoforms);
writer.close();
}
} catch (IOException e) {
throw new NextProtException("cannot get isoforms in " + mediaType.getExtension() + " format", e);
}
}
use of org.nextprot.api.core.service.export.format.NextprotMediaType in project nextprot-api by calipho-sib.
the class EntryAccessionController method writeEntries.
private void writeEntries(Collection<String> entries, NextprotMediaType mediaType, HttpServletResponse response) throws IOException {
if (mediaType == NextprotMediaType.JSON) {
JSONObjectsWriter<String> writer = new JSONObjectsWriter<>(response.getOutputStream());
writer.write(entries);
} else if (mediaType == NextprotMediaType.TXT) {
PrintWriter writer = new PrintWriter(response.getOutputStream());
entries.forEach(entryAccession -> {
writer.write(entryAccession);
writer.write("\n");
});
writer.close();
}
}
use of org.nextprot.api.core.service.export.format.NextprotMediaType in project nextprot-api by calipho-sib.
the class DbXrefController method getRequestedFormat.
private NextprotMediaType getRequestedFormat(HttpServletRequest request) {
NextprotMediaType format;
String uri = request.getRequestURI();
if (uri.toLowerCase().endsWith(".ttl")) {
format = NextprotMediaType.TURTLE;
} else if (uri.toLowerCase().endsWith(".xml")) {
format = NextprotMediaType.XML;
} else if (uri.toLowerCase().endsWith(".json")) {
format = NextprotMediaType.JSON;
} else if (uri.toLowerCase().endsWith(".txt")) {
format = NextprotMediaType.TXT;
} else
throw new NextProtException("Format not recognized");
return format;
}
use of org.nextprot.api.core.service.export.format.NextprotMediaType 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;
}
}
Aggregations