Search in sources :

Example 6 with MutableInjectableValues

use of com.bakdata.conquery.io.jackson.MutableInjectableValues 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();
}
Also used : Injectable(com.bakdata.conquery.io.jackson.Injectable) Table(com.bakdata.conquery.models.datasets.Table) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Column(com.bakdata.conquery.models.datasets.Column) Dataset(com.bakdata.conquery.models.datasets.Dataset) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Validator(javax.validation.Validator) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 7 with MutableInjectableValues

use of com.bakdata.conquery.io.jackson.MutableInjectableValues in project conquery by bakdata.

the class Conquery method initialize.

@Override
public void initialize(Bootstrap<ConqueryConfig> bootstrap) {
    final ObjectMapper confMapper = bootstrap.getObjectMapper();
    Jackson.configure(confMapper);
    confMapper.setConfig(confMapper.getDeserializationConfig().withView(InternalOnly.class));
    // check for java compiler, needed for the class generation
    if (ToolProvider.getSystemJavaCompiler() == null) {
        throw new IllegalStateException("Conquery requires to be run on either a JDK or a ServerJRE");
    }
    // main config file is json
    bootstrap.setConfigurationFactoryFactory(JsonConfigurationFactory::new);
    bootstrap.addCommand(new ShardNode());
    bootstrap.addCommand(new PreprocessorCommand());
    bootstrap.addCommand(new CollectEntitiesCommand());
    bootstrap.addCommand(new StandaloneCommand(this));
    bootstrap.addCommand(new RecodeStoreCommand());
    bootstrap.addCommand(new MigrateCommand());
    ((MutableInjectableValues) confMapper.getInjectableValues()).add(Validator.class, bootstrap.getValidatorFactory().getValidator());
    // do some setup in other classes after initialization but before running a
    // command
    bootstrap.addBundle(new ConfiguredBundle<>() {

        @Override
        public void run(ConqueryConfig configuration, Environment environment) {
            configuration.configureObjectMapper(environment.getObjectMapper());
        }

        @Override
        public void initialize(Bootstrap<?> bootstrap) {
            // Allow overriding of config from environment variables.
            bootstrap.setConfigurationSourceProvider(new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(), StringSubstitutor.createInterpolator()));
        }
    });
}
Also used : JsonConfigurationFactory(io.dropwizard.configuration.JsonConfigurationFactory) CollectEntitiesCommand(com.bakdata.conquery.commands.CollectEntitiesCommand) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) PreprocessorCommand(com.bakdata.conquery.commands.PreprocessorCommand) InternalOnly(com.bakdata.conquery.io.jackson.InternalOnly) StandaloneCommand(com.bakdata.conquery.commands.StandaloneCommand) MigrateCommand(com.bakdata.conquery.commands.MigrateCommand) SubstitutingSourceProvider(io.dropwizard.configuration.SubstitutingSourceProvider) ShardNode(com.bakdata.conquery.commands.ShardNode) RecodeStoreCommand(com.bakdata.conquery.commands.RecodeStoreCommand) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Environment(io.dropwizard.setup.Environment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with MutableInjectableValues

use of com.bakdata.conquery.io.jackson.MutableInjectableValues in project conquery by bakdata.

the class Cloner method clone.

public static <T> ConqueryConfig clone(ConqueryConfig config, Map<Class<T>, T> injectables, ObjectMapper mapper) {
    try {
        MutableInjectableValues injectableHolder = ((MutableInjectableValues) mapper.getInjectableValues());
        for (Entry<Class<T>, T> injectable : injectables.entrySet()) {
            injectableHolder.add(injectable.getKey(), injectable.getValue());
        }
        ConqueryConfig clone = mapper.readValue(mapper.writeValueAsBytes(config), ConqueryConfig.class);
        clone.setLoggingFactory(config.getLoggingFactory());
        return clone;
    } catch (IOException e) {
        throw new IllegalStateException("Failed to clone a conquery config " + config, e);
    }
}
Also used : MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) IOException(java.io.IOException)

Aggregations

MutableInjectableValues (com.bakdata.conquery.io.jackson.MutableInjectableValues)8 Injectable (com.bakdata.conquery.io.jackson.Injectable)4 Column (com.bakdata.conquery.models.datasets.Column)4 Dataset (com.bakdata.conquery.models.datasets.Dataset)4 Table (com.bakdata.conquery.models.datasets.Table)4 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)4 Validator (javax.validation.Validator)4 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)3 IdMapSerialisationTest (com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Test (org.junit.jupiter.api.Test)3 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 CollectEntitiesCommand (com.bakdata.conquery.commands.CollectEntitiesCommand)1 MigrateCommand (com.bakdata.conquery.commands.MigrateCommand)1 PreprocessorCommand (com.bakdata.conquery.commands.PreprocessorCommand)1 RecodeStoreCommand (com.bakdata.conquery.commands.RecodeStoreCommand)1 ShardNode (com.bakdata.conquery.commands.ShardNode)1 StandaloneCommand (com.bakdata.conquery.commands.StandaloneCommand)1 InternalOnly (com.bakdata.conquery.io.jackson.InternalOnly)1