Search in sources :

Example 1 with ReportGenerator

use of org.obiba.mica.search.reports.ReportGenerator 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 2 with ReportGenerator

use of org.obiba.mica.search.reports.ReportGenerator 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 3 with ReportGenerator

use of org.obiba.mica.search.reports.ReportGenerator 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 4 with ReportGenerator

use of org.obiba.mica.search.reports.ReportGenerator in project mica2 by obiba.

the class PublishedStudiesSetResource method reportStudies.

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

Example 5 with ReportGenerator

use of org.obiba.mica.search.reports.ReportGenerator in project mica2 by obiba.

the class StudyCsvReportGenerator method write.

@Override
public void write(OutputStream outputStream) {
    try (ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) {
        zipOutputStream.putNextEntry(new ZipEntry("studies.csv"));
        super.write(zipOutputStream);
        zipOutputStream.putNextEntry(new ZipEntry("populations.csv"));
        ReportGenerator reporter = new StudyPopulationCsvReportGenerator(studies, getLocale());
        reporter.write(zipOutputStream);
        zipOutputStream.putNextEntry(new ZipEntry("data-collection-events.csv"));
        reporter = new StudyPopulationDCECsvReportGenerator(studies, getLocale());
        reporter.write(zipOutputStream);
        zipOutputStream.putNextEntry(new ZipEntry("persons.csv"));
        for (int i = 0; i < studies.size(); i++) {
            BaseStudy study = studies.get(i);
            reporter = new PersonCsvReportGenerator(study.getId(), personService.getStudyMemberships(study.getId()), getLocale()) {

                @Override
                protected String getParentIdHeader() {
                    return "studyId";
                }

                @Override
                protected List<Person.Membership> getMemberships(Person person) {
                    return person.getStudyMemberships();
                }
            };
            reporter.write(zipOutputStream, i > 0);
        }
    } catch (IOException e) {
        log.error("Error when reporting studies", e);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) ReportGenerator(org.obiba.mica.search.reports.ReportGenerator) ZipOutputStream(java.util.zip.ZipOutputStream) List(java.util.List) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Person(org.obiba.mica.core.domain.Person)

Aggregations

ReportGenerator (org.obiba.mica.search.reports.ReportGenerator)7 StreamingOutput (javax.ws.rs.core.StreamingOutput)5 DocumentSet (org.obiba.mica.core.domain.DocumentSet)3 IOException (java.io.IOException)2 ZipEntry (java.util.zip.ZipEntry)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 JoinQueryReportGenerator (org.obiba.mica.search.reports.JoinQueryReportGenerator)2 NetworkCsvReportGenerator (org.obiba.mica.search.reports.generators.NetworkCsvReportGenerator)2 StudyCsvReportGenerator (org.obiba.mica.search.reports.generators.StudyCsvReportGenerator)2 JoinQuery (org.obiba.mica.spi.search.support.JoinQuery)2 Mica (org.obiba.mica.web.model.Mica)2 List (java.util.List)1 Person (org.obiba.mica.core.domain.Person)1 DatasetVariableCsvReportGenerator (org.obiba.mica.search.reports.generators.DatasetVariableCsvReportGenerator)1 SpecificStudyReportGenerator (org.obiba.mica.search.reports.generators.SpecificStudyReportGenerator)1 BaseStudy (org.obiba.mica.study.domain.BaseStudy)1