Search in sources :

Example 1 with TransformationConfigImpl

use of org.walkmod.conf.entities.impl.TransformationConfigImpl in project walkmod-core by walkmod.

the class XMLConfigurationProvider method getTransformationItems.

public List<TransformationConfig> getTransformationItems(Element element, boolean exceptionsEnabled) {
    List<TransformationConfig> transformationConfigs = new LinkedList<TransformationConfig>();
    NodeList transfNodes = element.getChildNodes();
    for (int j = 0; j < transfNodes.getLength(); j++) {
        element = (Element) transfNodes.item(j);
        if ("transformation".equals(element.getNodeName())) {
            TransformationConfig tc = new TransformationConfigImpl();
            String name = element.getAttribute("name");
            String visitor = element.getAttribute("type");
            String isMergeable = element.getAttribute("isMergeable");
            String mergePolicy = element.getAttribute("merge-policy");
            if ("".equals(visitor)) {
                throw new ConfigurationException("Invalid transformation definition: A " + "type attribute must be specified");
            }
            if ("".equals(name)) {
                name = null;
            }
            tc.setName(name);
            tc.setType(visitor);
            tc.setParameters(getParams(element));
            if (isMergeable != null && !("".equals(isMergeable))) {
                tc.isMergeable(Boolean.parseBoolean(isMergeable));
            }
            if (!"".equals(mergePolicy.trim())) {
                tc.isMergeable(true);
                tc.setMergePolicy(mergePolicy);
            }
            transformationConfigs.add(tc);
        }
    }
    return transformationConfigs;
}
Also used : TransformationConfigImpl(org.walkmod.conf.entities.impl.TransformationConfigImpl) ConfigurationException(org.walkmod.conf.ConfigurationException) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) NodeList(org.w3c.dom.NodeList) LinkedList(java.util.LinkedList)

Example 2 with TransformationConfigImpl

use of org.walkmod.conf.entities.impl.TransformationConfigImpl in project walkmod-core by walkmod.

the class JSONConfigParser method getTransformationCfgs.

public List<TransformationConfig> getTransformationCfgs(JsonNode current) {
    if (current.has("transformations")) {
        List<TransformationConfig> transList = new LinkedList<TransformationConfig>();
        Iterator<JsonNode> itTrans = current.get("transformations").iterator();
        while (itTrans.hasNext()) {
            JsonNode item = itTrans.next();
            TransformationConfig trans = new TransformationConfigImpl();
            if (item.has("type")) {
                trans.setType(item.get("type").asText());
            }
            if (item.has("name")) {
                trans.setName(item.get("name").asText());
            }
            if (item.has("merge-policy")) {
                trans.setMergePolicy(item.get("merge-policy").asText());
            }
            if (item.has("isMergeable")) {
                trans.isMergeable(item.get("isMergeable").asBoolean());
            }
            trans.setParameters(getParams(item));
            transList.add(trans);
        }
        return transList;
    }
    return null;
}
Also used : TransformationConfigImpl(org.walkmod.conf.entities.impl.TransformationConfigImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode) LinkedList(java.util.LinkedList)

Example 3 with TransformationConfigImpl

use of org.walkmod.conf.entities.impl.TransformationConfigImpl in project walkmod-core by walkmod.

the class AddTransformationCommand method buildTransformationCfg.

public TransformationConfig buildTransformationCfg() {
    TransformationConfig tconfig = new TransformationConfigImpl();
    tconfig.setType(type.get(0));
    tconfig.isMergeable(isMergeable);
    tconfig.setMergePolicy(mergePolicy);
    tconfig.setName(name);
    if (params != null) {
        tconfig.setParameters(new HashMap<String, Object>(params));
    }
    return tconfig;
}
Also used : TransformationConfigImpl(org.walkmod.conf.entities.impl.TransformationConfigImpl) TransformationConfig(org.walkmod.conf.entities.TransformationConfig)

Example 4 with TransformationConfigImpl

use of org.walkmod.conf.entities.impl.TransformationConfigImpl in project walkmod-core by walkmod.

the class DynamicConfigurationProvider method load.

@Override
public void load() throws ConfigurationException {
    config.prepareInitializers();
    if (chains != null) {
        for (String chain : chains) {
            if (StringUtils.isNotEmpty(chain)) {
                PluginConfig plugin = config.resolvePlugin(chain);
                config.getPlugins().add(plugin);
            }
        }
        config.preparePlugins();
    }
    String path = options.getPath();
    if (chains != null) {
        for (String chain : chains) {
            if (StringUtils.isNotEmpty(chain)) {
                ChainConfig cc = config.getChainConfig(chain);
                if (cc == null) {
                    cc = new ChainConfigImpl(new TransformationConfigImpl(chain));
                    config.addChainConfig(cc);
                }
            }
        }
    }
    if (StringUtils.isNotEmpty(path)) {
        for (ChainConfig cc : config.getChainConfigs()) {
            cc.setPath(path);
        }
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) TransformationConfigImpl(org.walkmod.conf.entities.impl.TransformationConfigImpl) ChainConfigImpl(org.walkmod.conf.entities.impl.ChainConfigImpl) ChainConfig(org.walkmod.conf.entities.ChainConfig)

Example 5 with TransformationConfigImpl

use of org.walkmod.conf.entities.impl.TransformationConfigImpl in project walkmod-core by walkmod.

the class LanguageConfigurationProviderTest method testNullOverwriting.

@Test
public void testNullOverwriting() {
    LanguageConfigurationProvider provider = new LanguageConfigurationProvider();
    Configuration conf = new ConfigurationImpl();
    ChainConfig cc = new ChainConfigImpl();
    cc.setName("test-chain");
    ReaderConfig reader = new ReaderConfig();
    WalkerConfig walker = new WalkerConfigImpl();
    TransformationConfig transformation = new TransformationConfigImpl();
    transformation.isMergeable(true);
    List<TransformationConfig> transf = new LinkedList<TransformationConfig>();
    transf.add(transformation);
    walker.setParserConfig(new ParserConfigImpl());
    walker.setTransformations(transf);
    WriterConfig writer = new WriterConfigImpl();
    cc.setReaderConfig(reader);
    cc.setWalkerConfig(walker);
    cc.setWriterConfig(writer);
    conf.addChainConfig(cc);
    provider.init(conf);
    provider.load();
    Assert.assertNotNull(reader.getPath());
    Assert.assertNotNull(reader.getType());
    Assert.assertNotNull(walker.getType());
    Assert.assertNotNull(walker.getParserConfig().getType());
    Assert.assertNotNull(writer.getPath());
    Assert.assertNotNull(writer.getType());
    Assert.assertNotNull(transformation.getMergePolicy());
    Assert.assertNotNull(conf.getMergePolicies());
    Collection<MergePolicyConfig> mergec = conf.getMergePolicies();
    Assert.assertEquals(1, mergec.size());
    MergePolicyConfig mpc = mergec.iterator().next();
    Assert.assertNotNull(mpc.getDefaultObjectPolicy());
    Assert.assertNotNull(mpc.getDefaultTypePolicy());
    Map<String, String> entries = mpc.getPolicyEntries();
    Assert.assertEquals(2, entries.size());
}
Also used : MergePolicyConfig(org.walkmod.conf.entities.MergePolicyConfig) ParserConfigImpl(org.walkmod.conf.entities.impl.ParserConfigImpl) Configuration(org.walkmod.conf.entities.Configuration) WalkerConfig(org.walkmod.conf.entities.WalkerConfig) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) ChainConfigImpl(org.walkmod.conf.entities.impl.ChainConfigImpl) WalkerConfigImpl(org.walkmod.conf.entities.impl.WalkerConfigImpl) LinkedList(java.util.LinkedList) ChainConfig(org.walkmod.conf.entities.ChainConfig) WriterConfig(org.walkmod.conf.entities.WriterConfig) TransformationConfigImpl(org.walkmod.conf.entities.impl.TransformationConfigImpl) ReaderConfig(org.walkmod.conf.entities.ReaderConfig) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) WriterConfigImpl(org.walkmod.conf.entities.impl.WriterConfigImpl) Test(org.junit.Test)

Aggregations

TransformationConfigImpl (org.walkmod.conf.entities.impl.TransformationConfigImpl)5 LinkedList (java.util.LinkedList)3 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)3 ChainConfig (org.walkmod.conf.entities.ChainConfig)2 ChainConfigImpl (org.walkmod.conf.entities.impl.ChainConfigImpl)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Test (org.junit.Test)1 NodeList (org.w3c.dom.NodeList)1 ConfigurationException (org.walkmod.conf.ConfigurationException)1 Configuration (org.walkmod.conf.entities.Configuration)1 MergePolicyConfig (org.walkmod.conf.entities.MergePolicyConfig)1 PluginConfig (org.walkmod.conf.entities.PluginConfig)1 ReaderConfig (org.walkmod.conf.entities.ReaderConfig)1 WalkerConfig (org.walkmod.conf.entities.WalkerConfig)1 WriterConfig (org.walkmod.conf.entities.WriterConfig)1 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)1 ParserConfigImpl (org.walkmod.conf.entities.impl.ParserConfigImpl)1 WalkerConfigImpl (org.walkmod.conf.entities.impl.WalkerConfigImpl)1 WriterConfigImpl (org.walkmod.conf.entities.impl.WriterConfigImpl)1