replace existing attributes when loading default configuration

This commit is contained in:
Claudio Atzori 2019-02-17 12:48:25 +01:00
parent f1c68d8ba3
commit 968cd47436
2 changed files with 25 additions and 1 deletions

View File

@ -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<String, String> 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();

View File

@ -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<String, String> config = Maps.newHashMap();
config.put("entityType", "organization");
config.put("configurationId", "dedup-organization-simple");
final DedupConfig dedupConf = DedupConfig.loadDefault(config);
System.out.println("dedupConf = " + dedupConf);
}
}