Search in sources :

Example 76 with StreamingOutput

use of javax.ws.rs.core.StreamingOutput in project mica2 by obiba.

the class PublishedNetworksSearchResource method export.

@POST
@Path("/_export")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response export(@FormParam("query") String query, @FormParam("locale") @DefaultValue("en") String locale) {
    if (!micaConfigService.getConfig().isNetworksExportEnabled())
        throw new BadRequestException("Networks export not enabled");
    JoinQuery joinQuery = searcher.makeJoinQuery(query);
    List<String> networkIds = joinQueryExecutor.query(QueryType.NETWORK, joinQuery).getNetworkResultDto().getExtension(MicaSearch.NetworkResultDto.result).getNetworksList().stream().map(Mica.NetworkDto::getId).collect(toList());
    ReportGenerator reporter = new NetworkCsvReportGenerator(publishedNetworkService.findByIds(networkIds, true), Strings.isNullOrEmpty(locale) ? joinQuery.getLocale() : locale, personService);
    StreamingOutput stream = reporter::write;
    return Response.ok(stream).header("Content-Disposition", "attachment; filename=\"Networks.zip\"").build();
}
Also used : ReportGenerator(org.obiba.mica.search.reports.ReportGenerator) JoinQueryReportGenerator(org.obiba.mica.search.reports.JoinQueryReportGenerator) NetworkCsvReportGenerator(org.obiba.mica.search.reports.generators.NetworkCsvReportGenerator) JoinQuery(org.obiba.mica.spi.search.support.JoinQuery) StreamingOutput(javax.ws.rs.core.StreamingOutput) Mica(org.obiba.mica.web.model.Mica) NetworkCsvReportGenerator(org.obiba.mica.search.reports.generators.NetworkCsvReportGenerator)

Example 77 with StreamingOutput

use of javax.ws.rs.core.StreamingOutput in project mica2 by obiba.

the class PublishedNetworksSetResource method reportNetworks.

@GET
@Path("/documents/_report")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response reportNetworks(@PathParam("id") String id, @QueryParam("locale") @DefaultValue("en") String locale) {
    DocumentSet documentSet = getSecuredDocumentSet(id);
    ReportGenerator reporter = new NetworkCsvReportGenerator(networkSetService.getPublishedNetworks(documentSet, true), locale, personService);
    StreamingOutput stream = reporter::write;
    return Response.ok(stream).header("Content-Disposition", "attachment; filename=\"Networks.zip\"").build();
}
Also used : ReportGenerator(org.obiba.mica.search.reports.ReportGenerator) NetworkCsvReportGenerator(org.obiba.mica.search.reports.generators.NetworkCsvReportGenerator) StreamingOutput(javax.ws.rs.core.StreamingOutput) DocumentSet(org.obiba.mica.core.domain.DocumentSet) NetworkCsvReportGenerator(org.obiba.mica.search.reports.generators.NetworkCsvReportGenerator)

Example 78 with StreamingOutput

use of javax.ws.rs.core.StreamingOutput in project mica2 by obiba.

the class PublishedStudiesSearchResource method export.

@POST
@Path("/_export")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response export(@FormParam("query") String query, @FormParam("locale") @DefaultValue("en") String locale) {
    if (!micaConfigService.getConfig().isStudiesExportEnabled())
        throw new BadRequestException("Studies export not enabled");
    JoinQuery joinQuery = searcher.makeJoinQuery(query);
    List<String> studyIds = joinQueryExecutor.query(QueryType.STUDY, joinQuery).getStudyResultDto().getExtension(MicaSearch.StudyResultDto.result).getSummariesList().stream().map(Mica.StudySummaryDto::getId).collect(toList());
    ReportGenerator reporter = new StudyCsvReportGenerator(publishedStudyService.findByIds(studyIds, true), Strings.isNullOrEmpty(locale) ? joinQuery.getLocale() : locale, personService);
    StreamingOutput stream = reporter::write;
    return Response.ok(stream).header("Content-Disposition", "attachment; filename=\"Studies.zip\"").build();
}
Also used : SpecificStudyReportGenerator(org.obiba.mica.search.reports.generators.SpecificStudyReportGenerator) StudyCsvReportGenerator(org.obiba.mica.search.reports.generators.StudyCsvReportGenerator) ReportGenerator(org.obiba.mica.search.reports.ReportGenerator) JoinQueryReportGenerator(org.obiba.mica.search.reports.JoinQueryReportGenerator) JoinQuery(org.obiba.mica.spi.search.support.JoinQuery) StreamingOutput(javax.ws.rs.core.StreamingOutput) Mica(org.obiba.mica.web.model.Mica) StudyCsvReportGenerator(org.obiba.mica.search.reports.generators.StudyCsvReportGenerator)

Example 79 with StreamingOutput

use of javax.ws.rs.core.StreamingOutput in project coprhd-controller by CoprHD.

the class AuditServiceTest method auditServiceTestJSON.

@Test
public void auditServiceTestJSON() throws WebApplicationException, IOException, JsonParseException {
    deleteIfExists(JsonTestOutputFile);
    DummyAuditLogRetriever dbAuditLogRetriever = new DummyAuditLogRetriever();
    AuditService auditResource = new AuditService();
    auditResource.setAuditLogRetriever(dbAuditLogRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_JSON_TYPE);
    Response r = auditResource.getAuditLogs("2012-08-08T00", "en_US", header);
    Assert.assertNotNull(r);
    Assert.assertEquals(Status.OK.getStatusCode(), r.getStatus());
    Assert.assertTrue(r.getEntity() instanceof StreamingOutput);
    StreamingOutput so = (StreamingOutput) r.getEntity();
    File of = new File(JsonTestOutputFile);
    OutputStream os = new FileOutputStream(of);
    so.write(os);
    os.close();
    ObjectMapper mapper = null;
    mapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
    AuditLogs auditLogs = mapper.readValue(new File(JsonTestOutputFile), AuditLogs.class);
    Assert.assertEquals(100, auditLogs.auditLogs.size());
    deleteIfExists(JsonTestOutputFile);
}
Also used : DummyAuditLogRetriever(com.emc.storageos.api.service.utils.DummyAuditLogRetriever) Response(javax.ws.rs.core.Response) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) AuditLogs(com.emc.storageos.api.service.utils.AuditLogs) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) StreamingOutput(javax.ws.rs.core.StreamingOutput) AuditService(com.emc.storageos.api.service.impl.resource.AuditService) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) Test(org.junit.Test)

Example 80 with StreamingOutput

use of javax.ws.rs.core.StreamingOutput in project coprhd-controller by CoprHD.

the class DbAuditLogRetrieverTest method auditServiceNullDBclientTestXML.

@Test
public void auditServiceNullDBclientTestXML() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = null;
    AuditService auditResource = new AuditService();
    DbAuditLogRetriever dummyDbAuditLogRetriever = new DbAuditLogRetriever();
    dummyDbAuditLogRetriever.setDbClient(dbClient);
    auditResource.setAuditLogRetriever(dummyDbAuditLogRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
    Response r = auditResource.getAuditLogs("2012-01-05T00:00", "en_US", header);
    Assert.assertNotNull(r);
    Assert.assertEquals(Status.OK.getStatusCode(), r.getStatus());
    Assert.assertTrue(r.getEntity() instanceof StreamingOutput);
    StreamingOutput so = (StreamingOutput) r.getEntity();
    File of = new File(XmlTestOutputFile);
    OutputStream os = new FileOutputStream(of);
    try {
        so.write(os);
    } catch (InternalServerErrorException e) {
        Assert.assertTrue(e.toString().contains("DB"));
    }
    os.close();
}
Also used : Response(javax.ws.rs.core.Response) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) DbAuditLogRetriever(com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) StreamingOutput(javax.ws.rs.core.StreamingOutput) AuditService(com.emc.storageos.api.service.impl.resource.AuditService) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) Test(org.junit.Test)

Aggregations

StreamingOutput (javax.ws.rs.core.StreamingOutput)190 OutputStream (java.io.OutputStream)84 Response (javax.ws.rs.core.Response)76 Path (javax.ws.rs.Path)53 Produces (javax.ws.rs.Produces)52 IOException (java.io.IOException)50 GET (javax.ws.rs.GET)50 File (java.io.File)45 InputStream (java.io.InputStream)45 Test (org.junit.Test)44 WebApplicationException (javax.ws.rs.WebApplicationException)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)32 List (java.util.List)26 MediaType (javax.ws.rs.core.MediaType)24 ByteArrayInputStream (java.io.ByteArrayInputStream)20 ArrayList (java.util.ArrayList)20 Consumes (javax.ws.rs.Consumes)20 HashMap (java.util.HashMap)19 POST (javax.ws.rs.POST)19 FileOutputStream (java.io.FileOutputStream)17