@Provides @Singleton static MonitoringConfig monitoringConfig(Config config) { return ConfigBeanFactory.create( config.getConfig("monitoring"), ModifiableMonitoringConfig.class) .toImmutable(); }
@Provides @Singleton static JavascriptStaticConfig javascriptStaticConfig(Config config) { return ConfigBeanFactory.create( config.getConfig("javascriptConfig"), ModifiableJavascriptStaticConfig.class) .toImmutable(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private Object getConfigValue(Class<?> paramClass, Type paramType, String path) { Optional<Object> extractedValue = ConfigExtractors.extractConfigValue(config, paramClass, path); if (extractedValue.isPresent()) { return extractedValue.get(); } ConfigValue configValue = config.getValue(path); ConfigValueType valueType = configValue.valueType(); if (valueType.equals(ConfigValueType.OBJECT) && Map.class.isAssignableFrom(paramClass)) { ConfigObject object = config.getObject(path); return object.unwrapped(); } else if (valueType.equals(ConfigValueType.OBJECT)) { Object bean = ConfigBeanFactory.create(config.getConfig(path), paramClass); return bean; } else if (valueType.equals(ConfigValueType.LIST) && List.class.isAssignableFrom(paramClass)) { Type listType = ((ParameterizedType) paramType).getActualTypeArguments()[0]; Optional<List<?>> extractedListValue = ListExtractors.extractConfigListValue(config, listType, path); if (extractedListValue.isPresent()) { return extractedListValue.get(); } else { List<? extends Config> configList = config.getConfigList(path); return configList.stream() .map(cfg -> { Object created = ConfigBeanFactory.create(cfg, (Class) listType); return created; }) .collect(Collectors.toList()); } } throw new RuntimeException("Cannot obtain config value for " + paramType + " at path: " + path); }
public static void main(String[] args) throws AuthenticationException, AudioException, ConverseException, DeviceRegisterException { Config root = ConfigFactory.load(); AuthenticationConf authenticationConf = ConfigBeanFactory.create(root.getConfig("authentication"), AuthenticationConf.class); DeviceRegisterConf deviceRegisterConf = ConfigBeanFactory.create(root.getConfig("deviceRegister"), DeviceRegisterConf.class); AssistantConf assistantConf = ConfigBeanFactory.create(root.getConfig("assistant"), AssistantConf.class); AudioConf audioConf = ConfigBeanFactory.create(root.getConfig("audio"), AudioConf.class); // Authentication AuthenticationHelper authenticationHelper = new AuthenticationHelper(authenticationConf); authenticationHelper .authenticate() .orElseThrow(() -> new AuthenticationException("Error during authentication")); // Check if we need to refresh the access token to request the api if (authenticationHelper.expired()) { authenticationHelper .refreshAccessToken() .orElseThrow(() -> new AuthenticationException("Error refreshing access token")); } // Register Device model and device DeviceRegister deviceRegister = new DeviceRegister(deviceRegisterConf, authenticationHelper.getOAuthCredentials().getAccessToken()); deviceRegister.register(); // Build the client (stub) AssistantClient assistantClient = new AssistantClient(authenticationHelper.getOAuthCredentials(), assistantConf, deviceRegister.getDeviceModel(), deviceRegister.getDevice()); // Build the objects to record and play the conversation AudioRecorder audioRecorder = new AudioRecorder(audioConf); AudioPlayer audioPlayer = new AudioPlayer(audioConf); // Main loop while (true) { // Check if we need to refresh the access token to request the api if (authenticationHelper.expired()) { authenticationHelper .refreshAccessToken() .orElseThrow(() -> new AuthenticationException("Error refreshing access token")); // Update the token for the assistant client assistantClient.updateCredentials(authenticationHelper.getOAuthCredentials()); } // Record byte[] request = audioRecorder.getRecord(); // Request the api byte[] response = assistantClient.requestAssistant(request); // Play result if any if (response.length > 0) { audioPlayer.play(response); } else { LOGGER.info("No response from the API"); } } }
@Provides @Singleton static DatabaseConfig dbConfig(Config config) { return ConfigBeanFactory.create(config.getConfig("database"), ModifiableDatabaseConfig.class) .toImmutable(); }
@Provides @Singleton static RedisConfig redisConfig(Config config) { return ConfigBeanFactory.create(config.getConfig("redis"), ModifiableRedisConfig.class) .toImmutable(); }
@Provides @Singleton static FirebaseAuthConfig firebaseConfig(Config config) { return ConfigBeanFactory.create( config.getConfig("firebaseAuth"), ModifiableFirebaseAuthConfig.class); }
@Provides @Singleton static ServerConfig serverConfig(Config config) { return ConfigBeanFactory.create(config.getConfig("server"), ModifiableServerConfig.class) .toImmutable(); }
@Provides static YummlyConfig yummlyConfig(Config config) { return ConfigBeanFactory.create(config.getConfig("yummly"), ModifiableYummlyConfig.class) .toImmutable(); }
public void run() { logger.info("Starting application..."); final Config config = ConfigFactory.load(); final SparkSettings sparkConf = ConfigBeanFactory.create(config.getConfig("spark"), SparkSettings.class); logger.info("Loaded config: " + config.toString()); new SparkInitializer(sparkConf).init(); }