Search in sources :

Example 6 with CentralRegistry

use of com.bakdata.conquery.models.identifiable.CentralRegistry in project conquery by bakdata.

the class SerializationTests method cqConcept.

@Test
public void cqConcept() throws JSONException, IOException {
    final Dataset dataset = new Dataset();
    dataset.setName("dataset");
    final TreeConcept concept = new TreeConcept();
    concept.setName("concept");
    concept.setDataset(dataset);
    final ConceptTreeConnector connector = new ConceptTreeConnector();
    connector.setConcept(concept);
    concept.setConnectors(List.of(connector));
    final CQConcept cqConcept = new CQConcept();
    cqConcept.setElements(List.of(concept));
    cqConcept.setLabel("Label");
    final CQTable cqTable = new CQTable();
    cqTable.setConnector(connector);
    cqTable.setFilters(List.of());
    cqTable.setConcept(cqConcept);
    cqConcept.setTables(List.of(cqTable));
    final CentralRegistry registry = new CentralRegistry();
    registry.register(dataset);
    registry.register(concept);
    registry.register(connector);
    SerializationTestUtil.forType(CQConcept.class).registry(registry).test(cqConcept);
}
Also used : 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) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Example 7 with CentralRegistry

use of com.bakdata.conquery.models.identifiable.CentralRegistry 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 8 with CentralRegistry

use of com.bakdata.conquery.models.identifiable.CentralRegistry in project conquery by bakdata.

the class SuccinctTrieTest method serializationTest.

@Test
public void serializationTest() throws IOException, JSONException {
    final CentralRegistry registry = new CentralRegistry();
    registry.register(Dataset.PLACEHOLDER);
    SuccinctTrie dict = new SuccinctTrie(Dataset.PLACEHOLDER, "testDict");
    data().forEach(value -> dict.put(value.getBytes()));
    dict.compress();
    SerializationTestUtil.forType(Dictionary.class).registry(registry).test(dict);
}
Also used : CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with CentralRegistry

use of com.bakdata.conquery.models.identifiable.CentralRegistry in project conquery by bakdata.

the class MapDictionaryTest method testSerializationAsList.

@Test
void testSerializationAsList() throws IOException, JSONException {
    MapDictionary map = new MapDictionary(Dataset.PLACEHOLDER, "dictionary");
    map.add("a".getBytes());
    map.add("b".getBytes());
    map.add("c".getBytes());
    final CentralRegistry registry = new CentralRegistry();
    registry.register(Dataset.PLACEHOLDER);
    String json = Jackson.MAPPER.writeValueAsString(map);
    assertThat(json).startsWith("{\"type\":\"MAP_DICTIONARY\",\"dataset\":\"PLACEHOLDER\",\"name\":\"dictionary\",\"id2Value\":[").endsWith("]}");
    SerializationTestUtil.forType(MapDictionary.class).registry(registry).test(map);
}
Also used : CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Test(org.junit.jupiter.api.Test)

Example 10 with CentralRegistry

use of com.bakdata.conquery.models.identifiable.CentralRegistry in project conquery by bakdata.

the class MetaIdReferenceDeserializer method deserialize.

@SuppressWarnings("unchecked")
@Override
public T deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException {
    if (parser.getCurrentToken() != JsonToken.VALUE_STRING) {
        return (T) ctxt.handleUnexpectedToken(type, parser.getCurrentToken(), parser, "name references should be strings");
    }
    ID id = ctxt.readValue(parser, idClass);
    try {
        final CentralRegistry centralRegistry = CentralRegistry.get(ctxt);
        // Not all Components have registries, we leave it up to the validator to be angry.
        if (centralRegistry == null) {
            return null;
        }
        Optional<T> result = centralRegistry.getOptional(id);
        if (result.isEmpty()) {
            throw new IdReferenceResolvingException(parser, "Could not find entry `" + id + "` of type " + type.getName(), id.toString(), type);
        }
        if (!type.isAssignableFrom(result.get().getClass())) {
            throw new InputMismatchException(String.format("Cannot assign type %s to %s ", result.get().getClass(), type));
        }
        return result.get();
    } catch (Exception e) {
        log.error("Error while resolving entry {} of type {}", id, type, e);
        throw e;
    }
}
Also used : CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) InputMismatchException(java.util.InputMismatchException) IOException(java.io.IOException) InputMismatchException(java.util.InputMismatchException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Aggregations

CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)17 Test (org.junit.jupiter.api.Test)13 Dataset (com.bakdata.conquery.models.datasets.Dataset)12 IdMapSerialisationTest (com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)9 Table (com.bakdata.conquery.models.datasets.Table)8 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)6 User (com.bakdata.conquery.models.auth.entities.User)5 Column (com.bakdata.conquery.models.datasets.Column)5 TreeConcept (com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept)5 Validator (javax.validation.Validator)5 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)4 Injectable (com.bakdata.conquery.io.jackson.Injectable)4 MutableInjectableValues (com.bakdata.conquery.io.jackson.MutableInjectableValues)4 ConceptTreeConnector (com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector)4 Import (com.bakdata.conquery.models.datasets.Import)3 ManagedExecutionId (com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId)3 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)2 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)2 Role (com.bakdata.conquery.models.auth.entities.Role)2 Concept (com.bakdata.conquery.models.datasets.concepts.Concept)2