List of usage examples for org.apache.commons.configuration2 ImmutableHierarchicalConfiguration getInt
int getInt(String key, int defaultValue);
From source file:com.gs.obevo.impl.AbstractEnvironmentEnricher.java
private void enrichSchemas(Environment dbEnv, ImmutableHierarchicalConfiguration envCfg, final Platform systemDbPlatform) { dbEnv.setName(envCfg.getString("name")); dbEnv.setDefaultUserId(envCfg.getString("defaultUserId")); dbEnv.setDefaultPassword(envCfg.getString("defaultPassword")); final int schemaNameValidationVersion = envCfg.getInt("schemaNameValidation", dbPlatformConfiguration.getFeatureToggleVersion("schemaNameValidation")); // TODO add include/exclude schemas functionality ImmutableList<Schema> schemaObjs = iterConfig(envCfg, "schemas.schema") .collect(new Function<ImmutableHierarchicalConfiguration, Schema>() { @Override/*from w ww. j ava 2 s .c o m*/ public Schema valueOf(ImmutableHierarchicalConfiguration cfg) { return AbstractEnvironmentEnricher.this.convertCfgToSchema(cfg, systemDbPlatform, schemaNameValidationVersion); } }); final MutableSet<String> schemasToInclude = iterString(envCfg, "includeSchemas").toSet(); final MutableSet<String> schemasToExclude = iterString(envCfg, "excludeSchemas").toSet(); if (!schemasToInclude.isEmpty() && !schemasToExclude.isEmpty()) { throw new IllegalArgumentException("Environment " + dbEnv.getName() + " has includeSchemas [" + schemasToInclude + "] and excludeSchemas [" + schemasToExclude + "] defined; please only specify one of them"); } else if (!schemasToInclude.isEmpty()) { schemaObjs = schemaObjs.select(new Predicate<Schema>() { @Override public boolean accept(Schema it) { return schemasToInclude.contains(it.getName()); } }); } else if (!schemasToExclude.isEmpty()) { schemaObjs = schemaObjs.reject(new Predicate<Schema>() { @Override public boolean accept(Schema it) { return schemasToExclude.contains(it.getName()); } }); } MutableMap<String, String> schemaNameOverrides = Maps.mutable.empty(); ImmutableSet<String> schemaNames = schemaObjs.collect(new Function<Schema, String>() { @Override public String valueOf(Schema schema1) { return schema1.getName(); } }).toSet().toImmutable(); for (ImmutableHierarchicalConfiguration schemaOverride : iterConfig(envCfg, "schemaOverrides.schemaOverride")) { String schema = schemaOverride.getString("schema"); if (schemaNames.contains(schema)) { schemaNameOverrides.put(schema, schemaOverride.getString("overrideValue")); } else { throw new IllegalArgumentException( "Schema override definition value " + schema + " is not defined in the schema list " + schemaNames + " for environment " + dbEnv.getName()); } } dbEnv.setSchemaNameOverrides(schemaNameOverrides.toImmutable()); // ensure that we only store the unique schema names here dbEnv.setSchemas( HashingStrategySets.mutable.ofAll(HashingStrategies.fromFunction(new Function<Schema, String>() { @Override public String valueOf(Schema schema) { return schema.getName(); } }), schemaObjs).toImmutable()); }