From 478ad72cb885b209c4435315e36b9e369fb2dd7e Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Mon, 12 Nov 2018 15:52:18 +0100 Subject: [PATCH] propagate exceptions in case of serialization errors, removed configuration pretty printing, removed unused class ScoredResult --- .../eu/dnetlib/pace/config/DedupConfig.java | 4 +-- .../java/eu/dnetlib/pace/config/WfConfig.java | 5 +-- .../pace/distance/eval/ScoreResult.java | 6 ++-- .../eu/dnetlib/pace/model/ClusteringDef.java | 2 +- .../java/eu/dnetlib/pace/model/CondDef.java | 3 +- .../java/eu/dnetlib/pace/model/FieldDef.java | 11 +++++++ .../dnetlib/pace/model/gt/ScoredResult.java | 32 ------------------ .../eu/dnetlib/pace/config/ConfigTest.java | 33 +++++++++---------- 8 files changed, 37 insertions(+), 59 deletions(-) delete mode 100644 dnet-pace-core/src/main/java/eu/dnetlib/pace/model/gt/ScoredResult.java 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 2f6b5e9e0..9d281d71e 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 @@ -101,9 +101,9 @@ public class DedupConfig implements Config, Serializable { @Override public String toString() { try { - return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this); + return new ObjectMapper().writeValueAsString(this); } catch (IOException e) { - return e.getStackTrace().toString(); + throw new PaceException("unable to serialise configuration", e); } } diff --git a/dnet-pace-core/src/main/java/eu/dnetlib/pace/config/WfConfig.java b/dnet-pace-core/src/main/java/eu/dnetlib/pace/config/WfConfig.java index a2edef3f7..ddcfaaece 100644 --- a/dnet-pace-core/src/main/java/eu/dnetlib/pace/config/WfConfig.java +++ b/dnet-pace-core/src/main/java/eu/dnetlib/pace/config/WfConfig.java @@ -9,6 +9,7 @@ import java.util.Set; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.gson.GsonBuilder; +import eu.dnetlib.pace.util.PaceException; import org.apache.commons.lang.StringUtils; import org.codehaus.jackson.map.ObjectMapper; @@ -252,9 +253,9 @@ public class WfConfig implements Serializable { @Override public String toString() { try { - return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this); + return new ObjectMapper().writeValueAsString(this); } catch (IOException e) { - return e.getStackTrace().toString(); + throw new PaceException("unable to serialise " + this.getClass().getName(), e); } } diff --git a/dnet-pace-core/src/main/java/eu/dnetlib/pace/distance/eval/ScoreResult.java b/dnet-pace-core/src/main/java/eu/dnetlib/pace/distance/eval/ScoreResult.java index 4e394b261..62b7d85b4 100644 --- a/dnet-pace-core/src/main/java/eu/dnetlib/pace/distance/eval/ScoreResult.java +++ b/dnet-pace-core/src/main/java/eu/dnetlib/pace/distance/eval/ScoreResult.java @@ -1,6 +1,6 @@ package eu.dnetlib.pace.distance.eval; -import com.google.gson.GsonBuilder; +import eu.dnetlib.pace.util.PaceException; import org.codehaus.jackson.map.ObjectMapper; import java.io.IOException; @@ -54,9 +54,9 @@ public class ScoreResult implements Serializable { @Override public String toString() { try { - return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this); + return new ObjectMapper().writeValueAsString(this); } catch (IOException e) { - return e.getStackTrace().toString(); + throw new PaceException("unable to serialise " + this.getClass().getName(), e); } } } diff --git a/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/ClusteringDef.java b/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/ClusteringDef.java index 57239263a..ece4de896 100644 --- a/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/ClusteringDef.java +++ b/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/ClusteringDef.java @@ -58,7 +58,7 @@ public class ClusteringDef implements Serializable { try { return new ObjectMapper().writeValueAsString(this); } catch (IOException e) { - return e.getStackTrace().toString(); + throw new PaceException("unable to serialise " + this.getClass().getName(), e); } } diff --git a/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/CondDef.java b/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/CondDef.java index aefd44d95..ccbca5897 100644 --- a/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/CondDef.java +++ b/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/CondDef.java @@ -6,6 +6,7 @@ import java.util.List; import eu.dnetlib.pace.condition.*; import eu.dnetlib.pace.config.PaceConfig; +import eu.dnetlib.pace.util.PaceException; import org.codehaus.jackson.map.ObjectMapper; public class CondDef implements Serializable { @@ -41,7 +42,7 @@ public class CondDef implements Serializable { try { return new ObjectMapper().writeValueAsString(this); } catch (IOException e) { - return e.getStackTrace().toString(); + throw new PaceException("unable to serialise " + this.getClass().getName(), e); } } diff --git a/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/FieldDef.java b/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/FieldDef.java index b954df7d6..bcc96c6c0 100644 --- a/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/FieldDef.java +++ b/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/FieldDef.java @@ -135,4 +135,15 @@ public class FieldDef implements Serializable { this.params = params; } + public void setName(String name) { + this.name = name; + } + + public void setPath(String path) { + this.path = path; + } + + public void setIgnoreMissing(boolean ignoreMissing) { + this.ignoreMissing = ignoreMissing; + } } diff --git a/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/gt/ScoredResult.java b/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/gt/ScoredResult.java deleted file mode 100644 index 9caecee87..000000000 --- a/dnet-pace-core/src/main/java/eu/dnetlib/pace/model/gt/ScoredResult.java +++ /dev/null @@ -1,32 +0,0 @@ -package eu.dnetlib.pace.model.gt; - -import org.codehaus.jackson.map.ObjectMapper; - -import java.io.IOException; - -public class ScoredResult extends Result { - - private double meanDistance; - - public ScoredResult() { - super(); - } - - public double getMeanDistance() { - return meanDistance; - } - - public void setMeanDistance(final double meanDistance) { - this.meanDistance = meanDistance; - } - - @Override - public String toString() { - try { - return new ObjectMapper().writeValueAsString(this); - } catch (IOException e) { - return e.getStackTrace().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 5ae030674..8be6098f3 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,11 +1,6 @@ package eu.dnetlib.pace.config; -import java.io.IOException; - import eu.dnetlib.pace.AbstractPaceTest; -import eu.dnetlib.pace.model.MapDocument; -import eu.dnetlib.pace.model.MapDocumentSerializer; -import org.apache.commons.io.IOUtils; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -15,23 +10,25 @@ public class ConfigTest extends AbstractPaceTest { @Test public void dedupConfigSerializationTest() { - final DedupConfig cfgFromClasspath = DedupConfig.load(readFromClasspath("result.pace.conf.json")); + String fromClasspath = readFromClasspath("result.pace.conf.json"); + System.out.println("fromClasspath = " + fromClasspath); - final String conf = cfgFromClasspath.toString(); + final DedupConfig conf = DedupConfig.load(fromClasspath); -// System.out.println("*****SERIALIZED*****"); -// System.out.println(conf); -// System.out.println("*****FROM CLASSPATH*****"); -// System.out.println(readFromClasspath("result.pace.conf.json")); - - final DedupConfig cfgFromSerialization = DedupConfig.load(conf); - - assertEquals(cfgFromClasspath.toString(), cfgFromSerialization.toString()); - - assertNotNull(cfgFromClasspath); - assertNotNull(cfgFromSerialization); + assertNotNull(conf); + String parsed = conf.toString(); + + System.out.println("parsed = " + parsed); + + DedupConfig conf2 = DedupConfig.load(parsed); + + assertNotNull(conf2); + + System.out.println("conf2 = " + conf2); + + assertEquals(parsed, conf2.toString()); } @Test