use of org.walkmod.conf.entities.WalkerConfig 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.WalkerConfig in project walkmod-core by walkmod.
the class LanguageConfigurationProvider method updateNulls.
private void updateNulls() {
Collection<ChainConfig> ccs = configuration.getChainConfigs();
Element rootElement = document.getDocumentElement();
if (ccs != null) {
for (ChainConfig cc : ccs) {
ReaderConfig rc = cc.getReaderConfig();
if (rc.getType() == null) {
rc.setType(rootElement.getAttribute("reader"));
}
if (rc.getPath() == null) {
rc.setPath(rootElement.getAttribute("path"));
}
WriterConfig wc = cc.getWriterConfig();
if (wc.getType() == null) {
wc.setType(rootElement.getAttribute("writer"));
}
if (wc.getPath() == null) {
wc.setPath(rootElement.getAttribute("path"));
}
WalkerConfig walkc = cc.getWalkerConfig();
if (walkc.getType() == null) {
walkc.setType(rootElement.getAttribute("walker"));
}
if (walkc.getParserConfig().getType() == null) {
if (!"".equals(rootElement.getAttribute("parser"))) {
walkc.getParserConfig().setType(rootElement.getAttribute("parser"));
}
}
List<TransformationConfig> transformations = walkc.getTransformations();
if (transformations != null) {
for (TransformationConfig tc : transformations) {
if (tc.isMergeable()) {
if (tc.getMergePolicy() == null) {
tc.setMergePolicy(DEFAULT_MERGE_ENGINE_NAME);
}
}
}
}
wc.setPatcherType(rootElement.getAttribute("patcher"));
}
}
}
use of org.walkmod.conf.entities.WalkerConfig in project walkmod-core by walkmod.
the class AddChainYMLAction method doAction.
@Override
public void doAction(JsonNode chainsNode) throws Exception {
ArrayNode chainsList = null;
ObjectMapper mapper = provider.getObjectMapper();
if (chainsNode != null) {
if (!chainsNode.has("chains")) {
chainsList = new ArrayNode(mapper.getNodeFactory());
if (chainsNode.isObject()) {
ObjectNode aux = (ObjectNode) chainsNode;
aux.set("chains", chainsList);
} else {
throw new TransformerException("The root element is not a JSON node");
}
} else {
JsonNode aux = chainsNode.get("chains");
if (aux.isArray()) {
chainsList = (ArrayNode) chainsNode.get("chains");
} else {
throw new TransformerException("The plugins element is not a valid array");
}
}
}
ObjectNode chainNode = new ObjectNode(mapper.getNodeFactory());
ReaderConfig readerCfg = chainCfg.getReaderConfig();
if (readerCfg != null) {
if (chainsNode == null) {
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode aux = (ObjectNode) chainsNode;
chainsList = new ArrayNode(mapper.getNodeFactory());
aux.set("chains", chainsList);
}
ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
chainNode.set("reader", readerNode);
populateWriterReader(readerNode, readerCfg.getPath(), readerCfg.getType(), readerCfg.getIncludes(), readerCfg.getExcludes(), readerCfg.getParameters());
} else {
provider.addDefaultReaderConfig(chainCfg);
}
WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
if (walkerCfg != null) {
ObjectNode walkerNode = null;
String type = walkerCfg.getType();
if (type != null) {
if (chainsNode == null) {
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode aux = (ObjectNode) chainsNode;
chainsList = new ArrayNode(mapper.getNodeFactory());
aux.set("chains", chainsList);
}
walkerNode = new ObjectNode(mapper.getNodeFactory());
chainNode.set("walker", walkerNode);
walkerNode.set("type", new TextNode(type));
}
Map<String, Object> wparams = walkerCfg.getParams();
if (wparams != null && !wparams.isEmpty()) {
if (walkerNode == null) {
if (chainsNode == null) {
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode aux = (ObjectNode) chainsNode;
chainsList = new ArrayNode(mapper.getNodeFactory());
aux.set("chains", chainsList);
}
walkerNode = new ObjectNode(mapper.getNodeFactory());
chainNode.set("walker", walkerNode);
}
populateParams(walkerNode, wparams);
}
String rootNamespace = walkerCfg.getRootNamespace();
if (rootNamespace != null) {
if (walkerNode == null) {
if (chainsNode == null) {
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode aux = (ObjectNode) chainsNode;
chainsList = new ArrayNode(mapper.getNodeFactory());
aux.set("chains", chainsList);
}
walkerNode = new ObjectNode(mapper.getNodeFactory());
chainNode.set("walker", walkerNode);
}
walkerNode.set("root-namespace", new TextNode(rootNamespace));
}
List<TransformationConfig> transformationList = walkerCfg.getTransformations();
if (transformationList != null && !transformationList.isEmpty()) {
ArrayNode transformationListNode = new ArrayNode(mapper.getNodeFactory());
if (walkerNode == null) {
if (chainsNode == null) {
ObjectNode aux = new ObjectNode(mapper.getNodeFactory());
aux.set("transformations", transformationListNode);
chainsNode = aux;
} else {
chainNode.set("transformations", transformationListNode);
}
} else {
walkerNode.set("transformations", transformationListNode);
}
for (TransformationConfig transCfg : transformationList) {
ObjectNode transformationNode = new ObjectNode(mapper.getNodeFactory());
transformationListNode.add(transformationNode);
createTransformation(transformationNode, transCfg);
}
}
}
WriterConfig writerCfg = chainCfg.getWriterConfig();
if (writerCfg != null) {
if (chainsNode == null) {
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode aux = (ObjectNode) chainsNode;
chainsList = new ArrayNode(mapper.getNodeFactory());
aux.set("chains", chainsList);
}
ObjectNode writerNode = new ObjectNode(mapper.getNodeFactory());
chainNode.set("writer", writerNode);
populateWriterReader(writerNode, writerCfg.getPath(), writerCfg.getType(), writerCfg.getIncludes(), writerCfg.getExcludes(), writerCfg.getParams());
} else {
provider.addDefaultWriterConfig(chainCfg);
}
if (chainsList != null) {
int beforePos = -1;
if (before != null) {
Iterator<JsonNode> it = chainsList.iterator();
int i = 0;
while (it.hasNext() && beforePos == -1) {
JsonNode next = it.next();
if (next.get("name").equals(before)) {
beforePos = i;
}
i++;
}
}
if (beforePos == -1) {
chainsList.add(chainNode);
} else {
chainsList.insert(beforePos, chainNode);
}
}
if (readerCfg != null || walkerCfg != null || writerCfg != null) {
provider.write(chainsNode);
}
}
use of org.walkmod.conf.entities.WalkerConfig in project walkmod-core by walkmod.
the class AddTransformationYMLAction method doAction.
@Override
public void doAction(JsonNode chainsNode) throws Exception {
ArrayNode transformationsNode = null;
boolean isMultiModule = chainsNode.has("modules");
ObjectMapper mapper = provider.getObjectMapper();
if (!isMultiModule) {
boolean validChainName = chain != null && !"".equals(chain) && !"default".equals(chain);
if (!chainsNode.has("chains")) {
if (chainsNode.has("transformations")) {
JsonNode aux = chainsNode.get("transformations");
if (aux.isArray()) {
transformationsNode = (ArrayNode) aux;
}
if (!validChainName) {
ObjectNode auxRoot = (ObjectNode) chainsNode;
if (transformationsNode == null) {
transformationsNode = new ArrayNode(mapper.getNodeFactory());
}
auxRoot.set("transformations", transformationsNode);
} else {
// reset the root
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode auxRoot = (ObjectNode) chainsNode;
// the default chain list added
ObjectNode chainObject = new ObjectNode(mapper.getNodeFactory());
chainObject.set("name", new TextNode("default"));
chainObject.set("transformations", transformationsNode);
ArrayNode chainsListNode = new ArrayNode(mapper.getNodeFactory());
// the requested chain added
ObjectNode newChain = new ObjectNode(mapper.getNodeFactory());
newChain.set("name", new TextNode(chain));
if (path != null && !"".equals(path.trim())) {
ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
newChain.set("reader", readerNode);
populateWriterReader(readerNode, path, null, null, null, null);
ObjectNode writerNode = new ObjectNode(mapper.getNodeFactory());
newChain.set("writer", writerNode);
populateWriterReader(writerNode, path, null, null, null, null);
}
transformationsNode = new ArrayNode(mapper.getNodeFactory());
newChain.set("transformations", transformationsNode);
if (before == null || !"default".equals(before)) {
chainsListNode.add(chainObject);
}
chainsListNode.add(newChain);
if (before != null && "default".equals(before)) {
chainsListNode.add(chainObject);
}
auxRoot.set("chains", chainsListNode);
}
} else {
ObjectNode auxRoot = (ObjectNode) chainsNode;
transformationsNode = new ArrayNode(mapper.getNodeFactory());
boolean writeChainInfo = validChainName;
if (!writeChainInfo) {
writeChainInfo = path != null && !"".equals(path.trim());
chain = "default";
}
if (writeChainInfo) {
ArrayNode auxChainsList = new ArrayNode(mapper.getNodeFactory());
ObjectNode aux = new ObjectNode(mapper.getNodeFactory());
auxChainsList.add(aux);
aux.set("name", new TextNode(chain));
if (path != null && !"".equals(path.trim())) {
ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
aux.set("reader", readerNode);
populateWriterReader(readerNode, path, null, null, null, null);
}
auxRoot.set("chains", auxChainsList);
if (path != null && !"".equals(path.trim())) {
ObjectNode writerNode = new ObjectNode(mapper.getNodeFactory());
aux.set("writer", writerNode);
populateWriterReader(writerNode, path, null, null, null, null);
}
auxRoot = aux;
}
auxRoot.set("transformations", transformationsNode);
}
} else {
if (validChainName) {
JsonNode aux = chainsNode.get("chains");
boolean found = false;
if (aux.isArray()) {
Iterator<JsonNode> it = aux.elements();
while (it.hasNext()) {
JsonNode next = it.next();
if (next.has("name")) {
String id = next.get("name").asText();
if (chain.equals(id)) {
found = true;
if (next.has("transformations")) {
JsonNode auxTrans = next.get("transformations");
if (auxTrans.isArray()) {
transformationsNode = (ArrayNode) auxTrans;
} else {
throw new Exception("The chain [" + chain + "] does not have a valid transformations node");
}
} else if (next.isObject()) {
ObjectNode auxNext = (ObjectNode) next;
transformationsNode = new ArrayNode(mapper.getNodeFactory());
auxNext.set("transformations", transformationsNode);
} else {
throw new Exception("The chain [" + chain + "] does not have a valid structure");
}
}
}
}
if (!found) {
ChainConfig chainCfg = new ChainConfigImpl();
chainCfg.setName(chain);
WalkerConfig walkerCfg = new WalkerConfigImpl();
List<TransformationConfig> transfs = new LinkedList<TransformationConfig>();
transfs.add(transformationCfg);
walkerCfg.setTransformations(transfs);
chainCfg.setWalkerConfig(walkerCfg);
provider.addChainConfig(chainCfg, false, before);
return;
}
}
} else {
ObjectNode node = new ObjectNode(mapper.getNodeFactory());
node.set("name", new TextNode(chain));
ArrayNode transNodes = new ArrayNode(mapper.getNodeFactory());
node.set("transformations", transNodes);
ArrayNode array = (ArrayNode) chainsNode.get("chains");
array.add(node);
ObjectNode transformationNode = new ObjectNode(mapper.getNodeFactory());
transNodes.add(transformationNode);
createTransformation(transformationNode, transformationCfg);
return;
}
}
if (transformationsNode != null) {
ObjectNode transformationNode = new ObjectNode(mapper.getNodeFactory());
if (order != null && order < transformationsNode.size()) {
transformationsNode.insert(order, transformationNode);
} else {
transformationsNode.add(transformationNode);
}
createTransformation(transformationNode, transformationCfg);
provider.write(chainsNode);
return;
} else if (chain != null) {
throw new Exception("The chain [" + chain + "] does not exists");
}
}
}
use of org.walkmod.conf.entities.WalkerConfig in project walkmod-core by walkmod.
the class AbstractChainConfigurationProvider method addDefaultWalker.
public void addDefaultWalker(ChainConfig ac) {
WalkerConfig wc = new WalkerConfigImpl();
wc.setType(null);
wc.setParserConfig(new ParserConfigImpl());
ac.setWalkerConfig(wc);
}
Aggregations