Skip to content

Commit

Permalink
fixes configurable yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviojava committed May 28, 2019
1 parent 51ec2a5 commit 8051033
Showing 1 changed file with 17 additions and 12 deletions.
Expand Up @@ -17,6 +17,7 @@
import org.jnosql.artemis.ConfigurationUnit;
import org.jnosql.artemis.configuration.Configurable;
import org.jnosql.artemis.configuration.ConfigurableReader;
import org.jnosql.artemis.configuration.ConfigurationException;
import org.jnosql.artemis.configuration.DefaultConfigurable;
import org.yaml.snakeyaml.Yaml;

Expand All @@ -42,21 +43,25 @@ class ConfigurableReaderYAML implements ConfigurableReader {

@Override
public List<Configurable> read(Supplier<InputStream> stream, ConfigurationUnit annotation) {
List<Configurable> configurations = cache.get(annotation.fileName());

if (nonNull(configurations)) {
List<Configurable> cached = cache.get(annotation.fileName());
if (nonNull(cached)) {
LOGGER.info("Loading the configuration file from the cache file: " + annotation.fileName());
return configurations;
return cached;
}
Yaml yaml = new Yaml();
Map<String, Object> config = yaml.load(stream.get());
List<Map<String, Object>> yamlConfigurations = (List<Map<String, Object>>) config.get("configurations");
List<Configurable> configurables = new ArrayList<>();
for (Map<String, Object> configuration : yamlConfigurations) {
configurables.add(getConfigurable(configuration));

try {
Yaml yaml = new Yaml();
Map<String, Object> config = yaml.load(stream.get());
List<Map<String, Object>> yamlConfigurations = (List<Map<String, Object>>) config.get("configurations");
List<Configurable> configurations = new ArrayList<>();
for (Map<String, Object> configuration : yamlConfigurations) {
configurations.add(getConfigurable(configuration));
}
cache.put(annotation.fileName(), configurations);
return configurations;
} catch (Exception exp) {
throw new ConfigurationException("Error to load Yaml file configuration", exp);
}
cache.put(annotation.fileName(), configurables);
return configurables;
}

private Configurable getConfigurable(Map<String, Object> configuration) {
Expand Down

0 comments on commit 8051033

Please sign in to comment.