Search in sources :

Example 16 with CQConcept

use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.

the class FormConfigTest method getConfigs.

@Test
public void getConfigs() {
    // PREPARE
    user.addPermission(dataset.createPermission(Ability.READ.asSet()));
    user.addPermission(FormPermission.onInstance(Ability.CREATE, form.getFormType()));
    ExportForm form2 = new ExportForm();
    RelativeMode mode3 = new RelativeMode();
    form2.setTimeMode(mode3);
    mode3.setForm(form);
    mode3.setFeatures(List.of(new CQConcept()));
    mode3.setOutcomes(List.of(new CQConcept()));
    TestForm form3 = new TestForm();
    ObjectMapper mapper = FormConfigProcessor.getMAPPER();
    FormConfigAPI formConfig = FormConfigAPI.builder().formType(form.getFormType()).values(mapper.valueToTree(form)).build();
    FormConfigAPI formConfig2 = FormConfigAPI.builder().formType(form2.getFormType()).values(mapper.valueToTree(form2)).build();
    // This should not be retrieved by the user because it does not hold the Permission to create TestForms
    FormConfigAPI formConfig3 = FormConfigAPI.builder().formType(form3.getFormType()).values(mapper.valueToTree(form2)).build();
    FormConfigId formId = processor.addConfig(user, dataset, formConfig).getId();
    FormConfigId formId2 = processor.addConfig(user, dataset, formConfig2).getId();
    FormConfigId _formId3 = processor.addConfig(user, dataset, formConfig3).getId();
    FormScanner.FRONTEND_FORM_CONFIGS = Map.of(form.getFormType(), new FormType(form.getFormType(), new TextNode("dummy")));
    // EXECUTE
    Stream<FormConfigOverviewRepresentation> response = processor.getConfigsByFormType(user, dataset, Collections.emptySet());
    // CHECK
    assertThat(response).containsExactlyInAnyOrder(FormConfigOverviewRepresentation.builder().formType(form.getClass().getAnnotation(CPSType.class).id()).id(formId).label(formConfig.getLabel()).own(true).ownerName(user.getLabel()).shared(false).system(false).tags(formConfig.getTags()).createdAt(formConfig.getCreationTime().atZone(ZoneId.systemDefault())).build(), FormConfigOverviewRepresentation.builder().formType(form2.getClass().getAnnotation(CPSType.class).id()).id(formId2).label(formConfig2.getLabel()).own(true).ownerName(user.getLabel()).shared(false).system(false).tags(formConfig2.getTags()).createdAt(formConfig2.getCreationTime().atZone(ZoneId.systemDefault())).build());
}
Also used : FormConfigAPI(com.bakdata.conquery.apiv1.forms.FormConfigAPI) FormConfigOverviewRepresentation(com.bakdata.conquery.models.forms.configs.FormConfig.FormConfigOverviewRepresentation) FormType(com.bakdata.conquery.models.forms.frontendconfiguration.FormType) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) TextNode(com.fasterxml.jackson.databind.node.TextNode) ExportForm(com.bakdata.conquery.apiv1.forms.export_form.ExportForm) FormConfigId(com.bakdata.conquery.models.identifiable.ids.specific.FormConfigId) RelativeMode(com.bakdata.conquery.apiv1.forms.export_form.RelativeMode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 17 with CQConcept

use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.

the class FormConfigTest method setupTest.

@BeforeEach
public void setupTest() {
    final ManagedQuery managedQuery = new ManagedQuery(null, null, dataset);
    managedQuery.setQueryId(UUID.randomUUID());
    form = new ExportForm();
    AbsoluteMode mode = new AbsoluteMode();
    form.setTimeMode(mode);
    form.setQueryGroupId(managedQuery.getId());
    mode.setForm(form);
    mode.setFeatures(List.of(new CQConcept()));
    user = new User("test", "test", storage);
    storage.addUser(user);
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) AbsoluteMode(com.bakdata.conquery.apiv1.forms.export_form.AbsoluteMode) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ExportForm(com.bakdata.conquery.apiv1.forms.export_form.ExportForm) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with CQConcept

use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.

the class ReusedQueryTest method execute.

@Override
public void execute(String name, TestConquery testConquery) throws Exception {
    final StandaloneSupport conquery = testConquery.getSupport(name);
    final String testJson = In.resource("/tests/query/SECONDARY_ID_MIXED/SECONDARY_IDS_MIXED.test.json").withUTF8().readAll();
    final Dataset dataset = conquery.getDataset();
    final QueryTest test = (QueryTest) JsonIntegrationTest.readJson(dataset, testJson);
    // Manually import data, so we can do our own work.
    {
        ValidatorHelper.failOnError(log, conquery.getValidator().validate(test));
        importSecondaryIds(conquery, test.getContent().getSecondaryIds());
        conquery.waitUntilWorkDone();
        LoadingUtil.importTables(conquery, test.getContent().getTables());
        conquery.waitUntilWorkDone();
        LoadingUtil.importConcepts(conquery, test.getRawConcepts());
        conquery.waitUntilWorkDone();
        LoadingUtil.importTableContents(conquery, test.getContent().getTables());
        conquery.waitUntilWorkDone();
    }
    final SecondaryIdQuery query = (SecondaryIdQuery) IntegrationUtils.parseQuery(conquery, test.getRawQuery());
    final ManagedExecutionId id = IntegrationUtils.assertQueryResult(conquery, query, 4L, ExecutionState.DONE, conquery.getTestUser(), 201);
    assertThat(id).isNotNull();
    final MetaStorage metaStorage = conquery.getMetaStorage();
    final ManagedQuery execution = (ManagedQuery) metaStorage.getExecution(id);
    // Normal reuse
    {
        final ConceptQuery reused = new ConceptQuery(new CQReusedQuery(execution.getId()));
        IntegrationUtils.assertQueryResult(conquery, reused, 2L, ExecutionState.DONE, conquery.getTestUser(), 201);
    }
    // Reuse by API
    {
        final URI reexecuteUri = HierarchyHelper.hierarchicalPath(conquery.defaultApiURIBuilder(), QueryResource.class, "reexecute").buildFromMap(Map.of(ResourceConstants.DATASET, conquery.getDataset().getName(), ResourceConstants.QUERY, execution.getId().toString()));
        final FullExecutionStatus status = conquery.getClient().target(reexecuteUri).request(MediaType.APPLICATION_JSON).post(Entity.entity(null, MediaType.APPLICATION_JSON_TYPE)).readEntity(FullExecutionStatus.class);
        assertThat(status.getStatus()).isIn(ExecutionState.RUNNING, ExecutionState.DONE);
    }
    // Reuse in SecondaryId
    {
        final SecondaryIdQuery reused = new SecondaryIdQuery();
        reused.setRoot(new CQReusedQuery(execution.getId()));
        reused.setSecondaryId(query.getSecondaryId());
        IntegrationUtils.assertQueryResult(conquery, reused, 4L, ExecutionState.DONE, conquery.getTestUser(), 201);
    }
    // Reuse in SecondaryId, but do exclude
    {
        final SecondaryIdQuery reused = new SecondaryIdQuery();
        final CQAnd root = new CQAnd();
        reused.setRoot(root);
        final CQReusedQuery reuse = new CQReusedQuery(execution.getId());
        reuse.setExcludeFromSecondaryId(true);
        // We select only a single event of the query by the exact filtering.
        final CQConcept cqConcept = new CQConcept();
        final ConceptId conceptId = new ConceptId(conquery.getDataset().getId(), "concept");
        final Concept<?> concept = conquery.getNamespaceStorage().getConcept(conceptId);
        cqConcept.setElements(List.of(concept));
        final CQTable cqTable = new CQTable();
        cqTable.setConcept(cqConcept);
        final CentralRegistry centralRegistry = conquery.getNamespaceStorage().getCentralRegistry();
        final Connector connector = centralRegistry.resolve(new ConnectorId(conceptId, "connector1"));
        cqTable.setConnector(connector);
        cqTable.setFilters(List.of(new FilterValue.CQRealRangeFilter((Filter<Range<BigDecimal>>) centralRegistry.resolve(new FilterId(connector.getId(), "filter")), new Range<>(BigDecimal.valueOf(1.01d), BigDecimal.valueOf(1.01d)))));
        cqConcept.setTables(List.of(cqTable));
        cqConcept.setExcludeFromSecondaryId(false);
        root.setChildren(List.of(reuse, cqConcept));
        reused.setSecondaryId(query.getSecondaryId());
        IntegrationUtils.assertQueryResult(conquery, reused, 1L, ExecutionState.DONE, conquery.getTestUser(), 201);
    }
    // Reuse Multiple times with different query types
    {
        final SecondaryIdQuery reused1 = new SecondaryIdQuery();
        reused1.setRoot(new CQReusedQuery(execution.getId()));
        reused1.setSecondaryId(query.getSecondaryId());
        final ManagedExecutionId reused1Id = IntegrationUtils.assertQueryResult(conquery, reused1, 4L, ExecutionState.DONE, conquery.getTestUser(), 201);
        final ManagedQuery execution1 = (ManagedQuery) metaStorage.getExecution(reused1Id);
        {
            final SecondaryIdQuery reused2 = new SecondaryIdQuery();
            reused2.setRoot(new CQReusedQuery(execution1.getId()));
            reused2.setSecondaryId(query.getSecondaryId());
            final ManagedExecutionId reused2Id = IntegrationUtils.assertQueryResult(conquery, reused2, 4L, ExecutionState.DONE, conquery.getTestUser(), 201);
            final ManagedQuery execution2 = (ManagedQuery) metaStorage.getExecution(reused2Id);
            assertThat(reused2Id).as("Query should be reused.").isEqualTo(reused1Id);
            // Now we change to ConceptQuery
            final ConceptQuery reused3 = new ConceptQuery(new CQReusedQuery(execution2.getId()));
            IntegrationUtils.assertQueryResult(conquery, reused3, 2L, ExecutionState.DONE, conquery.getTestUser(), 201);
        }
        {
            final SecondaryIdQuery reusedDiffId = new SecondaryIdQuery();
            reusedDiffId.setRoot(new CQReusedQuery(execution1.getId()));
            // ignored is a single global value and therefore the same as by-PID
            reusedDiffId.setSecondaryId(conquery.getNamespace().getStorage().getSecondaryId(new SecondaryIdDescriptionId(conquery.getDataset().getId(), "ignored")));
            final ManagedExecutionId executionId = IntegrationUtils.assertQueryResult(conquery, reusedDiffId, 2L, ExecutionState.DONE, conquery.getTestUser(), 201);
            assertThat(executionId).as("Query should NOT be reused.").isNotEqualTo(reused1Id);
        }
        {
            // Reuse by another user (create a copy of the actual query)
            final SecondaryIdQuery reused = new SecondaryIdQuery();
            reused.setRoot(new CQReusedQuery(execution.getId()));
            reused.setSecondaryId(query.getSecondaryId());
            User shareHolder = new User("shareholder", "ShareHolder", conquery.getMetaStorage());
            conquery.getMetaProcessor().addUser(shareHolder);
            shareHolder.addPermissions(Set.of(dataset.createPermission(Set.of(Ability.READ)), execution.createPermission(Set.of(Ability.READ))));
            ManagedExecutionId copyId = IntegrationUtils.assertQueryResult(conquery, reused, 4L, ExecutionState.DONE, shareHolder, 201);
            ManagedExecution<?> copy = metaStorage.getExecution(copyId);
            // Contentwise the label and tags should be the same
            assertThat(copy).usingRecursiveComparison().comparingOnlyFields("label", "tags").isEqualTo(execution);
            // However the Object holding the tags must be different, so the two are not linked here
            assertThat(copy.getTags()).isNotSameAs(execution.getTags());
            // And the ids must be different
            assertThat(copy.getId()).isNotSameAs(execution.getId());
        }
    }
}
Also used : Connector(com.bakdata.conquery.models.datasets.concepts.Connector) User(com.bakdata.conquery.models.auth.entities.User) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) URI(java.net.URI) FilterId(com.bakdata.conquery.models.identifiable.ids.specific.FilterId) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) CQAnd(com.bakdata.conquery.apiv1.query.concept.specific.CQAnd) ConnectorId(com.bakdata.conquery.models.identifiable.ids.specific.ConnectorId) Concept(com.bakdata.conquery.models.datasets.concepts.Concept) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) SecondaryIdDescriptionId(com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId) CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) QueryTest(com.bakdata.conquery.integration.json.QueryTest) Dataset(com.bakdata.conquery.models.datasets.Dataset) Range(com.bakdata.conquery.models.common.Range) FullExecutionStatus(com.bakdata.conquery.apiv1.FullExecutionStatus) BigDecimal(java.math.BigDecimal) ConceptId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptId) FilterValue(com.bakdata.conquery.apiv1.query.concept.filter.FilterValue) Filter(com.bakdata.conquery.models.datasets.concepts.filters.Filter) SecondaryIdQuery(com.bakdata.conquery.apiv1.query.SecondaryIdQuery) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) StandaloneSupport(com.bakdata.conquery.util.support.StandaloneSupport) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery)

Aggregations

CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)18 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)8 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)7 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)6 Test (org.junit.jupiter.api.Test)6 Dataset (com.bakdata.conquery.models.datasets.Dataset)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ExportForm (com.bakdata.conquery.apiv1.forms.export_form.ExportForm)3 CQAnd (com.bakdata.conquery.apiv1.query.concept.specific.CQAnd)3 CQExternal (com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal)3 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)3 ResultType (com.bakdata.conquery.models.externalservice.ResultType)3 I18n (com.bakdata.conquery.models.i18n.I18n)3 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)3 IdMapSerialisationTest (com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)3 UniqueNamer (com.bakdata.conquery.models.query.resultinfo.UniqueNamer)3 CsvSource (org.junit.jupiter.params.provider.CsvSource)3