Search in sources :

Example 1 with WriterConfigImpl

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

the class AbstractChainConfigurationProvider method addDefaultWriterConfig.

public void addDefaultWriterConfig(ChainConfig ac) {
    WriterConfig wc = new WriterConfigImpl();
    wc.setPath(ac.getReaderConfig().getPath());
    wc.setType(null);
    ac.setWriterConfig(wc);
}
Also used : WriterConfigImpl(org.walkmod.conf.entities.impl.WriterConfigImpl) WriterConfig(org.walkmod.conf.entities.WriterConfig)

Example 2 with WriterConfigImpl

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

the class JSONConfigParser method getWriter.

public WriterConfig getWriter(JsonNode writer) {
    WriterConfig model = new WriterConfigImpl();
    if (writer.has("path")) {
        model.setPath(writer.get("path").asText());
    }
    if (writer.has("type")) {
        model.setType(writer.get("type").asText());
    }
    if (writer.has("includes")) {
        JsonNode includesJson = writer.get("includes");
        model.setIncludes(getFileSet(includesJson));
    }
    if (writer.has("excludes")) {
        JsonNode excludesJson = writer.get("excludes");
        model.setExcludes(getFileSet(excludesJson));
    }
    model.setParams(getParams(writer));
    return model;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WriterConfigImpl(org.walkmod.conf.entities.impl.WriterConfigImpl)

Example 3 with WriterConfigImpl

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

the class XMLConfigurationProvider method loadWriter.

public void loadWriter(Element child, ChainConfig ac) {
    if ("writer".equals(child.getNodeName())) {
        WriterConfig wc = new WriterConfigImpl();
        String path = child.getAttribute("path");
        if ("".equals(path)) {
            throw new ConfigurationException("Invalid writer definition: " + "A path attribute must be specified");
        }
        wc.setPath(path);
        String type = child.getAttribute("type");
        if ("".equals(type)) {
            wc.setType(null);
        } else {
            wc.setType(type);
        }
        NodeList childs = child.getChildNodes();
        if (childs != null) {
            int max = childs.getLength();
            List<String> excludes = new LinkedList<String>();
            List<String> includes = new LinkedList<String>();
            for (int i = 0; i < max; i++) {
                Node n = childs.item(i);
                String nodeName = n.getNodeName();
                if ("exclude".equals(nodeName)) {
                    Element exclude = (Element) n;
                    excludes.add(exclude.getAttribute("wildcard"));
                } else if ("include".equals(nodeName)) {
                    Element include = (Element) n;
                    includes.add(include.getAttribute("wildcard"));
                } else if (!"param".equals(nodeName)) {
                    throw new ConfigurationException("Invalid writer definition. Only exclude or include tags are supported");
                }
            }
            if (!excludes.isEmpty()) {
                String[] excludesArray = new String[excludes.size()];
                int j = 0;
                for (String exclude : excludes) {
                    excludesArray[j] = exclude;
                    j++;
                }
                wc.setExcludes(excludesArray);
            }
            if (!includes.isEmpty()) {
                String[] includesArray = new String[includes.size()];
                int j = 0;
                for (String include : includes) {
                    includesArray[j] = include;
                    j++;
                }
                wc.setIncludes(includesArray);
            }
        }
        wc.setParams(getParams(child));
        ac.setWriterConfig(wc);
    }
}
Also used : ConfigurationException(org.walkmod.conf.ConfigurationException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) WriterConfigImpl(org.walkmod.conf.entities.impl.WriterConfigImpl) LinkedList(java.util.LinkedList) WriterConfig(org.walkmod.conf.entities.WriterConfig)

Example 4 with WriterConfigImpl

use of org.walkmod.conf.entities.impl.WriterConfigImpl 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

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