Project

General

Profile

« Previous | Next » 

Revision 58915

using Long for dates in broker events

View differences:

modules/dnet-mapreduce-jobs/trunk/src/main/java/eu/dnetlib/data/mapreduce/hbase/broker/model/Event.java
1 1
package eu.dnetlib.data.mapreduce.hbase.broker.model;
2 2

  
3
import java.util.Date;
4 3
import java.util.Map;
5 4

  
6 5
import com.google.gson.Gson;
7
import com.google.gson.GsonBuilder;
8 6

  
9 7
public class Event {
10 8

  
11
	public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
12

  
13 9
	private String eventId;
14 10

  
15 11
	private String producerId;
......
18 14

  
19 15
	private String payload;
20 16

  
21
	private Date creationDate;
17
	private Long creationDate;
22 18

  
23
	private Date expiryDate;
19
	private Long expiryDate;
24 20

  
25 21
	private boolean instantMessage;
26 22

  
......
28 24

  
29 25
	public Event() {}
30 26

  
31
	public Event(final String producerId, final String eventId, final String topic, final String payload, final Date creationDate, final Date expiryDate,
32
			final boolean instantMessage,
33
			final Map<String, Object> map) {
27
	public Event(final String producerId, final String eventId, final String topic, final String payload, final Long creationDate, final Long expiryDate,
28
		final boolean instantMessage,
29
		final Map<String, Object> map) {
34 30
		this.producerId = producerId;
35 31
		this.eventId = eventId;
36 32
		this.topic = topic;
......
73 69
		this.payload = payload;
74 70
	}
75 71

  
76
	public Date getCreationDate() {
72
	public Long getCreationDate() {
77 73
		return this.creationDate;
78 74
	}
79 75

  
80
	public void setCreationDate(final Date creationDate) {
76
	public void setCreationDate(final Long creationDate) {
81 77
		this.creationDate = creationDate;
82 78
	}
83 79

  
84
	public Date getExpiryDate() {
80
	public Long getExpiryDate() {
85 81
		return this.expiryDate;
86 82
	}
87 83

  
88
	public void setExpiryDate(final Date expiryDate) {
84
	public void setExpiryDate(final Long expiryDate) {
89 85
		this.expiryDate = expiryDate;
90 86
	}
91 87

  
......
106 102
	}
107 103

  
108 104
	public String toJson() {
109

  
110
		final Gson gson = new GsonBuilder()
111
				.setDateFormat(DATE_FORMAT).create();
112

  
113
		return gson.toJson(this);
105
		return new Gson().toJson(this);
114 106
	}
115 107
}
modules/dnet-mapreduce-jobs/trunk/src/main/java/eu/dnetlib/data/mapreduce/hbase/broker/model/EventWrapper.java
25 25

  
26 26
	public Event asBrokerEvent() {
27 27

  
28
		final Date now = new Date();
28
		final long now = new Date().getTime();
29 29

  
30 30
		final Event res = new Event();
31 31

  
32 32
		final String eventId =
33
				calculateEventId(event.getTopic(), event.getMap().get("target_publication_id").toString(), highlightValue);
33
			calculateEventId(event.getTopic(), event.getMap().get("target_publication_id").toString(), highlightValue);
34 34

  
35 35
		res.setEventId(eventId);
36 36
		res.setProducerId(event.getProducerId());
37 37
		res.setPayload(event.getPayload());
38 38
		res.setMap(event.getMap()
39
				.entrySet()
40
				.stream()
41
				.filter(e -> e.getValue().asObject() != null)
42
				.collect(Collectors.toMap(
43
						e -> e.getKey(),
44
						e -> e.getValue().asObject())));
39
			.entrySet()
40
			.stream()
41
			.filter(e -> e.getValue().asObject() != null)
42
			.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().asObject())));
45 43
		res.setTopic(event.getTopic());
46 44
		res.setCreationDate(now);
47 45
		res.setExpiryDate(calculateExpiryDate(now, event.getTthDays()));
......
51 49

  
52 50
	private String calculateEventId(final String topic, final String publicationId, final String value) {
53 51
		return "event-"
54
				+ DigestUtils.md5Hex(topic).substring(0, 6) + "-"
55
				+ DigestUtils.md5Hex(publicationId).substring(0, 8) + "-"
56
				+ DigestUtils.md5Hex(value).substring(0, 8);
52
			+ DigestUtils.md5Hex(topic).substring(0, 6) + "-"
53
			+ DigestUtils.md5Hex(publicationId).substring(0, 8) + "-"
54
			+ DigestUtils.md5Hex(value).substring(0, 8);
57 55
	}
58 56

  
59
	private Date calculateExpiryDate(final Date now, final int ttlDays) {
57
	private Long calculateExpiryDate(final long now, final int ttlDays) {
60 58
		if (ttlDays < 0) {
61 59
			return null;
62 60
		} else if (ttlDays == 0) {
63 61
			return now;
64 62
		} else {
65
			return new Date(now.getTime() + ttlDays * 24 * 60 * 60 * 1000);
63
			return now + ttlDays * 24 * 60 * 60 * 1000;
66 64
		}
67 65
	}
68 66

  
modules/dnet-mapreduce-jobs/trunk/src/main/java/eu/dnetlib/data/mapreduce/hbase/broker/model/MapValue.java
3 3
import java.util.List;
4 4
import java.util.stream.Collectors;
5 5

  
6
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.DateParser;
7 6
import org.apache.commons.lang3.BooleanUtils;
8 7
import org.apache.commons.lang3.StringUtils;
9 8
import org.apache.commons.lang3.math.NumberUtils;
10 9
import org.apache.commons.logging.Log;
11 10
import org.apache.commons.logging.LogFactory;
12 11

  
12
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.DateParser;
13

  
13 14
public class MapValue {
14 15

  
15 16
	private MapValueType type = MapValueType.STRING;
......
100 101
	public String toString() {
101 102
		return String.format("[ type; %s, value: %s ]", getType(), getValue());
102 103
	}
103
	}
104
}
modules/dnet-mapreduce-jobs/trunk/pom.xml
67 67
		<dependency>
68 68
			<groupId>eu.dnetlib</groupId>
69 69
			<artifactId>dnet-openaire-broker-common</artifactId>
70
			<version>[1.0.0,2.0.0)</version>
70
			<version>[2.0.0,3.0.0)</version>
71 71
		</dependency>
72 72
		<dependency>
73 73
			<groupId>com.mycila</groupId>

Also available in: Unified diff