use of com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept in project conquery by bakdata.
the class SerializationTests method testFormQuery.
@Test
public void testFormQuery() throws IOException, JSONException {
CQConcept concept = new CQConcept();
final TreeConcept testConcept = new TreeConcept();
Dataset dataset = new Dataset();
dataset.setName("testDataset");
testConcept.setDataset(dataset);
testConcept.setName("concept");
final ConceptTreeConnector connector = new ConceptTreeConnector();
connector.setConcept(testConcept);
connector.setName("connector1");
testConcept.setConnectors(List.of(connector));
concept.setElements(Collections.singletonList(testConcept));
CQTable[] tables = { new CQTable() };
connector.setTable(new Table());
tables[0].setConnector(connector);
tables[0].setConcept(concept);
concept.setTables(Arrays.asList(tables));
ConceptQuery subQuery = new ConceptQuery(concept);
CQOr features = new CQOr();
features.setChildren(Collections.singletonList(concept));
AbsoluteFormQuery query = new AbsoluteFormQuery(subQuery, CDateRange.exactly(LocalDate.now()).toSimpleRange(), ArrayConceptQuery.createFromFeatures(Collections.singletonList(features)), List.of(ExportForm.ResolutionAndAlignment.of(Resolution.COMPLETE, Alignment.NO_ALIGN), ExportForm.ResolutionAndAlignment.of(Resolution.QUARTERS, Alignment.QUARTER)));
CentralRegistry centralRegistry = new CentralRegistry();
centralRegistry.register(dataset);
centralRegistry.register(testConcept);
centralRegistry.register(connector);
SerializationTestUtil.forType(AbsoluteFormQuery.class).registry(centralRegistry).test(query);
}
use of com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept 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.datasets.concepts.tree.TreeConcept in project conquery by bakdata.
the class CBlockDeserializer method deserialize.
@Override
public CBlock deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
CBlock block = beanDeserializer.deserialize(p, ctxt);
TreeConcept concept = block.getConnector().getConcept();
if (block.getMostSpecificChildren() != null) {
// deduplicate concrete paths after loading from disk.
for (int event = 0; event < block.getMostSpecificChildren().length; event++) {
int[] mostSpecificChildren = block.getMostSpecificChildren()[event];
if (mostSpecificChildren == null || Connector.isNotContained(mostSpecificChildren)) {
block.getMostSpecificChildren()[event] = Connector.NOT_CONTAINED;
continue;
}
log.trace("Getting Elements for local ids: {}", mostSpecificChildren);
block.getMostSpecificChildren()[event] = concept.getElementByLocalId(mostSpecificChildren).getPrefix();
}
}
return block;
}
use of com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept 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.datasets.concepts.tree.TreeConcept in project conquery by bakdata.
the class FEValueTest method sortedValidityDates.
@Test
public void sortedValidityDates() {
Dataset dataset = new Dataset();
dataset.setName("testDataset");
Table table = new Table();
table.setDataset(dataset);
table.setName("testTable");
Column column = new Column();
column.setName("testColumn");
column.setTable(table);
ConceptTreeConnector connector = new ConceptTreeConnector();
connector.setName("testConnector");
TreeConcept concept = new TreeConcept();
concept.setDataset(dataset);
concept.setName("testConcept");
ValidityDate val0 = new ValidityDate();
val0.setName("val0");
val0.setConnector(connector);
ValidityDate val1 = new ValidityDate();
val1.setName("val1");
val1.setConnector(connector);
ValidityDate val2 = new ValidityDate();
val2.setName("val2");
val2.setConnector(connector);
List<ValidityDate> validityDates = List.of(val0, val1, val2);
connector.setColumn(column);
connector.setConcept(concept);
connector.setValidityDates(validityDates);
FETable feTable = FrontEndConceptBuilder.createTable(connector);
assertThat(feTable.getDateColumn().getOptions()).containsExactly(new FEValue("val0", val0.getId().toString()), new FEValue("val1", val1.getId().toString()), new FEValue("val2", val2.getId().toString()));
}
Aggregations