use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.
the class DefaultLabelTest method autoLabelConceptQuery.
@ParameterizedTest
@CsvSource({ "de,Concept", "en,Concept" })
void autoLabelConceptQuery(Locale locale, String autoLabel) {
I18n.LOCALE.set(locale);
CQConcept concept = makeCQConcept("Concept");
ConceptQuery cq = new ConceptQuery(concept);
ManagedQuery mQuery = cq.toManagedExecution(user, DATASET);
mQuery.setLabel(mQuery.makeAutoLabel(getPrintSettings(locale)));
assertThat(mQuery.getLabel()).isEqualTo(autoLabel + AUTO_LABEL_SUFFIX);
assertThat(mQuery.getLabelWithoutAutoLabelSuffix()).isEqualTo(autoLabel);
}
use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.
the class DefaultLabelTest method autoLabelConceptQueryFallback.
@ParameterizedTest
@CsvSource({ "de,Default-Concept", "en,Default-Concept" })
void autoLabelConceptQueryFallback(Locale locale, String autoLabel) {
I18n.LOCALE.set(locale);
CQConcept concept = new CQConcept();
concept.setLabel(null);
concept.setElements(List.of(CONCEPT));
ConceptQuery cq = new ConceptQuery(concept);
ManagedQuery mQuery = cq.toManagedExecution(user, DATASET);
UUID uuid = UUID.randomUUID();
mQuery.setQueryId(uuid);
mQuery.setLabel(mQuery.makeAutoLabel(getPrintSettings(locale)));
assertThat(mQuery.getLabel()).isEqualTo(autoLabel + AUTO_LABEL_SUFFIX);
assertThat(mQuery.getLabelWithoutAutoLabelSuffix()).isEqualTo(autoLabel);
}
use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.
the class DefaultLabelTest method autoLabelComplexQueryNullLabels.
@ParameterizedTest
@CsvSource({ "de,Hochgeladene-Liste Anfrage Default-Concept Concept2 Concept3", "en,Uploaded-List Query Default-Concept Concept2 Concept3" })
void autoLabelComplexQueryNullLabels(Locale locale, String autoLabel) {
I18n.LOCALE.set(locale);
final ManagedQuery managedQuery = new ManagedQuery(null, null, DATASET);
managedQuery.setQueryId(UUID.randomUUID());
CQAnd and = new CQAnd();
CQConcept concept1 = new CQConcept();
concept1.setLabel(null);
concept1.setElements(List.of(CONCEPT));
CQConcept concept2 = makeCQConcept("Concept2");
CQConcept concept3 = makeCQConcept("Concept3");
and.setChildren(List.of(new CQExternal(List.of(), new String[0][0]), new CQReusedQuery(managedQuery.getId()), concept1, concept2, concept3));
ConceptQuery cq = new ConceptQuery(and);
ManagedQuery mQuery = cq.toManagedExecution(user, DATASET);
mQuery.setLabel(mQuery.makeAutoLabel(getPrintSettings(locale)));
assertThat(mQuery.getLabel()).isEqualTo(autoLabel + AUTO_LABEL_SUFFIX);
assertThat(mQuery.getLabelWithoutAutoLabelSuffix()).isEqualTo(autoLabel);
}
use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.
the class FilteringConceptManipulator method consume.
public void consume(CQConcept concept, DatasetRegistry namespaces) {
List<Select> selects = concept.getSelects();
if (!selectBlockList.isEmpty()) {
selects.removeIf(s -> selectBlockList.contains(s.getId()));
} else if (!selectAllowList.isEmpty()) {
selects.removeIf(s -> !selectAllowList.contains(s.getId()));
}
// Add default selects if none is present anymore
if (selects.isEmpty()) {
concept.setSelects(selectDefault.stream().map(namespaces::resolve).collect(Collectors.toList()));
}
// Handle tables
List<CQTable> tables = concept.getTables();
Iterator<CQTable> it = tables.iterator();
while (it.hasNext()) {
CQTable table = it.next();
if (tableBlockList.contains(table.getConnector().getId())) {
it.remove();
}
if (!tableAllowList.containsKey(table.getConnector().getId())) {
it.remove();
} else {
// If table is allowlisted apply a table manipulator if one exist
TableManipulator tableMan = tableAllowList.get(table.getConnector().getId());
if (tableMan != null) {
tableMan.consume(table, namespaces);
}
}
}
if (tables.isEmpty()) {
throw new IllegalStateException(String.format("After filtering the tables of concept %s, no table was left in the concept. ConceptManipulator: %s", concept, this.toString()));
}
}
use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.
the class SecondaryIdQuery method resolve.
@Override
public void resolve(final QueryResolveContext context) {
DateAggregationMode resolvedDateAggregationMode = dateAggregationMode;
if (context.getDateAggregationMode() != null) {
log.trace("Overriding date aggregation mode ({}) with mode from context ({})", dateAggregationMode, context.getDateAggregationMode());
resolvedDateAggregationMode = context.getDateAggregationMode();
}
final QueryResolveContext resolvedContext = context.withDateAggregationMode(resolvedDateAggregationMode);
this.query = new ConceptQuery(root);
query.resolve(resolvedContext);
withSecondaryId = new HashSet<>();
withoutSecondaryId = new HashSet<>();
// TODO FK: can we refactor this into methods of CQConcept?
// partition tables by their holding of the requested SecondaryId.
// This assumes that from the root, only ConceptNodes hold TableIds we are interested in.
query.visit(queryElement -> {
if (!(queryElement instanceof CQConcept)) {
return;
}
final CQConcept concept = (CQConcept) queryElement;
for (CQTable connector : concept.getTables()) {
final Table table = connector.getConnector().getTable();
final Column secondaryIdColumn = findSecondaryIdColumn(table);
if (secondaryIdColumn != null && !concept.isExcludeFromSecondaryId()) {
withSecondaryId.add(secondaryIdColumn);
} else {
withoutSecondaryId.add(table);
}
}
});
// If there are no tables with the secondaryId, we fail as that is user error.
if (withSecondaryId.isEmpty()) {
throw new ConqueryError.NoSecondaryIdSelectedError();
}
}
Aggregations