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);
}
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();
}
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);
}
}
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();
}
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();
}
Aggregations