Search in sources :

Example 11 with ManagedQuery

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

the class PermissionCleanupTaskTest method doDeletePermissionInvalidReference.

@Test
void doDeletePermissionInvalidReference() {
    assertThat(STORAGE.getAllExecutions()).isEmpty();
    final ManagedQuery managedQuery = createManagedQuery();
    // Removing the execution
    STORAGE.removeExecution(managedQuery.getId());
    User user = new User("test", "test", STORAGE);
    STORAGE.updateUser(user);
    user.addPermission(ExecutionPermission.onInstance(AbilitySets.QUERY_CREATOR, managedQuery.getId()));
    deleteQueryPermissionsWithMissingRef(STORAGE, STORAGE.getAllUsers());
    assertThat(user.getPermissions()).isEmpty();
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Test(org.junit.jupiter.api.Test)

Example 12 with ManagedQuery

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

the class QueryCleanupTaskTest method singleNamedButUUID.

@Test
void singleNamedButUUID() throws Exception {
    assertThat(STORAGE.getAllExecutions()).isEmpty();
    final ManagedQuery managedQuery = createManagedQuery();
    managedQuery.setLabel(UUID.randomUUID().toString());
    new QueryCleanupTask(STORAGE, queryExpiration).execute(Map.of(), null);
    assertThat(STORAGE.getAllExecutions()).isEmpty();
}
Also used : ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Test(org.junit.jupiter.api.Test)

Example 13 with ManagedQuery

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

the class QueryCleanupTaskTest method reusedNoNames.

@Test
void reusedNoNames() throws Exception {
    assertThat(STORAGE.getAllExecutions()).isEmpty();
    final ManagedQuery managedQuery = createManagedQuery();
    final ManagedQuery managedQueryReused = createManagedQuery();
    managedQuery.setQuery(new ConceptQuery(new CQReusedQuery(managedQueryReused.getId())));
    new QueryCleanupTask(STORAGE, queryExpiration).execute(Map.of(), null);
    assertThat(STORAGE.getAllExecutions()).isEmpty();
}
Also used : CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) Test(org.junit.jupiter.api.Test)

Example 14 with ManagedQuery

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

the class QueryCleanupTaskTest method createManagedQuery.

private ManagedQuery createManagedQuery() {
    final CQAnd root = new CQAnd();
    root.setChildren(new ArrayList<>());
    ConceptQuery query = new ConceptQuery(root);
    final ManagedQuery managedQuery = new ManagedQuery(query, null, new Dataset("test"));
    managedQuery.setCreationTime(LocalDateTime.now().minus(queryExpiration).minusDays(1));
    STORAGE.addExecution(managedQuery);
    return managedQuery;
}
Also used : Dataset(com.bakdata.conquery.models.datasets.Dataset) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) CQAnd(com.bakdata.conquery.apiv1.query.concept.specific.CQAnd) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery)

Example 15 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery 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)

Aggregations

ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)37 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)18 Test (org.junit.jupiter.api.Test)18 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)13 User (com.bakdata.conquery.models.auth.entities.User)12 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)8 Dataset (com.bakdata.conquery.models.datasets.Dataset)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 CsvSource (org.junit.jupiter.params.provider.CsvSource)6 CQAnd (com.bakdata.conquery.apiv1.query.concept.specific.CQAnd)5 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)5 List (java.util.List)5 Slf4j (lombok.extern.slf4j.Slf4j)5 CQExternal (com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal)4 ManagedExecutionId (com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId)4 PrintSettings (com.bakdata.conquery.models.query.PrintSettings)4 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)3 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)3 I18n (com.bakdata.conquery.models.i18n.I18n)3 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)3