use of org.walkmod.conf.entities.impl.ProviderConfigImpl in project walkmod-core by walkmod.
the class YAMLConfigurationProvider method load.
@Override
public void load() throws ConfigurationException {
File file = new File(fileName);
try {
JsonNode node = null;
if (file.exists() && file.length() > 0) {
node = mapper.readTree(file);
configuration.prepareInitializers();
if (node.has("plugins")) {
Iterator<JsonNode> it = node.get("plugins").iterator();
Collection<PluginConfig> pluginList = new LinkedList<PluginConfig>();
while (it.hasNext()) {
JsonNode current = it.next();
String pluginId = current.asText();
String[] split = pluginId.split(":");
if (split.length > 3) {
} else {
String groupId, artifactId, version;
groupId = split[0];
artifactId = split[1];
version = split[2];
PluginConfig plugin = new PluginConfigImpl();
plugin.setGroupId(groupId);
plugin.setArtifactId(artifactId);
plugin.setVersion(version);
pluginList.add(plugin);
}
}
configuration.setPlugins(pluginList);
}
if (node.has("modules")) {
Iterator<JsonNode> it = node.get("modules").iterator();
List<String> modules = new LinkedList<String>();
configuration.setModules(modules);
while (it.hasNext()) {
JsonNode current = it.next();
modules.add(current.asText());
}
configuration.setModules(modules);
}
if (node.has("merge-policies")) {
Iterator<JsonNode> it = node.get("merge-policies").iterator();
Collection<MergePolicyConfig> mergePolicies = new LinkedList<MergePolicyConfig>();
while (it.hasNext()) {
JsonNode next = it.next();
if (next.has("policy")) {
MergePolicyConfig mergeCfg = new MergePolicyConfigImpl();
mergeCfg.setName(next.get("name").asText());
mergeCfg.setDefaultObjectPolicy(next.get("default-object-policy").asText());
mergeCfg.setDefaultTypePolicy(next.get("default-type-policy").asText());
if (next.has("policy")) {
Iterator<JsonNode> it2 = next.get("policy").iterator();
Map<String, String> policies = new HashMap<String, String>();
while (it2.hasNext()) {
JsonNode nextPolicy = it2.next();
String objectType = nextPolicy.get("object-type").asText();
String policyType = nextPolicy.get("policy-type").asText();
policies.put(objectType, policyType);
}
mergeCfg.setPolicyEntries(policies);
}
mergePolicies.add(mergeCfg);
}
}
configuration.setMergePolicies(mergePolicies);
}
if (node.has("conf-providers")) {
Iterator<JsonNode> it = node.get("conf-providers").iterator();
Collection<ProviderConfig> provConfigs = new LinkedList<ProviderConfig>();
while (it.hasNext()) {
JsonNode next = it.next();
ProviderConfig provCfg = new ProviderConfigImpl();
provCfg.setType(next.get("type").asText());
provCfg.setParameters(converter.getParams(next));
provConfigs.add(provCfg);
}
configuration.setProviderConfigurations(provConfigs);
}
if (node.has("chains")) {
Iterator<JsonNode> it = node.get("chains").iterator();
Collection<ChainConfig> chains = new LinkedList<ChainConfig>();
int i = 0;
while (it.hasNext()) {
ChainConfig chainCfg = new ChainConfigImpl();
JsonNode current = it.next();
if (current.has("name")) {
chainCfg.setName(current.get("name").asText());
} else {
chainCfg.setName("chain_" + i);
}
if (current.has("reader")) {
JsonNode reader = current.get("reader");
chainCfg.setReaderConfig(converter.getReader(reader));
} else {
addDefaultReaderConfig(chainCfg);
}
if (current.has("writer")) {
JsonNode writer = current.get("writer");
chainCfg.setWriterConfig(converter.getWriter(writer));
} else {
addDefaultWriterConfig(chainCfg);
}
if (current.has("walker")) {
chainCfg.setWalkerConfig(converter.getWalker(current));
} else {
addDefaultWalker(chainCfg);
if (current.has("transformations")) {
WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
walkerCfg.setTransformations(converter.getTransformationCfgs(current));
}
}
chains.add(chainCfg);
}
configuration.setChainConfigs(chains);
} else if (node.has("transformations")) {
Collection<ChainConfig> chains = new LinkedList<ChainConfig>();
ChainConfig chainCfg = new ChainConfigImpl();
chainCfg.setName("");
addDefaultReaderConfig(chainCfg);
addDefaultWalker(chainCfg);
WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
walkerCfg.setTransformations(converter.getTransformationCfgs(node));
addDefaultWriterConfig(chainCfg);
chains.add(chainCfg);
configuration.setChainConfigs(chains);
}
}
} catch (JsonProcessingException e) {
throw new ConfigurationException("Error parsing the " + fileName + " configuration", e);
} catch (IOException e) {
throw new ConfigurationException("Error reading the " + fileName + " configuration", e);
}
configuration.preparePlugins();
}
use of org.walkmod.conf.entities.impl.ProviderConfigImpl in project walkmod-core by walkmod.
the class XMLConfigurationProvider method loadProviders.
private void loadProviders() {
Element rootElement = document.getDocumentElement();
NodeList children = rootElement.getChildNodes();
Collection<ProviderConfig> providers = new LinkedList<ProviderConfig>();
int childSize = children.getLength();
for (int i = 0; i < childSize; i++) {
Node childNode = children.item(i);
if ("conf-providers".equals(childNode.getNodeName())) {
Element child = (Element) childNode;
NodeList providersNodes = child.getChildNodes();
int providersSize = providersNodes.getLength();
for (int j = 0; j < providersSize; j++) {
Node providerNode = providersNodes.item(j);
if ("conf-provider".equals(providerNode.getNodeName())) {
Element providerElem = (Element) providerNode;
ProviderConfig pc = new ProviderConfigImpl();
pc.setType(providerElem.getAttribute("type"));
pc.setParameters(getParams(providerElem));
providers.add(pc);
}
}
}
}
configuration.setProviderConfigurations(providers);
}
use of org.walkmod.conf.entities.impl.ProviderConfigImpl in project walkmod-core by walkmod.
the class AddCfgProviderCommand method build.
public ProviderConfig build() throws Exception {
ProviderConfig prov = new ProviderConfigImpl();
prov.setType(type.get(0));
if (params != null) {
prov.setParameters(new HashMap<String, Object>(params));
}
return prov;
}
Aggregations