Search in sources :

Example 1 with ConceptQuery

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);
}
Also used : CQDateRestriction(com.bakdata.conquery.apiv1.query.concept.specific.CQDateRestriction) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) FilterValue(com.bakdata.conquery.apiv1.query.concept.filter.FilterValue)

Example 2 with ConceptQuery

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();
    }
}
Also used : ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) Query(com.bakdata.conquery.apiv1.query.Query) SingletonNamespaceCollection(com.bakdata.conquery.models.worker.SingletonNamespaceCollection) CsvParser(com.univocity.parsers.csv.CsvParser) CQExternal(com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal) JsonNode(com.fasterxml.jackson.databind.JsonNode) UUID(java.util.UUID) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with ConceptQuery

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());
}
Also used : ExternalUploadResult(com.bakdata.conquery.apiv1.query.ExternalUploadResult) BadRequestException(javax.ws.rs.BadRequestException) CQExternal(com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery)

Example 4 with ConceptQuery

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);
}
Also used : CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) Table(com.bakdata.conquery.models.datasets.Table) Dataset(com.bakdata.conquery.models.datasets.Dataset) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) ConceptTreeConnector(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) ArrayConceptQuery(com.bakdata.conquery.apiv1.query.ArrayConceptQuery) AbsoluteFormQuery(com.bakdata.conquery.models.forms.managed.AbsoluteFormQuery) CQOr(com.bakdata.conquery.apiv1.query.concept.specific.CQOr) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Example 5 with ConceptQuery

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);
}
Also used : CQExternal(com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)20 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)16 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)10 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)8 Test (org.junit.jupiter.api.Test)7 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 CQExternal (com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal)5 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)4 Dataset (com.bakdata.conquery.models.datasets.Dataset)4 ArrayConceptQuery (com.bakdata.conquery.apiv1.query.ArrayConceptQuery)2 FilterValue (com.bakdata.conquery.apiv1.query.concept.filter.FilterValue)2 Table (com.bakdata.conquery.models.datasets.Table)2 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)2 UUID (java.util.UUID)2 FullExecutionStatus (com.bakdata.conquery.apiv1.FullExecutionStatus)1 FeatureGroup (com.bakdata.conquery.apiv1.forms.FeatureGroup)1 ExternalUploadResult (com.bakdata.conquery.apiv1.query.ExternalUploadResult)1 Query (com.bakdata.conquery.apiv1.query.Query)1