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);
}
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);
}
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);
}
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);
}
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;
}
}
Aggregations