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