1
0
Fork 0

propagate exceptions in case of serialization errors, removed configuration pretty printing, removed unused class ScoredResult

This commit is contained in:
Claudio Atzori 2018-11-12 15:52:18 +01:00
parent f7616c7a8a
commit 478ad72cb8
8 changed files with 37 additions and 59 deletions

View File

@ -101,9 +101,9 @@ public class DedupConfig implements Config, Serializable {
@Override @Override
public String toString() { public String toString() {
try { try {
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this); return new ObjectMapper().writeValueAsString(this);
} catch (IOException e) { } catch (IOException e) {
return e.getStackTrace().toString(); throw new PaceException("unable to serialise configuration", e);
} }
} }

View File

@ -9,6 +9,7 @@ import java.util.Set;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import eu.dnetlib.pace.util.PaceException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
@ -252,9 +253,9 @@ public class WfConfig implements Serializable {
@Override @Override
public String toString() { public String toString() {
try { try {
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this); return new ObjectMapper().writeValueAsString(this);
} catch (IOException e) { } catch (IOException e) {
return e.getStackTrace().toString(); throw new PaceException("unable to serialise " + this.getClass().getName(), e);
} }
} }

View File

@ -1,6 +1,6 @@
package eu.dnetlib.pace.distance.eval; package eu.dnetlib.pace.distance.eval;
import com.google.gson.GsonBuilder; import eu.dnetlib.pace.util.PaceException;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import java.io.IOException; import java.io.IOException;
@ -54,9 +54,9 @@ public class ScoreResult implements Serializable {
@Override @Override
public String toString() { public String toString() {
try { try {
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this); return new ObjectMapper().writeValueAsString(this);
} catch (IOException e) { } catch (IOException e) {
return e.getStackTrace().toString(); throw new PaceException("unable to serialise " + this.getClass().getName(), e);
} }
} }
} }

View File

@ -58,7 +58,7 @@ public class ClusteringDef implements Serializable {
try { try {
return new ObjectMapper().writeValueAsString(this); return new ObjectMapper().writeValueAsString(this);
} catch (IOException e) { } catch (IOException e) {
return e.getStackTrace().toString(); throw new PaceException("unable to serialise " + this.getClass().getName(), e);
} }
} }

View File

@ -6,6 +6,7 @@ import java.util.List;
import eu.dnetlib.pace.condition.*; import eu.dnetlib.pace.condition.*;
import eu.dnetlib.pace.config.PaceConfig; import eu.dnetlib.pace.config.PaceConfig;
import eu.dnetlib.pace.util.PaceException;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
public class CondDef implements Serializable { public class CondDef implements Serializable {
@ -41,7 +42,7 @@ public class CondDef implements Serializable {
try { try {
return new ObjectMapper().writeValueAsString(this); return new ObjectMapper().writeValueAsString(this);
} catch (IOException e) { } catch (IOException e) {
return e.getStackTrace().toString(); throw new PaceException("unable to serialise " + this.getClass().getName(), e);
} }
} }

View File

@ -135,4 +135,15 @@ public class FieldDef implements Serializable {
this.params = params; 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;
}
} }

View File

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

View File

@ -1,11 +1,6 @@
package eu.dnetlib.pace.config; package eu.dnetlib.pace.config;
import java.io.IOException;
import eu.dnetlib.pace.AbstractPaceTest; 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 org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -15,23 +10,25 @@ public class ConfigTest extends AbstractPaceTest {
@Test @Test
public void dedupConfigSerializationTest() { 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*****"); assertNotNull(conf);
// 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);
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 @Test