Search in sources :

Example 1 with SingletonNamespaceCollection

use of com.bakdata.conquery.models.worker.SingletonNamespaceCollection in project conquery by bakdata.

the class ConqueryTestSpec method parseSubTreeList.

public static <T> List<T> parseSubTreeList(StandaloneSupport support, ArrayNode node, Class<?> expectedType, Consumer<T> modifierBeforeValidation) throws IOException, JSONException {
    ObjectMapper mapper = support.getDataset().injectIntoNew(new SingletonNamespaceCollection(support.getNamespace().getStorage().getCentralRegistry()).injectIntoNew(Jackson.MAPPER.copy().addHandler(new DatasetPlaceHolderFiller(support))));
    List<T> result = new ArrayList<>(node.size());
    for (var child : node) {
        T value;
        try {
            value = mapper.readerFor(expectedType).readValue(child);
        } catch (Exception e) {
            if (child.isValueNode()) {
                String potentialPath = child.textValue();
                try {
                    value = mapper.readerFor(expectedType).readValue(IntegrationTest.class.getResource(potentialPath));
                } catch (Exception e2) {
                    throw new RuntimeException("Could not parse value " + potentialPath, e2);
                }
            } else {
                throw e;
            }
        }
        if (modifierBeforeValidation != null) {
            modifierBeforeValidation.accept(value);
        }
        result.add(value);
        ValidatorHelper.failOnError(log, support.getValidator().validate(value));
    }
    return result;
}
Also used : SingletonNamespaceCollection(com.bakdata.conquery.models.worker.SingletonNamespaceCollection) ArrayList(java.util.ArrayList) IntegrationTest(com.bakdata.conquery.integration.IntegrationTest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JSONException(com.bakdata.conquery.models.exceptions.JSONException) IOException(java.io.IOException)

Example 2 with SingletonNamespaceCollection

use of com.bakdata.conquery.models.worker.SingletonNamespaceCollection 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 SingletonNamespaceCollection

use of com.bakdata.conquery.models.worker.SingletonNamespaceCollection in project conquery by bakdata.

the class IdRefrenceTest method testListReferences.

@Test
public void testListReferences() throws IOException {
    CentralRegistry registry = new CentralRegistry();
    Dataset dataset = new Dataset();
    dataset.setName("dataset");
    Table table = new Table();
    table.setDataset(dataset);
    table.setName("table");
    registry.register(dataset);
    registry.register(table);
    final CentralRegistry metaRegistry = new CentralRegistry();
    User user = new User("usermail", "userlabel", mock(MetaStorage.class));
    metaRegistry.register(user);
    String json = Jackson.MAPPER.writeValueAsString(new ListHolder(Collections.singletonList(table), Collections.singletonList(user)));
    assertThat(json).contains("\"user.usermail\"").contains("\"dataset.table\"");
    ListHolder holder = new SingletonNamespaceCollection(registry, metaRegistry).injectIntoNew(Jackson.MAPPER.readerFor(ListHolder.class)).readValue(json);
    assertThat(holder.getUsers().get(0)).isSameAs(user);
    assertThat(holder.getTables().get(0)).isSameAs(table);
}
Also used : Table(com.bakdata.conquery.models.datasets.Table) User(com.bakdata.conquery.models.auth.entities.User) Dataset(com.bakdata.conquery.models.datasets.Dataset) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) SingletonNamespaceCollection(com.bakdata.conquery.models.worker.SingletonNamespaceCollection) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Test(org.junit.jupiter.api.Test)

Example 4 with SingletonNamespaceCollection

use of com.bakdata.conquery.models.worker.SingletonNamespaceCollection in project conquery by bakdata.

the class SerializationTestUtil method test.

private void test(T value, T expected, ObjectMapper mapper) throws IOException {
    if (registry != null) {
        mapper = new SingletonNamespaceCollection(registry, registry).injectIntoNew(mapper);
    }
    for (Injectable injectable : injectables) {
        mapper = injectable.injectIntoNew(mapper);
    }
    ObjectWriter writer = mapper.writerFor(type).withView(InternalOnly.class);
    ObjectReader reader = mapper.readerFor(type).withView(InternalOnly.class);
    ValidatorHelper.failOnError(log, validator.validate(value));
    byte[] src = writer.writeValueAsBytes(value);
    T copy = reader.readValue(src);
    if (expected == null && copy == null) {
        return;
    }
    ValidatorHelper.failOnError(log, validator.validate(copy));
    // because IdentifiableImp cashes the hash
    if (value instanceof IdentifiableImpl) {
        assertThat(copy.hashCode()).isEqualTo(value.hashCode());
    }
    RecursiveComparisonAssert<?> ass = assertThat(copy).as("Unequal after copy.").usingRecursiveComparison();
    ass.isEqualTo(expected);
}
Also used : Injectable(com.bakdata.conquery.io.jackson.Injectable) SingletonNamespaceCollection(com.bakdata.conquery.models.worker.SingletonNamespaceCollection) IdentifiableImpl(com.bakdata.conquery.models.identifiable.IdentifiableImpl) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Example 5 with SingletonNamespaceCollection

use of com.bakdata.conquery.models.worker.SingletonNamespaceCollection in project conquery by bakdata.

the class ConqueryTestSpec method parseSubTree.

public static <T> T parseSubTree(StandaloneSupport support, JsonNode node, JavaType expectedType, Consumer<T> modifierBeforeValidation) throws IOException, JSONException {
    ObjectMapper mapper = support.getDataset().injectIntoNew(new SingletonNamespaceCollection(support.getNamespace().getStorage().getCentralRegistry(), support.getMetaStorage().getCentralRegistry()).injectIntoNew(Jackson.MAPPER.copy().addHandler(new DatasetPlaceHolderFiller(support))));
    T result = mapper.readerFor(expectedType).readValue(node);
    if (modifierBeforeValidation != null) {
        modifierBeforeValidation.accept(result);
    }
    ValidatorHelper.failOnError(log, support.getValidator().validate(result));
    return result;
}
Also used : SingletonNamespaceCollection(com.bakdata.conquery.models.worker.SingletonNamespaceCollection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

SingletonNamespaceCollection (com.bakdata.conquery.models.worker.SingletonNamespaceCollection)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)1 Query (com.bakdata.conquery.apiv1.query.Query)1 CQExternal (com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal)1 IntegrationTest (com.bakdata.conquery.integration.IntegrationTest)1 Injectable (com.bakdata.conquery.io.jackson.Injectable)1 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)1 User (com.bakdata.conquery.models.auth.entities.User)1 Dataset (com.bakdata.conquery.models.datasets.Dataset)1 Table (com.bakdata.conquery.models.datasets.Table)1 JSONException (com.bakdata.conquery.models.exceptions.JSONException)1 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)1 IdentifiableImpl (com.bakdata.conquery.models.identifiable.IdentifiableImpl)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 CsvParser (com.univocity.parsers.csv.CsvParser)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1