Search in sources :

Example 6 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.

the class SerializingStoreDumpTest method testCorruptKeyDump.

/**
 * Tests if entries with corrupted keys are dumped.
 */
@Test
public void testCorruptKeyDump() throws IOException {
    // Set dump directory to this tests temp-dir
    config.setUnreadableDataDumpDirectory(tmpDir);
    {
        // Open a store and insert a valid key-value pair (UserId & User)
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        store.add(new UserId("testU1"), user);
    }
    {
        // Open that store again, with a different config to insert a corrupt entry
        // (String & ManagedQuery)
        SerializingStore<String, QueryDescription> store = createSerializedStore(config, env, Validators.newValidator(), new StoreInfo<>(USER_STORE_ID.getName(), String.class, QueryDescription.class));
        store.add("not a valid conquery Id", cQuery);
    }
    {
        // Reopen the store with the initial value and try to iterate over all entries
        // (this triggers the dump or removal of invalid entries)
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        IterationStatistic expectedResult = new IterationStatistic();
        expectedResult.setTotalProcessed(2);
        expectedResult.setFailedKeys(1);
        expectedResult.setFailedValues(0);
        // Iterate (do nothing with the entries themselves)
        IterationStatistic result = store.forEach((k, v, s) -> {
        });
        assertThat(result).isEqualTo(expectedResult);
    }
    // Test if the correct number of dumpfiles was generated
    Condition<File> dumpFileCond = new Condition<>(f -> f.getName().endsWith(SerializingStore.DUMP_FILE_EXTENTION), "dump file");
    assertThat(tmpDir.listFiles()).areExactly(1, dumpFileCond);
    // Test if the dump is correct
    File dumpFile = getDumpFile(dumpFileCond);
    assertThat((QueryDescription) Jackson.MAPPER.readerFor(QueryDescription.class).readValue(dumpFile)).isEqualTo(cQuery);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Validators(io.dropwizard.jersey.validation.Validators) Environments(jetbrains.exodus.env.Environments) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) StoreMappings(com.bakdata.conquery.io.storage.StoreMappings) Environment(jetbrains.exodus.env.Environment) Files(com.google.common.io.Files) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) Validator(javax.validation.Validator) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) User(com.bakdata.conquery.models.auth.entities.User) File(java.io.File) Dataset(com.bakdata.conquery.models.datasets.Dataset) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) Slf4j(lombok.extern.slf4j.Slf4j) AfterEach(org.junit.jupiter.api.AfterEach) Condition(org.assertj.core.api.Condition) CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) Jackson(com.bakdata.conquery.io.jackson.Jackson) XodusStoreFactory(com.bakdata.conquery.models.config.XodusStoreFactory) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) Condition(org.assertj.core.api.Condition) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 7 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery 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)

Example 8 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.

the class DefaultLabelTest method autoLabelComplexQuery.

@ParameterizedTest
@CsvSource({ "de,Hochgeladene-Liste Anfrage Concept1 Concept2 und weitere", "en,Uploaded-List Query Concept1 Concept2 and further" })
void autoLabelComplexQuery(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 = makeCQConcept("Concept1");
    CQConcept concept2 = makeCQConcept("Concept2");
    CQConcept concept3 = makeCQConcept("Concept3veryveryveryveryveryveryveryverylooooooooooooooooooooonglabel");
    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);
}
Also used : CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) CQExternal(com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) CQAnd(com.bakdata.conquery.apiv1.query.concept.specific.CQAnd) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.

the class PermissionCleanupTaskTest method doDeletePermissionsOfOwnedReference.

@Test
void doDeletePermissionsOfOwnedReference() {
    assertThat(STORAGE.getAllExecutions()).isEmpty();
    // Created owned execution
    final ManagedQuery managedQueryOwned = createManagedQuery();
    // Setup user
    User user = new User("test", "test", STORAGE);
    User user2 = new User("test2", "test2", STORAGE);
    STORAGE.updateUser(user);
    user.addPermission(ExecutionPermission.onInstance(AbilitySets.QUERY_CREATOR, managedQueryOwned.getId()));
    managedQueryOwned.setOwner(user);
    STORAGE.updateExecution(managedQueryOwned);
    // Created not owned execution
    final ManagedQuery managedQueryNotOwned = createManagedQuery();
    // Setup user
    user.addPermission(ExecutionPermission.onInstance(Ability.READ, managedQueryNotOwned.getId()));
    // Set owner
    managedQueryNotOwned.setOwner(user2);
    STORAGE.updateExecution(managedQueryNotOwned);
    deletePermissionsOfOwnedInstances(STORAGE, ExecutionPermission.DOMAIN.toLowerCase(), ManagedExecutionId.Parser.INSTANCE, STORAGE::getExecution);
    assertThat(user.getPermissions()).containsOnly(ExecutionPermission.onInstance(Ability.READ, managedQueryNotOwned.getId()));
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Test(org.junit.jupiter.api.Test)

Example 10 with ManagedQuery

use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.

the class PermissionCleanupTaskTest method doDeletePartialPermissionWithInvalidReference.

@Test
void doDeletePartialPermissionWithInvalidReference() {
    assertThat(STORAGE.getAllExecutions()).isEmpty();
    final ManagedQuery managedQuery1 = createManagedQuery();
    final ManagedQuery managedQuery2 = createManagedQuery();
    // Removing the second execution
    STORAGE.removeExecution(managedQuery2.getId());
    User user = new User("test", "test", STORAGE);
    STORAGE.updateUser(user);
    user.addPermission(// Build a permission with multiple instances
    new WildcardPermission(List.of(Set.of(ExecutionPermission.DOMAIN), Set.of(Ability.READ.toString().toLowerCase()), Set.of(managedQuery1.getId().toString(), managedQuery2.getId().toString())), Instant.now()));
    deleteQueryPermissionsWithMissingRef(STORAGE, STORAGE.getAllUsers());
    assertThat(user.getPermissions()).containsOnly(ExecutionPermission.onInstance(Ability.READ, managedQuery1.getId()));
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) WildcardPermission(com.bakdata.conquery.models.auth.permissions.WildcardPermission) Test(org.junit.jupiter.api.Test)

Aggregations

ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)37 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)18 Test (org.junit.jupiter.api.Test)18 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)13 User (com.bakdata.conquery.models.auth.entities.User)12 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)8 Dataset (com.bakdata.conquery.models.datasets.Dataset)8 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 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)5 List (java.util.List)5 Slf4j (lombok.extern.slf4j.Slf4j)5 CQExternal (com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal)4 ManagedExecutionId (com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId)4 PrintSettings (com.bakdata.conquery.models.query.PrintSettings)4 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)3 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)3 I18n (com.bakdata.conquery.models.i18n.I18n)3 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)3