use of com.bakdata.conquery.models.identifiable.CentralRegistry in project conquery by bakdata.
the class NamespacedStorage method decorateConceptStore.
private void decorateConceptStore(IdentifiableStore<Concept<?>> store) {
store.onAdd(concept -> {
if (concept.getDataset() != null && !concept.getDataset().equals(dataset.get())) {
throw new IllegalStateException("Concept is not for this dataset.");
}
concept.setDataset(dataset.get());
concept.initElements();
concept.getSelects().forEach(centralRegistry::register);
for (Connector connector : concept.getConnectors()) {
centralRegistry.register(connector);
connector.collectAllFilters().forEach(centralRegistry::register);
connector.getSelects().forEach(centralRegistry::register);
connector.getValidityDates().forEach(centralRegistry::register);
}
// add imports of table
if (isRegisterImports()) {
for (Import imp : getAllImports()) {
for (Connector con : concept.getConnectors()) {
if (con.getTable().equals(imp.getTable())) {
con.addImport(imp);
}
}
}
}
if (concept instanceof TreeConcept) {
((TreeConcept) concept).getAllChildren().values().forEach(centralRegistry::register);
}
}).onRemove(concept -> {
concept.getSelects().forEach(centralRegistry::remove);
// see #146 remove from Dataset.concepts
for (Connector connector : concept.getConnectors()) {
connector.getSelects().forEach(centralRegistry::remove);
connector.collectAllFilters().forEach(centralRegistry::remove);
connector.getValidityDates().forEach(centralRegistry::remove);
centralRegistry.remove(connector);
}
if (concept instanceof TreeConcept) {
((TreeConcept) concept).getAllChildren().values().forEach(centralRegistry::remove);
}
});
}
use of com.bakdata.conquery.models.identifiable.CentralRegistry in project conquery by bakdata.
the class SerializationTests method group.
@Test
public void group() throws IOException, JSONException {
Group group = new Group("group", "group", STORAGE);
group.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("test")));
group.addPermission(ExecutionPermission.onInstance(Ability.READ, new ManagedExecutionId(new DatasetId("dataset"), UUID.randomUUID())));
group.addRole(new Role("company", "company", STORAGE));
Role role = new Role("company", "company", STORAGE);
group.addRole(role);
User user = new User("userName", "userLabel", STORAGE);
group.addMember(user);
CentralRegistry registry = new CentralRegistry();
registry.register(role);
registry.register(user);
SerializationTestUtil.forType(Group.class).injectables(STORAGE).registry(registry).test(group);
}
use of com.bakdata.conquery.models.identifiable.CentralRegistry in project conquery by bakdata.
the class SerializationTests method bucketCompoundDateRange.
@Test
public void bucketCompoundDateRange() throws JSONException, IOException {
Dataset dataset = new Dataset();
dataset.setName("datasetName");
Table table = new Table();
Column startCol = new Column();
startCol.setName("startCol");
startCol.setType(MajorTypeId.DATE);
startCol.setTable(table);
Column endCol = new Column();
endCol.setLabel("endLabel");
endCol.setName("endCol");
endCol.setType(MajorTypeId.DATE);
endCol.setTable(table);
Column compoundCol = new Column();
compoundCol.setName("compoundCol");
compoundCol.setType(MajorTypeId.DATE_RANGE);
compoundCol.setTable(table);
table.setColumns(new Column[] { startCol, endCol, compoundCol });
table.setDataset(dataset);
table.setName("tableName");
Import imp = new Import(table);
imp.setName("importTest");
DateRangeTypeCompound compoundStore = new DateRangeTypeCompound(startCol.getName(), endCol.getName(), new BitSetStore(BitSet.valueOf(new byte[] { 0b1000 }), new BitSet(), 4));
// 0b1000 is a binary representation of 8 so that the 4th is set to make sure that BitSet length is 4.
ColumnStore startStore = new IntegerDateStore(new ShortArrayStore(new short[] { 1, 2, 3, 4 }, Short.MIN_VALUE));
ColumnStore endStore = new IntegerDateStore(new ShortArrayStore(new short[] { 5, 6, 7, 8 }, Short.MIN_VALUE));
Bucket bucket = new Bucket(0, 1, 4, new ColumnStore[] { startStore, endStore, compoundStore }, Collections.emptySet(), new int[0], new int[0], imp);
compoundStore.setParent(bucket);
CentralRegistry registry = new CentralRegistry();
registry.register(dataset);
registry.register(startCol);
registry.register(endCol);
registry.register(compoundCol);
registry.register(table);
registry.register(imp);
registry.register(bucket);
final Validator validator = Validators.newValidator();
SerializationTestUtil.forType(Bucket.class).registry(registry).injectables(new Injectable() {
@Override
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(Validator.class, validator);
}
}).test(bucket);
}
use of com.bakdata.conquery.models.identifiable.CentralRegistry in project conquery by bakdata.
the class SerializationTests method managedQuery.
@Test
public void managedQuery() throws JSONException, IOException {
final CentralRegistry registry = new CentralRegistry();
final Dataset dataset = new Dataset("test-dataset");
final User user = new User("test-user", "test-user", STORAGE);
registry.register(dataset);
registry.register(user);
ManagedQuery execution = new ManagedQuery(null, user, dataset);
execution.setTags(new String[] { "test-tag" });
SerializationTestUtil.forType(ManagedExecution.class).registry(registry).test(execution);
}
use of com.bakdata.conquery.models.identifiable.CentralRegistry in project conquery by bakdata.
the class GroovyIndexedTest method init.
@BeforeAll
public static void init() throws IOException, JSONException, ConfigurationException {
ObjectNode node = Jackson.MAPPER.readerFor(ObjectNode.class).readValue(In.resource(GroovyIndexedTest.class, CONCEPT_SOURCE).asStream());
// load concept tree from json
CentralRegistry registry = new CentralRegistry();
Table table = new Table();
table.setName("the_table");
Dataset dataset = new Dataset();
dataset.setName("the_dataset");
registry.register(dataset);
table.setDataset(dataset);
Column column = new Column();
column.setName("the_column");
column.setType(MajorTypeId.STRING);
table.setColumns(new Column[] { column });
column.setTable(table);
registry.register(table);
registry.register(column);
// Prepare Serdes injections
final Validator validator = Validators.newValidator();
final ObjectReader conceptReader = new Injectable() {
@Override
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(Validator.class, validator);
}
}.injectInto(registry.injectIntoNew(dataset.injectIntoNew(Jackson.MAPPER))).readerFor(Concept.class);
// load tree twice to to avoid references
indexedConcept = conceptReader.readValue(node);
indexedConcept.setDataset(dataset);
indexedConcept.initElements();
TreeChildPrefixIndex.putIndexInto(indexedConcept);
oldConcept = conceptReader.readValue(node);
oldConcept.setDataset(dataset);
oldConcept.initElements();
}
Aggregations