com.typesafe.config.ConfigBeanFactory Java Examples

The following examples show how to use com.typesafe.config.ConfigBeanFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoadTestApplication.java    From casquatch with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

		//Create CasquatchDao from config
		CasquatchDao db=CasquatchDao.builder().build();

		//Load loadtest config
		ConfigFactory.invalidateCaches();
		Config config = ConfigFactory.load().getConfig("loadtest");
		if(log.isTraceEnabled()) {
			for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
				log.trace("Config: {} -> {}", entry.getKey(), entry.getValue().render());
			}
		}
		LoadTestConfig loadTestConfig = ConfigBeanFactory.create(config,LoadTestConfig.class);

		//Run for each entity
		if(loadTestConfig.getEntities().size()>0) {
			for (Class entity : loadTestConfig.getEntityClasses()) {
				new LoadWrapper<>(entity, db).run(loadTestConfig);
			}
		}
		System.exit(0);
	}
 
Example #2
Source File: MonitoringModule.java    From curiostack with MIT License 5 votes vote down vote up
@Provides
@Singleton
static MonitoringConfig monitoringConfig(Config config) {
  return ConfigBeanFactory.create(
          config.getConfig("monitoring"), ModifiableMonitoringConfig.class)
      .toImmutable();
}
 
Example #3
Source File: ServerModule.java    From curiostack with MIT License 5 votes vote down vote up
@Provides
@Singleton
static JavascriptStaticConfig javascriptStaticConfig(Config config) {
  return ConfigBeanFactory.create(
          config.getConfig("javascriptConfig"), ModifiableJavascriptStaticConfig.class)
      .toImmutable();
}
 
Example #4
Source File: TypesafeConfigModule.java    From typesafeconfig-guice with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: GoogleAssistantClient.java    From google-assistant-java-demo with GNU General Public License v3.0 4 votes vote down vote up
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);
        IoConf ioConf = ConfigBeanFactory.create(root.getConfig("io"), IoConf.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(), ioConf);

        // Build the objects to record and play the conversation
        AudioRecorder audioRecorder = new AudioRecorder(audioConf);
        AudioPlayer audioPlayer = new AudioPlayer(audioConf);

        // Initiating Scanner to take user input
        Scanner scanner = new Scanner(System.in);

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


            // Get input (text or voice)
            byte[] request = getInput(ioConf, scanner, audioRecorder);

            // requesting assistant with text query
            assistantClient.requestAssistant(request);
            LOGGER.info(assistantClient.getTextResponse());

            if (Boolean.TRUE.equals(ioConf.getOutputAudio())) {
                byte[] audioResponse = assistantClient.getAudioResponse();
                if (audioResponse.length > 0) {
                    audioPlayer.play(audioResponse);
                } else {
                    LOGGER.info("No response from the API");
                }
            }
        }
    }
 
Example #6
Source File: GatewayMain.java    From curiostack with MIT License 4 votes vote down vote up
@Provides
@Singleton
static GatewayConfig gatewayConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("gateway"), ModifiableGatewayConfig.class)
      .toImmutable();
}
 
Example #7
Source File: SecurityModule.java    From curiostack with MIT License 4 votes vote down vote up
@Provides
@Singleton
static SecurityConfig securityConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("security"), ModifiableSecurityConfig.class)
      .toImmutable();
}
 
Example #8
Source File: DatabaseModule.java    From curiostack with MIT License 4 votes vote down vote up
@Provides
@Singleton
static DatabaseConfig dbConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("database"), ModifiableDatabaseConfig.class)
      .toImmutable();
}
 
Example #9
Source File: RedisModule.java    From curiostack with MIT License 4 votes vote down vote up
@Provides
@Singleton
static RedisConfig redisConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("redis"), ModifiableRedisConfig.class)
      .toImmutable();
}
 
Example #10
Source File: FirebaseAuthModule.java    From curiostack with MIT License 4 votes vote down vote up
@Provides
@Singleton
static FirebaseAuthConfig firebaseConfig(Config config) {
  return ConfigBeanFactory.create(
      config.getConfig("firebaseAuth"), ModifiableFirebaseAuthConfig.class);
}
 
Example #11
Source File: CryptoModule.java    From curiostack with MIT License 4 votes vote down vote up
@Provides
@Singleton
public static SignerConfig signerConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("signer"), ModifiableSignerConfig.class)
      .toImmutable();
}
 
Example #12
Source File: ServerModule.java    From curiostack with MIT License 4 votes vote down vote up
@Provides
@Singleton
static ServerConfig serverConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("server"), ModifiableServerConfig.class)
      .toImmutable();
}
 
Example #13
Source File: YummlyApiModule.java    From curiostack with MIT License 4 votes vote down vote up
@Provides
static YummlyConfig yummlyConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("yummly"), ModifiableYummlyConfig.class)
      .toImmutable();
}
 
Example #14
Source File: GeneratorExternalTests.java    From casquatch with Apache License 2.0 3 votes vote down vote up
@Test
public void testGenerator() throws Exception {

    CasquatchGeneratorConfiguration casquatchGeneratorConfiguration = ConfigBeanFactory.create(ConfigLoader.generator(),CasquatchGeneratorConfiguration.class);

    new CasquatchTestDaoBuilder().withDDL("CREATE TABLE IF NOT EXISTS table_name (key_one int,key_two int,col_one text,col_two text,PRIMARY KEY ((key_one), key_two))");

    new CasquatchGenerator(casquatchGeneratorConfiguration).run();

    assertTrue(new File(casquatchGeneratorConfiguration.getOutputFolder()+"/src/main/java/"+casquatchGeneratorConfiguration.getPackageName().replace(".","/")+"/TableName.java").exists());

}
 
Example #15
Source File: CasquatchGenerator.java    From casquatch with Apache License 2.0 2 votes vote down vote up
/**
 * Initialize CasquatchGenerator
 * @throws Exception relays any exception found
 */
public CasquatchGenerator() throws Exception {
    this(ConfigBeanFactory.create(ConfigLoader.generator(),CasquatchGeneratorConfiguration.class));
}