Revision 50995
Added by Claudio Atzori about 6 years ago
modules/dnet-mapreduce-jobs/trunk/src/test/java/eu/dnetlib/data/mapreduce/hbase/broker/EventFactoryTest.java | ||
---|---|---|
3 | 3 |
import java.util.UUID; |
4 | 4 |
|
5 | 5 |
import eu.dnetlib.data.mapreduce.hbase.broker.model.EventWrapper; |
6 |
import eu.dnetlib.data.proto.FieldTypeProtos.StringField; |
|
6 | 7 |
import org.apache.commons.lang.math.RandomUtils; |
7 | 8 |
import org.apache.commons.logging.Log; |
8 | 9 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
51 | 52 |
Result.newBuilder().setMetadata( |
52 | 53 |
Result.Metadata.newBuilder().setDateofacceptance(OafTest.sf("")) |
53 | 54 |
.addTitle(sp("aaaa Title", "main title", "dnet:dataCite_title")) |
55 |
.setDateofacceptance(sf("2017-07-13")) |
|
54 | 56 |
.setResulttype(q("publication", "dnet:result_typologies"))) |
55 | 57 |
.addInstance( |
56 | 58 |
Instance.newBuilder() |
... | ... | |
62 | 64 |
log.info("oaf: " + JsonFormat.printToString(oaf)); |
63 | 65 |
|
64 | 66 |
final float trust = RandomUtils.nextFloat(); |
65 |
final EventMessage event = EventFactory.asEvent(oaf, Topic.ENRICH_MISSING_PUBLICATION_DATE, new OpenAireEventPayload(), source, trust); |
|
67 |
final OpenAireEventPayload openAireEventPayload = new OpenAireEventPayload(); |
|
68 |
final EventMessage event = EventFactory.asEvent(oaf, Topic.ENRICH_MISSING_PUBLICATION_DATE, openAireEventPayload, source, trust); |
|
66 | 69 |
|
67 | 70 |
final OpenAireEventPayload p = OpenAireEventPayloadFactory.fromOAF(oaf, source, trust); |
68 | 71 |
final OpenAireEventPayload payload = HighlightFactory.highlightEnrichPublicationDate(p, OafTest.sf("2012-01-01")); |
... | ... | |
90 | 93 |
return KeyValue.newBuilder().setKey(k).setValue(v); |
91 | 94 |
} |
92 | 95 |
|
96 |
private StringField.Builder sf(final String value) { |
|
97 |
return StringField.newBuilder().setValue(value); |
|
98 |
} |
|
99 |
|
|
93 | 100 |
private StructuredProperty.Builder sp(final String v, final String classid, final String scheme) { |
94 | 101 |
return OafTest.getStructuredproperty(v, classid, scheme); |
95 | 102 |
} |
modules/dnet-mapreduce-jobs/trunk/src/main/java/eu/dnetlib/data/mapreduce/hbase/broker/model/EventMessage.java | ||
---|---|---|
3 | 3 |
import java.util.Map; |
4 | 4 |
|
5 | 5 |
import com.google.gson.Gson; |
6 |
|
|
7 | 6 |
import eu.dnetlib.data.mapreduce.hbase.broker.Topic; |
8 | 7 |
|
9 | 8 |
/** |
modules/dnet-mapreduce-jobs/trunk/src/main/java/eu/dnetlib/data/mapreduce/hbase/broker/mapping/DateParser.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.mapreduce.hbase.broker.mapping; |
2 | 2 |
|
3 | 3 |
import java.text.ParseException; |
4 |
import java.util.Date; |
|
5 | 4 |
|
6 | 5 |
import org.apache.commons.lang3.time.DateUtils; |
7 | 6 |
import org.apache.commons.logging.Log; |
... | ... | |
11 | 10 |
|
12 | 11 |
private static final Log log = LogFactory.getLog(DateParser.class); |
13 | 12 |
|
14 |
public static Date parse(final String s) {
|
|
13 |
public static Long parse(final String s) {
|
|
15 | 14 |
if (s == null) { |
16 | 15 |
log.warn("Date is NULL"); |
17 | 16 |
return null; |
18 | 17 |
} |
19 | 18 |
try { |
20 |
return DateUtils.parseDate(s, "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss"); |
|
19 |
return DateUtils.parseDate(s, "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss").getTime();
|
|
21 | 20 |
} catch (final ParseException e) { |
22 | 21 |
log.warn("Invalid Date: " + s); |
23 | 22 |
return null; |
Also available in: Unified diff
force gson to serialise dates inside the map as long (the ES mapping assumes to find such type)