Search in sources :

Example 1 with SolcastConfig

use of me.retrodaredevil.solarthing.rest.graphql.solcast.SolcastConfig in project solarthing by wildmountainfarms.

the class GraphQLProviderTest method testGeneration.

@Test
void testGeneration() {
    CouchDbDatabaseSettings couchDbDatabaseSettings = new CouchDbDatabaseSettings(new CouchPropertiesBuilder("http", "localhost", 5984, null, null).build(), new OkHttpPropertiesBuilder().build());
    ObjectMapper mapper = JacksonUtil.defaultMapper();
    // Use DefaultInstanceOptions.REQUIRE_NO_DEFAULTS while testing because first, we don't actually query any data,
    // and second, we're trying to get rid of usages of DefaultInstanceOptions.DEFAULT_DEFAULT_INSTANCE_OPTIONS
    CacheController cacheController = new CacheController(new CacheHandler(mapper, DefaultInstanceOptions.REQUIRE_NO_DEFAULTS, CouchDbUtil.createInstance(couchDbDatabaseSettings.getCouchProperties(), couchDbDatabaseSettings.getOkHttpProperties())));
    GraphQLSchema schema = GraphQLProvider.createGraphQLSchemaGenerator(JacksonUtil.defaultMapper(), couchDbDatabaseSettings, DefaultInstanceOptions.REQUIRE_NO_DEFAULTS, new SolcastConfig(Collections.emptyMap()), cacheController).generate();
    GraphQL.newGraphQL(schema).build();
}
Also used : SolcastConfig(me.retrodaredevil.solarthing.rest.graphql.solcast.SolcastConfig) CouchDbDatabaseSettings(me.retrodaredevil.solarthing.config.databases.implementations.CouchDbDatabaseSettings) CacheController(me.retrodaredevil.solarthing.rest.cache.CacheController) CacheHandler(me.retrodaredevil.solarthing.rest.cache.CacheHandler) CouchPropertiesBuilder(me.retrodaredevil.couchdb.CouchPropertiesBuilder) GraphQLSchema(graphql.schema.GraphQLSchema) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OkHttpPropertiesBuilder(me.retrodaredevil.okhttp3.OkHttpPropertiesBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with SolcastConfig

use of me.retrodaredevil.solarthing.rest.graphql.solcast.SolcastConfig in project solarthing by wildmountainfarms.

the class GraphQLProvider method init.

@PostConstruct
public void init() {
    try {
        updateNonNull();
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    ObjectMapper objectMapper = JacksonUtil.defaultMapper();
    SolcastConfig solcastConfig = null;
    try {
        solcastConfig = objectMapper.readValue(solcastFile, SolcastConfig.class);
    } catch (JsonParseException | JsonMappingException e) {
        throw new RuntimeException("Bad solcast JSON!", e);
    } catch (IOException e) {
        LOGGER.debug("No solcast config! Not using solcast!");
    }
    if (solcastConfig == null) {
        solcastConfig = new SolcastConfig(Collections.emptyMap());
    }
    GraphQLSchema schema = createGraphQLSchemaGenerator(objectMapper, couchDbDatabaseSettings, defaultInstanceOptions, solcastConfig, cacheController).generate();
    this.graphQL = GraphQL.newGraphQL(schema).defaultDataFetcherExceptionHandler(new SolarThingExceptionHandler()).build();
}
Also used : SolcastConfig(me.retrodaredevil.solarthing.rest.graphql.solcast.SolcastConfig) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) GraphQLSchema(graphql.schema.GraphQLSchema) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 GraphQLSchema (graphql.schema.GraphQLSchema)2 SolcastConfig (me.retrodaredevil.solarthing.rest.graphql.solcast.SolcastConfig)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 IOException (java.io.IOException)1 PostConstruct (javax.annotation.PostConstruct)1 CouchPropertiesBuilder (me.retrodaredevil.couchdb.CouchPropertiesBuilder)1 OkHttpPropertiesBuilder (me.retrodaredevil.okhttp3.OkHttpPropertiesBuilder)1 CouchDbDatabaseSettings (me.retrodaredevil.solarthing.config.databases.implementations.CouchDbDatabaseSettings)1 CacheController (me.retrodaredevil.solarthing.rest.cache.CacheController)1 CacheHandler (me.retrodaredevil.solarthing.rest.cache.CacheHandler)1 Test (org.junit.jupiter.api.Test)1