Search in sources :

Example 1 with JoinQuery

use of org.obiba.mica.spi.search.support.JoinQuery in project mica2 by obiba.

the class GenericReportGenerator method generateCsv.

public void generateCsv(QueryType exportType, String rqlQuery, List<String> columnsToHide, OutputStream outputStream) throws IOException {
    JoinQuery joinQuery = searcher.makeJoinQuery(rqlQuery);
    MicaSearch.JoinQueryResultDto queryResult = joinQueryExecutor.query(exportType, joinQuery);
    CsvReportGenerator csvReportGenerator = csvReportGeneratorFactory.get(exportType, queryResult, columnsToHide, joinQuery.getLocale());
    csvReportGenerator.write(outputStream);
}
Also used : JoinQuery(org.obiba.mica.spi.search.support.JoinQuery) MicaSearch(org.obiba.mica.web.model.MicaSearch)

Example 2 with JoinQuery

use of org.obiba.mica.spi.search.support.JoinQuery 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 3 with JoinQuery

use of org.obiba.mica.spi.search.support.JoinQuery in project mica2 by obiba.

the class JoinQueryReportGenerator method generateCsv.

public void generateCsv(QueryType exportType, String rqlQuery, List<String> columnsToHide, OutputStream outputStream) throws IOException {
    final String limitRegex = "limit\\((\\d+),(\\d+)\\)";
    Pattern pattern = Pattern.compile(limitRegex);
    Matcher matcher = pattern.matcher(rqlQuery);
    if (matcher.find()) {
        int size = Integer.valueOf(matcher.group(2));
        int numberOfSteps = Double.valueOf(Math.ceil(size / (double) MAX_DOWNLOAD_STEP)).intValue();
        for (int i = 0; i < numberOfSteps; i++) {
            JoinQuery joinQuery = searcher.makeJoinQuery(rqlQuery.replace(matcher.group(), "limit(" + (MAX_DOWNLOAD_STEP * i) + "," + MAX_DOWNLOAD_STEP + ")"));
            MicaSearch.JoinQueryResultDto queryResult = joinQueryExecutor.query(exportType, joinQuery);
            ReportGenerator reportGenerator = dtosCsvReportGeneratorFactory.get(exportType, queryResult, columnsToHide, joinQuery.getLocale());
            reportGenerator.write(outputStream, i > 0);
        }
    } else {
        JoinQuery joinQuery = searcher.makeJoinQuery(rqlQuery);
        MicaSearch.JoinQueryResultDto queryResult = joinQueryExecutor.query(exportType, joinQuery);
        ReportGenerator reportGenerator = dtosCsvReportGeneratorFactory.get(exportType, queryResult, columnsToHide, joinQuery.getLocale());
        reportGenerator.write(outputStream);
    }
}
Also used : Pattern(java.util.regex.Pattern) JoinQuery(org.obiba.mica.spi.search.support.JoinQuery) Matcher(java.util.regex.Matcher) MicaSearch(org.obiba.mica.web.model.MicaSearch)

Example 4 with JoinQuery

use of org.obiba.mica.spi.search.support.JoinQuery in project mica2 by obiba.

the class CoverageQueryExecutor method coverageQuery.

public MicaSearch.TaxonomiesCoverageDto coverageQuery(String rqlJoinQuery, boolean strict) throws IOException {
    joinQuery = searcher.makeJoinQuery(rqlJoinQuery);
    // If no variable query is specified, nothing is returned if strictness is applied, otherwise coverage of all terms is returned.
    if (strict) {
        restrictedTermsMap = joinQuery.getVariableQuery().getTaxonomyTermsMap();
        // If do not need all the facets then we can restrict the variable aggregations to the ones matching these names.
        if (!joinQuery.isWithFacets()) {
            restrictedTermsMap.forEach((taxo, vocMap) -> vocMap.keySet().forEach(voc -> joinQuery.getVariableQuery().getAggregations().add("attributes." + AttributeKey.getMapKey(voc, taxo) + "." + LanguageTag.UNDETERMINED)));
        }
    }
    // We need the aggregations internally for building the coverage result,
    // but we may not need them in the final result
    JoinQuery joinQueryWithFacets = new JoinQueryWrapperWithFacets(joinQuery);
    MicaSearch.JoinQueryResultDto result = joinQueryExecutor.queryCoverage(joinQueryWithFacets);
    List<MicaSearch.AggregationResultDto> aggregations = ungroupAggregations(result.getVariableResultDto().getAggsList());
    MicaSearch.TaxonomiesCoverageDto.Builder builder = // 
    MicaSearch.TaxonomiesCoverageDto.newBuilder().setTotalCount(// 
    result.getVariableResultDto().getTotalCount()).setTotalHits(// 
    result.getVariableResultDto().getTotalHits()).addAllTaxonomies(getCoverages(aggregations)).setQueryResult(result);
    // Do not append the aggregations if no facets is requested
    if (joinQuery.isWithFacets())
        builder.setQueryResult(result);
    return builder.build();
}
Also used : Searcher(org.obiba.mica.spi.search.Searcher) Query(org.obiba.mica.spi.search.support.Query) Collection(java.util.Collection) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) IOException(java.io.IOException) AttributeKey(org.obiba.mica.spi.search.support.AttributeKey) OpalService(org.obiba.mica.micaConfig.service.OpalService) NotNull(javax.validation.constraints.NotNull) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Scope(org.springframework.context.annotation.Scope) Term(org.obiba.opal.core.domain.taxonomy.Term) Inject(javax.inject.Inject) MicaSearch(org.obiba.mica.web.model.MicaSearch) Component(org.springframework.stereotype.Component) List(java.util.List) Lists(com.google.common.collect.Lists) LanguageTag(sun.util.locale.LanguageTag) JoinQuery(org.obiba.mica.spi.search.support.JoinQuery) Map(java.util.Map) Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Dtos(org.obiba.mica.web.model.Dtos) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) JoinQuery(org.obiba.mica.spi.search.support.JoinQuery) MicaSearch(org.obiba.mica.web.model.MicaSearch)

Example 5 with JoinQuery

use of org.obiba.mica.spi.search.support.JoinQuery 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)

Aggregations

JoinQuery (org.obiba.mica.spi.search.support.JoinQuery)6 Mica (org.obiba.mica.web.model.Mica)3 MicaSearch (org.obiba.mica.web.model.MicaSearch)3 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 JoinQueryReportGenerator (org.obiba.mica.search.reports.JoinQueryReportGenerator)2 ReportGenerator (org.obiba.mica.search.reports.ReportGenerator)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 NotNull (javax.validation.constraints.NotNull)1 JsonTranslator (org.obiba.core.translator.JsonTranslator)1