From 968cd4743665bd53e1262e4da88261132a144d05 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Sun, 17 Feb 2019 12:48:25 +0100 Subject: [PATCH] replace existing attributes when loading default configuration --- .../eu/dnetlib/pace/config/DedupConfig.java | 7 ++++++- .../eu/dnetlib/pace/config/ConfigTest.java | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/dnet-pace-core/src/main/java/eu/dnetlib/pace/config/DedupConfig.java b/dnet-pace-core/src/main/java/eu/dnetlib/pace/config/DedupConfig.java index d7396406f..1cfcb089c 100644 --- a/dnet-pace-core/src/main/java/eu/dnetlib/pace/config/DedupConfig.java +++ b/dnet-pace-core/src/main/java/eu/dnetlib/pace/config/DedupConfig.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.function.BiFunction; import eu.dnetlib.pace.util.PaceException; import org.antlr.stringtemplate.StringTemplate; @@ -73,7 +74,11 @@ public class DedupConfig implements Config, Serializable { template.setAttribute(e.getKey(), e.getValue()); } for (final Entry e : params.entrySet()) { - template.setAttribute(e.getKey(), e.getValue()); + if (template.getAttribute(e.getKey()) != null) { + template.getAttributes().computeIfPresent(e.getKey(), (o, o2) -> e.getValue()); + } else { + template.setAttribute(e.getKey(), e.getValue()); + } } final String json = template.toString(); diff --git a/dnet-pace-core/src/test/java/eu/dnetlib/pace/config/ConfigTest.java b/dnet-pace-core/src/test/java/eu/dnetlib/pace/config/ConfigTest.java index 8be6098f3..6b5a2b99c 100644 --- a/dnet-pace-core/src/test/java/eu/dnetlib/pace/config/ConfigTest.java +++ b/dnet-pace-core/src/test/java/eu/dnetlib/pace/config/ConfigTest.java @@ -1,8 +1,12 @@ package eu.dnetlib.pace.config; +import com.google.common.collect.Maps; import eu.dnetlib.pace.AbstractPaceTest; import org.junit.Test; +import java.io.IOException; +import java.util.Map; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -36,7 +40,22 @@ public class ConfigTest extends AbstractPaceTest { DedupConfig load = DedupConfig.load(readFromClasspath("result.pace.conf.json")); + assertNotNull(load); System.out.println(load.toString()); + } + @Test + public void testLoadDefaults() throws IOException { + + final Map config = Maps.newHashMap(); + config.put("entityType", "organization"); + config.put("configurationId", "dedup-organization-simple"); + final DedupConfig dedupConf = DedupConfig.loadDefault(config); + + System.out.println("dedupConf = " + dedupConf); + } + + + }