Search in sources :

Example 1 with SingleTableResult

use of com.bakdata.conquery.models.query.SingleTableResult in project conquery by bakdata.

the class ResultExcelProcessor method getExcelResult.

public <E extends ManagedExecution<?> & SingleTableResult> Response getExcelResult(Subject subject, E exec, DatasetId datasetId, boolean pretty) {
    ConqueryMDC.setLocation(subject.getName());
    final Namespace namespace = datasetRegistry.get(datasetId);
    Dataset dataset = namespace.getDataset();
    subject.authorize(dataset, Ability.READ);
    subject.authorize(dataset, Ability.DOWNLOAD);
    subject.authorize(exec, Ability.READ);
    IdPrinter idPrinter = config.getFrontend().getQueryUpload().getIdPrinter(subject, exec, namespace);
    final Locale locale = I18n.LOCALE.get();
    PrintSettings settings = new PrintSettings(pretty, locale, datasetRegistry, config, idPrinter::createId);
    ExcelRenderer excelRenderer = new ExcelRenderer(config.getExcel(), settings);
    StreamingOutput out = output -> excelRenderer.renderToStream(config.getFrontend().getQueryUpload().getIdResultInfos(), (ManagedExecution<?> & SingleTableResult) exec, output);
    return makeResponseWithFileName(out, exec.getLabelWithoutAutoLabelSuffix(), "xlsx", MEDIA_TYPE, ResultUtil.ContentDispositionOption.ATTACHMENT);
}
Also used : IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) Locale(java.util.Locale) ResultUtil(com.bakdata.conquery.io.result.ResultUtil) ConqueryMDC(com.bakdata.conquery.util.io.ConqueryMDC) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) ResultUtil.makeResponseWithFileName(com.bakdata.conquery.io.result.ResultUtil.makeResponseWithFileName) Subject(com.bakdata.conquery.models.auth.entities.Subject) RequiredArgsConstructor(lombok.RequiredArgsConstructor) StreamingOutput(javax.ws.rs.core.StreamingOutput) SingleTableResult(com.bakdata.conquery.models.query.SingleTableResult) ArrayList(java.util.ArrayList) Dataset(com.bakdata.conquery.models.datasets.Dataset) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) Response(javax.ws.rs.core.Response) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) Ability(com.bakdata.conquery.models.auth.permissions.Ability) Locale(java.util.Locale) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) I18n(com.bakdata.conquery.models.i18n.I18n) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) Namespace(com.bakdata.conquery.models.worker.Namespace) Dataset(com.bakdata.conquery.models.datasets.Dataset) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) StreamingOutput(javax.ws.rs.core.StreamingOutput) SingleTableResult(com.bakdata.conquery.models.query.SingleTableResult) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) Namespace(com.bakdata.conquery.models.worker.Namespace)

Example 2 with SingleTableResult

use of com.bakdata.conquery.models.query.SingleTableResult in project conquery by bakdata.

the class ResultArrowProcessor method getArrowResult.

public static <E extends ManagedExecution<?> & SingleTableResult> Response getArrowResult(Function<OutputStream, Function<VectorSchemaRoot, ArrowWriter>> writerProducer, Subject subject, E exec, Dataset dataset, DatasetRegistry datasetRegistry, boolean pretty, String fileExtension, MediaType mediaType, ConqueryConfig config) {
    final Namespace namespace = datasetRegistry.get(dataset.getId());
    ConqueryMDC.setLocation(subject.getName());
    log.info("Downloading results for {} on dataset {}", exec, dataset);
    subject.authorize(dataset, Ability.READ);
    subject.authorize(dataset, Ability.DOWNLOAD);
    subject.authorize(exec, Ability.READ);
    // Check if subject is permitted to download on all datasets that were referenced by the query
    authorizeDownloadDatasets(subject, exec);
    if (!(exec instanceof ManagedQuery || (exec instanceof ManagedForm && ((ManagedForm) exec).getSubQueries().size() == 1))) {
        return Response.status(HttpStatus.SC_UNPROCESSABLE_ENTITY, "Execution result is not a single Table").build();
    }
    // Get the locale extracted by the LocaleFilter
    IdPrinter idPrinter = config.getFrontend().getQueryUpload().getIdPrinter(subject, exec, namespace);
    final Locale locale = I18n.LOCALE.get();
    PrintSettings settings = new PrintSettings(pretty, locale, datasetRegistry, config, idPrinter::createId);
    // Collect ResultInfos for id columns and result columns
    final List<ResultInfo> resultInfosId = config.getFrontend().getQueryUpload().getIdResultInfos();
    final List<ResultInfo> resultInfosExec = exec.getResultInfos();
    StreamingOutput out = output -> renderToStream(writerProducer.apply(output), settings, config.getArrow().getBatchSize(), resultInfosId, resultInfosExec, exec.streamResults());
    return makeResponseWithFileName(out, exec.getLabelWithoutAutoLabelSuffix(), fileExtension, mediaType, ResultUtil.ContentDispositionOption.ATTACHMENT);
}
Also used : IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) Locale(java.util.Locale) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) ManagedForm(com.bakdata.conquery.models.forms.managed.ManagedForm) Subject(com.bakdata.conquery.models.auth.entities.Subject) AuthorizationHelper.authorizeDownloadDatasets(com.bakdata.conquery.models.auth.AuthorizationHelper.authorizeDownloadDatasets) HttpStatus(org.apache.http.HttpStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) UtilityClass(lombok.experimental.UtilityClass) MediaType(javax.ws.rs.core.MediaType) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) ArrowWriter(org.apache.arrow.vector.ipc.ArrowWriter) Locale(java.util.Locale) ArrowRenderer.renderToStream(com.bakdata.conquery.io.result.arrow.ArrowRenderer.renderToStream) I18n(com.bakdata.conquery.models.i18n.I18n) IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) OutputStream(java.io.OutputStream) ResultUtil(com.bakdata.conquery.io.result.ResultUtil) ConqueryMDC(com.bakdata.conquery.util.io.ConqueryMDC) ResultUtil.makeResponseWithFileName(com.bakdata.conquery.io.result.ResultUtil.makeResponseWithFileName) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) StreamingOutput(javax.ws.rs.core.StreamingOutput) SingleTableResult(com.bakdata.conquery.models.query.SingleTableResult) Dataset(com.bakdata.conquery.models.datasets.Dataset) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Response(javax.ws.rs.core.Response) Ability(com.bakdata.conquery.models.auth.permissions.Ability) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) Namespace(com.bakdata.conquery.models.worker.Namespace) ManagedForm(com.bakdata.conquery.models.forms.managed.ManagedForm) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) StreamingOutput(javax.ws.rs.core.StreamingOutput) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) Namespace(com.bakdata.conquery.models.worker.Namespace)

Example 3 with SingleTableResult

use of com.bakdata.conquery.models.query.SingleTableResult in project conquery by bakdata.

the class ResultCsvProcessor method getResult.

public <E extends ManagedExecution<?> & SingleTableResult> Response getResult(Subject subject, Dataset dataset, E exec, String userAgent, String queryCharset, boolean pretty) {
    final Namespace namespace = datasetRegistry.get(dataset.getId());
    ConqueryMDC.setLocation(subject.getName());
    log.info("Downloading results for {} on dataset {}", exec, dataset);
    subject.authorize(namespace.getDataset(), Ability.READ);
    subject.authorize(namespace.getDataset(), Ability.DOWNLOAD);
    subject.authorize(exec, Ability.READ);
    // Check if subject is permitted to download on all datasets that were referenced by the query
    authorizeDownloadDatasets(subject, exec);
    IdPrinter idPrinter = config.getFrontend().getQueryUpload().getIdPrinter(subject, exec, namespace);
    // Get the locale extracted by the LocaleFilter
    final Locale locale = I18n.LOCALE.get();
    PrintSettings settings = new PrintSettings(pretty, locale, datasetRegistry, config, idPrinter::createId);
    Charset charset = determineCharset(userAgent, queryCharset);
    StreamingOutput out = os -> {
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, charset))) {
            CsvRenderer renderer = new CsvRenderer(config.getCsv().createWriter(writer), settings);
            renderer.toCSV(config.getFrontend().getQueryUpload().getIdResultInfos(), exec.getResultInfos(), exec.streamResults());
        } catch (EofException e) {
            log.info("User canceled download");
        } catch (Exception e) {
            throw new WebApplicationException("Failed to load result", e);
        }
    };
    return makeResponseWithFileName(out, exec.getLabelWithoutAutoLabelSuffix(), "csv", new MediaType("text", "csv", charset.toString()), ResultUtil.ContentDispositionOption.ATTACHMENT);
}
Also used : Locale(java.util.Locale) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Subject(com.bakdata.conquery.models.auth.entities.Subject) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AuthorizationHelper.authorizeDownloadDatasets(com.bakdata.conquery.models.auth.AuthorizationHelper.authorizeDownloadDatasets) EofException(org.eclipse.jetty.io.EofException) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) MediaType(javax.ws.rs.core.MediaType) Charset(java.nio.charset.Charset) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) Locale(java.util.Locale) OutputStreamWriter(java.io.OutputStreamWriter) I18n(com.bakdata.conquery.models.i18n.I18n) IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) ResultUtil(com.bakdata.conquery.io.result.ResultUtil) ConqueryMDC(com.bakdata.conquery.util.io.ConqueryMDC) ResultUtil.makeResponseWithFileName(com.bakdata.conquery.io.result.ResultUtil.makeResponseWithFileName) BufferedWriter(java.io.BufferedWriter) ResultUtil.determineCharset(com.bakdata.conquery.io.result.ResultUtil.determineCharset) StreamingOutput(javax.ws.rs.core.StreamingOutput) SingleTableResult(com.bakdata.conquery.models.query.SingleTableResult) Dataset(com.bakdata.conquery.models.datasets.Dataset) Slf4j(lombok.extern.slf4j.Slf4j) Response(javax.ws.rs.core.Response) Ability(com.bakdata.conquery.models.auth.permissions.Ability) WebApplicationException(javax.ws.rs.WebApplicationException) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) Namespace(com.bakdata.conquery.models.worker.Namespace) EofException(org.eclipse.jetty.io.EofException) WebApplicationException(javax.ws.rs.WebApplicationException) Charset(java.nio.charset.Charset) ResultUtil.determineCharset(com.bakdata.conquery.io.result.ResultUtil.determineCharset) StreamingOutput(javax.ws.rs.core.StreamingOutput) Namespace(com.bakdata.conquery.models.worker.Namespace) EofException(org.eclipse.jetty.io.EofException) WebApplicationException(javax.ws.rs.WebApplicationException) BufferedWriter(java.io.BufferedWriter) IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) MediaType(javax.ws.rs.core.MediaType) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

ResultUtil (com.bakdata.conquery.io.result.ResultUtil)3 ResultUtil.makeResponseWithFileName (com.bakdata.conquery.io.result.ResultUtil.makeResponseWithFileName)3 Subject (com.bakdata.conquery.models.auth.entities.Subject)3 Ability (com.bakdata.conquery.models.auth.permissions.Ability)3 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)3 Dataset (com.bakdata.conquery.models.datasets.Dataset)3 ManagedExecution (com.bakdata.conquery.models.execution.ManagedExecution)3 I18n (com.bakdata.conquery.models.i18n.I18n)3 IdPrinter (com.bakdata.conquery.models.identifiable.mapping.IdPrinter)3 PrintSettings (com.bakdata.conquery.models.query.PrintSettings)3 SingleTableResult (com.bakdata.conquery.models.query.SingleTableResult)3 DatasetRegistry (com.bakdata.conquery.models.worker.DatasetRegistry)3 Namespace (com.bakdata.conquery.models.worker.Namespace)3 ConqueryMDC (com.bakdata.conquery.util.io.ConqueryMDC)3 Locale (java.util.Locale)3 MediaType (javax.ws.rs.core.MediaType)3 Response (javax.ws.rs.core.Response)3 StreamingOutput (javax.ws.rs.core.StreamingOutput)3 AuthorizationHelper.authorizeDownloadDatasets (com.bakdata.conquery.models.auth.AuthorizationHelper.authorizeDownloadDatasets)2 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)2