use of com.bakdata.conquery.apiv1.query.ConceptQuery in project conquery by bakdata.
the class FilterTest method parseQuery.
private Query parseQuery(StandaloneSupport support) throws JSONException, IOException {
rawFilterValue.put("filter", support.getDataset().getName() + ".concept.connector.filter");
FilterValue<?> result = parseSubTree(support, rawFilterValue, Jackson.MAPPER.getTypeFactory().constructType(FilterValue.class));
CQTable cqTable = new CQTable();
cqTable.setFilters(Collections.singletonList(result));
cqTable.setConnector(connector);
CQConcept cqConcept = new CQConcept();
cqTable.setConcept(cqConcept);
cqConcept.setElements(Collections.singletonList(concept));
cqConcept.setTables(Collections.singletonList(cqTable));
if (dateRange != null) {
CQDateRestriction restriction = new CQDateRestriction();
restriction.setDateRange(dateRange);
restriction.setChild(cqConcept);
return new ConceptQuery(restriction);
}
return new ConceptQuery(cqConcept);
}
use of com.bakdata.conquery.apiv1.query.ConceptQuery in project conquery by bakdata.
the class LoadingUtil method importPreviousQueries.
public static void importPreviousQueries(StandaloneSupport support, RequiredData content, User user) throws IOException {
// Load previous query results if available
int id = 1;
for (ResourceFile queryResults : content.getPreviousQueryResults()) {
UUID queryId = new UUID(0L, id++);
final CsvParser parser = support.getConfig().getCsv().withParseHeaders(false).withSkipHeader(false).createParser();
String[][] data = parser.parseAll(queryResults.stream()).toArray(new String[0][]);
ConceptQuery q = new ConceptQuery(new CQExternal(Arrays.asList("ID", "DATE_SET"), data));
ManagedExecution<?> managed = support.getNamespace().getExecutionManager().createQuery(support.getNamespace().getNamespaces(), q, queryId, user, support.getNamespace().getDataset());
user.addPermission(managed.createPermission(AbilitySets.QUERY_CREATOR));
if (managed.getState() == ExecutionState.FAILED) {
fail("Query failed");
}
}
for (JsonNode queryNode : content.getPreviousQueries()) {
ObjectMapper mapper = new SingletonNamespaceCollection(support.getNamespaceStorage().getCentralRegistry()).injectIntoNew(Jackson.MAPPER);
mapper = support.getDataset().injectIntoNew(mapper);
Query query = mapper.readerFor(Query.class).readValue(queryNode);
UUID queryId = new UUID(0L, id++);
ManagedExecution<?> managed = support.getNamespace().getExecutionManager().createQuery(support.getNamespace().getNamespaces(), query, queryId, user, support.getNamespace().getDataset());
user.addPermission(ExecutionPermission.onInstance(AbilitySets.QUERY_CREATOR, managed.getId()));
if (managed.getState() == ExecutionState.FAILED) {
fail("Query failed");
}
}
// wait only if we actually did anything
if (!content.getPreviousQueryResults().isEmpty()) {
support.waitUntilWorkDone();
}
}
use of com.bakdata.conquery.apiv1.query.ConceptQuery in project conquery by bakdata.
the class QueryProcessor method uploadEntities.
/**
* Try to resolve the external upload, if successful, create query for the subject and return id and statistics for that.
*/
public ExternalUploadResult uploadEntities(Subject subject, Dataset dataset, ExternalUpload upload) {
final CQExternal.ResolveStatistic statistic = CQExternal.resolveEntities(upload.getValues(), upload.getFormat(), datasetRegistry.get(dataset.getId()).getStorage().getIdMapping(), config.getFrontend().getQueryUpload(), config.getLocale().getDateReader());
// Resolving nothing is a problem thus we fail.
if (statistic.getResolved().isEmpty()) {
throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(new ExternalUploadResult(null, 0, statistic.getUnresolvedId(), statistic.getUnreadableDate())).build());
}
final ConceptQuery query = new ConceptQuery(new CQExternal(upload.getFormat(), upload.getValues()));
// We only create the Query, really no need to execute it as it's only useful for composition.
final ManagedQuery execution = ((ManagedQuery) datasetRegistry.get(dataset.getId()).getExecutionManager().createExecution(datasetRegistry, query, subject.getUser(), dataset));
execution.setLastResultCount((long) statistic.getResolved().size());
if (upload.getLabel() != null) {
execution.setLabel(upload.getLabel());
}
execution.initExecutable(datasetRegistry, config);
return new ExternalUploadResult(execution.getId(), statistic.getResolved().size(), statistic.getUnresolvedId(), statistic.getUnreadableDate());
}
use of com.bakdata.conquery.apiv1.query.ConceptQuery in project conquery by bakdata.
the class SerializationTests method testFormQuery.
@Test
public void testFormQuery() throws IOException, JSONException {
CQConcept concept = new CQConcept();
final TreeConcept testConcept = new TreeConcept();
Dataset dataset = new Dataset();
dataset.setName("testDataset");
testConcept.setDataset(dataset);
testConcept.setName("concept");
final ConceptTreeConnector connector = new ConceptTreeConnector();
connector.setConcept(testConcept);
connector.setName("connector1");
testConcept.setConnectors(List.of(connector));
concept.setElements(Collections.singletonList(testConcept));
CQTable[] tables = { new CQTable() };
connector.setTable(new Table());
tables[0].setConnector(connector);
tables[0].setConcept(concept);
concept.setTables(Arrays.asList(tables));
ConceptQuery subQuery = new ConceptQuery(concept);
CQOr features = new CQOr();
features.setChildren(Collections.singletonList(concept));
AbsoluteFormQuery query = new AbsoluteFormQuery(subQuery, CDateRange.exactly(LocalDate.now()).toSimpleRange(), ArrayConceptQuery.createFromFeatures(Collections.singletonList(features)), List.of(ExportForm.ResolutionAndAlignment.of(Resolution.COMPLETE, Alignment.NO_ALIGN), ExportForm.ResolutionAndAlignment.of(Resolution.QUARTERS, Alignment.QUARTER)));
CentralRegistry centralRegistry = new CentralRegistry();
centralRegistry.register(dataset);
centralRegistry.register(testConcept);
centralRegistry.register(connector);
SerializationTestUtil.forType(AbsoluteFormQuery.class).registry(centralRegistry).test(query);
}
use of com.bakdata.conquery.apiv1.query.ConceptQuery in project conquery by bakdata.
the class DefaultLabelTest method autoLabelUploadQuery.
@ParameterizedTest
@CsvSource({ "de,Hochgeladene-Liste", "en,Uploaded-List" })
void autoLabelUploadQuery(Locale locale, String autoLabel) {
I18n.LOCALE.set(locale);
CQExternal external = new CQExternal(List.of(), new String[0][0]);
ConceptQuery cq = new ConceptQuery(external);
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);
}
Aggregations