From 6e9b27f37d836dc4abb540b215665b6e9e25f153 Mon Sep 17 00:00:00 2001 From: miconis Date: Fri, 24 Apr 2020 14:36:42 +0200 Subject: [PATCH] implementation of the mechanism to truncate the string and the lists --- .../eu/dnetlib/pace/util/MapDocumentUtil.java | 19 +++++++++++++++++-- .../eu/dnetlib/pace/config/ConfigTest.java | 9 ++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dnet-pace-core/src/main/java/eu/dnetlib/pace/util/MapDocumentUtil.java b/dnet-pace-core/src/main/java/eu/dnetlib/pace/util/MapDocumentUtil.java index a4d8c96c38..2f04767a20 100644 --- a/dnet-pace-core/src/main/java/eu/dnetlib/pace/util/MapDocumentUtil.java +++ b/dnet-pace-core/src/main/java/eu/dnetlib/pace/util/MapDocumentUtil.java @@ -29,7 +29,7 @@ public class MapDocumentUtil { switch (fdef.getType()) { case String: case Int: - stringField.put(fdef.getName(), new FieldValueImpl(fdef.getType(), fdef.getName(), getJPathString(fdef.getPath(), json))); + stringField.put(fdef.getName(), new FieldValueImpl(fdef.getType(), fdef.getName(), truncateValue(getJPathString(fdef.getPath(), json), fdef.getLength()))); break; case URL: String uv = getJPathString(fdef.getPath(), json); @@ -39,7 +39,7 @@ public class MapDocumentUtil { case List: case JSON: FieldListImpl fi = new FieldListImpl(fdef.getName(), fdef.getType()); - getJPathList(fdef.getPath(), json, fdef.getType()) + truncateList(getJPathList(fdef.getPath(), json, fdef.getType()), fdef.getSize()) .stream() .map(item -> new FieldValueImpl(Type.String, fdef.getName(), item)) .forEach(fi::add); @@ -104,4 +104,19 @@ public class MapDocumentUtil { } + public static String truncateValue(String value, int length) { + + if (length == -1 || length > value.length()) + return value; + + return value.substring(0, length); + } + + public static List truncateList(List list, int size) { + if (size == -1 || size > list.size()) + return list; + + return list.subList(0, size); + } + } 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 0a89640810..4abf40cc80 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 @@ -83,11 +83,14 @@ public class ConfigTest extends AbstractPaceTest { final MapDocument mapDocument = MapDocumentUtil.asMapDocumentWithJPath(dedupConf, json); - System.out.println("mapDocument = " + mapDocument.getFieldMap()); +// System.out.println("mapDocument = " + mapDocument.getFieldMap()); - JsonListMatch jsonListMatch = new JsonListMatch(params); +// JsonListMatch jsonListMatch = new JsonListMatch(params); +// +// jsonListMatch.compare(mapDocument.getFieldMap().get("pid"), mapDocument.getFieldMap().get("pid"), null); + + System.out.println("mapDocument = " + mapDocument.getFieldMap().get("title").stringValue()); - jsonListMatch.compare(mapDocument.getFieldMap().get("pid"), mapDocument.getFieldMap().get("pid"), null); }