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