Search in sources :

Example 1 with IdentifiableImpl

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

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

the class FrontEndConceptBuilder method createCTNode.

private static FENode createCTNode(ConceptElement<?> ce) {
    MatchingStats matchingStats = ce.getMatchingStats();
    FENode n = FENode.builder().active(null).description(ce.getDescription()).label(ce.getLabel()).additionalInfos(ce.getAdditionalInfos()).matchingEntries(matchingStats.countEvents()).matchingEntities(matchingStats.countEntities()).dateRange(matchingStats.spanEvents() != null ? matchingStats.spanEvents().toSimpleRange() : null).build();
    if (ce instanceof ConceptTreeNode) {
        ConceptTreeNode<?> tree = (ConceptTreeNode<?>) ce;
        if (tree.getChildren() != null) {
            n.setChildren(tree.getChildren().stream().map(IdentifiableImpl::getId).toArray(ConceptTreeChildId[]::new));
        }
        if (tree.getParent() != null) {
            n.setParent(tree.getParent().getId());
        }
    }
    return n;
}
Also used : ConceptTreeNode(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeNode) FENode(com.bakdata.conquery.apiv1.frontend.FENode) IdentifiableImpl(com.bakdata.conquery.models.identifiable.IdentifiableImpl) ConceptTreeChildId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptTreeChildId)

Aggregations

IdentifiableImpl (com.bakdata.conquery.models.identifiable.IdentifiableImpl)2 FENode (com.bakdata.conquery.apiv1.frontend.FENode)1 Injectable (com.bakdata.conquery.io.jackson.Injectable)1 ConceptTreeNode (com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeNode)1 ConceptTreeChildId (com.bakdata.conquery.models.identifiable.ids.specific.ConceptTreeChildId)1 SingletonNamespaceCollection (com.bakdata.conquery.models.worker.SingletonNamespaceCollection)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1