Search in sources :

Example 1 with JSONObjectsWriter

use of org.nextprot.api.web.service.impl.writer.JSONObjectsWriter 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);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) SlimIsoformTSVWriter(org.nextprot.api.core.service.export.io.SlimIsoformTSVWriter) NextprotMediaType(org.nextprot.api.core.service.export.format.NextprotMediaType) IOException(java.io.IOException) JSONObjectsWriter(org.nextprot.api.web.service.impl.writer.JSONObjectsWriter) ApiMethod(org.jsondoc.core.annotation.ApiMethod)

Example 2 with JSONObjectsWriter

use of org.nextprot.api.web.service.impl.writer.JSONObjectsWriter 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();
    }
}
Also used : PrintWriter(java.io.PrintWriter) ApiVerb(org.jsondoc.core.pojo.ApiVerb) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) MediaType(org.springframework.http.MediaType) Collection(java.util.Collection) HttpServletResponse(javax.servlet.http.HttpServletResponse) NextProtException(org.nextprot.api.commons.exception.NextProtException) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) Controller(org.springframework.stereotype.Controller) NextprotMediaType(org.nextprot.api.core.service.export.format.NextprotMediaType) ApiQueryParam(org.jsondoc.core.annotation.ApiQueryParam) ProteinExistence(org.nextprot.api.core.domain.ProteinExistence) HttpServletRequest(javax.servlet.http.HttpServletRequest) ApiMethod(org.jsondoc.core.annotation.ApiMethod) JSONObjectsWriter(org.nextprot.api.web.service.impl.writer.JSONObjectsWriter) Api(org.jsondoc.core.annotation.Api) MasterIdentifierService(org.nextprot.api.core.service.MasterIdentifierService) ApiPathParam(org.jsondoc.core.annotation.ApiPathParam) JSONObjectsWriter(org.nextprot.api.web.service.impl.writer.JSONObjectsWriter) PrintWriter(java.io.PrintWriter)

Aggregations

IOException (java.io.IOException)2 ApiMethod (org.jsondoc.core.annotation.ApiMethod)2 NextProtException (org.nextprot.api.commons.exception.NextProtException)2 NextprotMediaType (org.nextprot.api.core.service.export.format.NextprotMediaType)2 JSONObjectsWriter (org.nextprot.api.web.service.impl.writer.JSONObjectsWriter)2 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Api (org.jsondoc.core.annotation.Api)1 ApiPathParam (org.jsondoc.core.annotation.ApiPathParam)1 ApiQueryParam (org.jsondoc.core.annotation.ApiQueryParam)1 ApiVerb (org.jsondoc.core.pojo.ApiVerb)1 ProteinExistence (org.nextprot.api.core.domain.ProteinExistence)1 MasterIdentifierService (org.nextprot.api.core.service.MasterIdentifierService)1 SlimIsoformTSVWriter (org.nextprot.api.core.service.export.io.SlimIsoformTSVWriter)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 MediaType (org.springframework.http.MediaType)1 Controller (org.springframework.stereotype.Controller)1 PathVariable (org.springframework.web.bind.annotation.PathVariable)1