use of com.bakdata.conquery.apiv1.query.QueryDescription in project conquery by bakdata.
the class ManagedExecution method setAdditionalFieldsForStatusWithSource.
/**
* Sets additional fields of an {@link ExecutionStatus} when a more specific status is requested.
*/
protected void setAdditionalFieldsForStatusWithSource(Subject subject, FullExecutionStatus status) {
QueryDescription query = getSubmitted();
NamespacedIdentifiableCollector namespacesIdCollector = new NamespacedIdentifiableCollector();
query.visit(namespacesIdCollector);
final Set<Concept> concepts = namespacesIdCollector.getIdentifiables().stream().filter(ConceptElement.class::isInstance).map(ConceptElement.class::cast).map(ConceptElement::getConcept).collect(Collectors.toSet());
boolean canExpand = subject.isPermittedAll(concepts, Ability.READ);
status.setCanExpand(canExpand);
status.setQuery(canExpand ? getSubmitted() : null);
}
use of com.bakdata.conquery.apiv1.query.QueryDescription in project conquery by bakdata.
the class QueryProcessor method tryReuse.
/**
* Determine if the submitted query does reuse ONLY another query and restart that instead of creating another one.
*/
private ManagedExecution<?> tryReuse(QueryDescription query, ManagedExecutionId executionId, DatasetRegistry datasetRegistry, ConqueryConfig config, ExecutionManager executionManager, User user) {
ManagedExecution<?> execution = datasetRegistry.getMetaRegistry().resolve(executionId);
if (execution == null) {
return null;
}
// Direct reuse only works if the queries are of the same type (As reuse reconstructs the Query for different types)
if (!query.getClass().equals(execution.getSubmitted().getClass())) {
return null;
}
// If SecondaryIds differ from selected and prior, we cannot reuse them.
if (query instanceof SecondaryIdQuery) {
final SecondaryIdDescription selectedSecondaryId = ((SecondaryIdQuery) query).getSecondaryId();
final SecondaryIdDescription reusedSecondaryId = ((SecondaryIdQuery) execution.getSubmitted()).getSecondaryId();
if (!selectedSecondaryId.equals(reusedSecondaryId)) {
return null;
}
}
// If the user is not the owner of the execution, we definitely create a new Execution, so the owner can cancel it
if (!user.isOwner(execution)) {
final ManagedExecution<?> newExecution = executionManager.createExecution(datasetRegistry, execution.getSubmitted(), user, execution.getDataset());
newExecution.setLabel(execution.getLabel());
newExecution.setTags(execution.getTags().clone());
storage.updateExecution(newExecution);
execution = newExecution;
}
ExecutionState state = execution.getState();
if (state.equals(ExecutionState.RUNNING)) {
log.trace("The Execution[{}] was already started and its state is: {}", execution.getId(), state);
return execution;
}
log.trace("Re-executing Query {}", execution);
executionManager.execute(datasetRegistry, execution, config);
return execution;
}
Aggregations