Revision 51006
Added by Claudio Atzori over 6 years ago
modules/dnet-mapreduce-jobs/branches/beta/src/test/java/eu/dnetlib/data/mapreduce/hbase/broker/EventFactoryTest.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.UUID; |
4 | 4 |
|
5 |
import eu.dnetlib.data.mapreduce.hbase.broker.model.EventWrapper; |
|
6 |
import eu.dnetlib.data.proto.FieldTypeProtos.StringField; |
|
5 | 7 |
import org.apache.commons.lang.math.RandomUtils; |
6 | 8 |
import org.apache.commons.logging.Log; |
7 | 9 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
50 | 52 |
Result.newBuilder().setMetadata( |
51 | 53 |
Result.Metadata.newBuilder().setDateofacceptance(OafTest.sf("")) |
52 | 54 |
.addTitle(sp("aaaa Title", "main title", "dnet:dataCite_title")) |
55 |
.setDateofacceptance(sf("2017-07-13")) |
|
53 | 56 |
.setResulttype(q("publication", "dnet:result_typologies"))) |
54 | 57 |
.addInstance( |
55 | 58 |
Instance.newBuilder() |
... | ... | |
61 | 64 |
log.info("oaf: " + JsonFormat.printToString(oaf)); |
62 | 65 |
|
63 | 66 |
final float trust = RandomUtils.nextFloat(); |
64 |
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); |
|
65 | 69 |
|
66 | 70 |
final OpenAireEventPayload p = OpenAireEventPayloadFactory.fromOAF(oaf, source, trust); |
67 | 71 |
final OpenAireEventPayload payload = HighlightFactory.highlightEnrichPublicationDate(p, OafTest.sf("2012-01-01")); |
... | ... | |
73 | 77 |
|
74 | 78 |
event.setPayload(payload.toJSON()); |
75 | 79 |
|
76 |
log.info("event: " + event.toString()); |
|
80 |
log.info("event message: " + event.toString());
|
|
77 | 81 |
|
82 |
final EventWrapper wrapper = new EventWrapper(event, "test"); |
|
83 |
|
|
84 |
log.info("broker event: " + wrapper.asBrokerEvent().toJson()); |
|
85 |
|
|
78 | 86 |
} |
79 | 87 |
|
80 | 88 |
private Qualifier.Builder q(final String classid, final String scheme) { |
... | ... | |
85 | 93 |
return KeyValue.newBuilder().setKey(k).setValue(v); |
86 | 94 |
} |
87 | 95 |
|
96 |
private StringField.Builder sf(final String value) { |
|
97 |
return StringField.newBuilder().setValue(value); |
|
98 |
} |
|
99 |
|
|
88 | 100 |
private StructuredProperty.Builder sp(final String v, final String classid, final String scheme) { |
89 | 101 |
return OafTest.getStructuredproperty(v, classid, scheme); |
90 | 102 |
} |
modules/dnet-mapreduce-jobs/branches/beta/src/main/java/eu/dnetlib/data/mapreduce/hbase/broker/model/Event.java | ||
---|---|---|
4 | 4 |
import java.util.Map; |
5 | 5 |
|
6 | 6 |
import com.google.gson.Gson; |
7 |
import com.google.gson.GsonBuilder; |
|
7 | 8 |
|
8 | 9 |
public class Event { |
9 | 10 |
|
11 |
public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; |
|
12 |
|
|
10 | 13 |
private String eventId; |
11 | 14 |
|
12 | 15 |
private String producerId; |
... | ... | |
103 | 106 |
} |
104 | 107 |
|
105 | 108 |
public String toJson() { |
106 |
return new Gson().toJson(this); |
|
109 |
|
|
110 |
final Gson gson = new GsonBuilder() |
|
111 |
.setDateFormat(DATE_FORMAT).create(); |
|
112 |
|
|
113 |
return gson.toJson(this); |
|
107 | 114 |
} |
108 | 115 |
} |
modules/dnet-mapreduce-jobs/branches/beta/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/branches/beta/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; |
modules/dnet-mapreduce-jobs/branches/beta/pom.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" ?> |
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
4 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 | 5 |
<parent> |
4 | 6 |
<groupId>eu.dnetlib</groupId> |
5 | 7 |
<artifactId>dnet45-parent</artifactId> |
6 | 8 |
<version>1.0.0</version> |
7 |
<relativePath />
|
|
9 |
<relativePath/> |
|
8 | 10 |
</parent> |
9 | 11 |
<modelVersion>4.0.0</modelVersion> |
10 | 12 |
<groupId>eu.dnetlib</groupId> |
... | ... | |
148 | 150 |
<dependency> |
149 | 151 |
<groupId>eu.dnetlib</groupId> |
150 | 152 |
<artifactId>dnet-openaireplus-mapping-utils</artifactId> |
151 |
<version>[6.0.0,6.1.5-SNAPSHOT)</version>
|
|
153 |
<version>[6.0.0,7.0.0)</version>
|
|
152 | 154 |
</dependency> |
153 | 155 |
<dependency> |
154 | 156 |
<groupId>org.antlr</groupId> |
... | ... | |
190 | 192 |
<dependency> |
191 | 193 |
<groupId>org.elasticsearch</groupId> |
192 | 194 |
<artifactId>elasticsearch-hadoop-mr</artifactId> |
193 |
<version>2.4.5</version> |
|
195 |
<version>5.2.0</version> |
|
196 |
<exclusions> |
|
197 |
<exclusion> |
|
198 |
<groupId>tomcat</groupId> |
|
199 |
<artifactId>jasper-compiler</artifactId> |
|
200 |
</exclusion> |
|
201 |
<exclusion> |
|
202 |
<groupId>org.antlr</groupId> |
|
203 |
<artifactId>antlr-runtime</artifactId> |
|
204 |
</exclusion> |
|
205 |
<exclusion> |
|
206 |
<groupId>org.eclipse.jetty.aggregate</groupId> |
|
207 |
<artifactId>jetty-all</artifactId> |
|
208 |
</exclusion> |
|
209 |
<exclusion> |
|
210 |
<groupId>org.slf4j</groupId> |
|
211 |
<artifactId>slf4j-log4j12</artifactId> |
|
212 |
</exclusion> |
|
213 |
<exclusion> |
|
214 |
<groupId>org.glassfish.jersey.core</groupId> |
|
215 |
<artifactId>jersey-client</artifactId> |
|
216 |
</exclusion> |
|
217 |
<exclusion> |
|
218 |
<groupId>org.glassfish.jersey.core</groupId> |
|
219 |
<artifactId>jersey-common</artifactId> |
|
220 |
</exclusion> |
|
221 |
<exclusion> |
|
222 |
<groupId>org.glassfish.jersey.core</groupId> |
|
223 |
<artifactId>jersey-server</artifactId> |
|
224 |
</exclusion> |
|
225 |
<exclusion> |
|
226 |
<groupId>org.glassfish.jersey.containers</groupId> |
|
227 |
<artifactId>jersey-container-servlet</artifactId> |
|
228 |
</exclusion> |
|
229 |
<exclusion> |
|
230 |
<groupId>org.glassfish.jersey.containers</groupId> |
|
231 |
<artifactId>jersey-container-servlet-core</artifactId> |
|
232 |
</exclusion> |
|
233 |
|
|
234 |
<exclusion> |
|
235 |
<groupId>org.codehaus.groovy</groupId> |
|
236 |
<artifactId>groovy-all</artifactId> |
|
237 |
</exclusion> |
|
238 |
|
|
239 |
<exclusion> |
|
240 |
<groupId>org.apache.hive</groupId> |
|
241 |
<artifactId>hive-service</artifactId> |
|
242 |
</exclusion> |
|
243 |
|
|
244 |
<exclusion> |
|
245 |
<groupId>org.apache.spark</groupId> |
|
246 |
<artifactId>spark-core_2.10</artifactId> |
|
247 |
</exclusion> |
|
248 |
<exclusion> |
|
249 |
<groupId>org.apache.spark</groupId> |
|
250 |
<artifactId>spark-sql_2.10</artifactId> |
|
251 |
</exclusion> |
|
252 |
<exclusion> |
|
253 |
<groupId>org.apache.spark</groupId> |
|
254 |
<artifactId>spark-streaming_2.10</artifactId> |
|
255 |
</exclusion> |
|
256 |
<exclusion> |
|
257 |
<groupId>cascading</groupId> |
|
258 |
<artifactId>cascading-hadoop</artifactId> |
|
259 |
</exclusion> |
|
260 |
<exclusion> |
|
261 |
<groupId>cascading</groupId> |
|
262 |
<artifactId>cascading-local</artifactId> |
|
263 |
</exclusion> |
|
264 |
<exclusion> |
|
265 |
<groupId>org.apache.storm</groupId> |
|
266 |
<artifactId>storm-core</artifactId> |
|
267 |
</exclusion> |
|
268 |
<exclusion> |
|
269 |
<groupId>org.apache.pig</groupId> |
|
270 |
<artifactId>pig</artifactId> |
|
271 |
</exclusion> |
|
272 |
</exclusions> |
|
273 |
|
|
194 | 274 |
</dependency> |
195 | 275 |
<dependency> |
196 | 276 |
<groupId>org.mockito</groupId> |
Also available in: Unified diff
force gson to serialise dates in a format that can be undrestood by ElasticSearch, updated elasticsearch-hadoop-mr lib to version 5.2.0