1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.es.log.exentity;
17
18 import java.time.LocalDateTime;
19 import java.time.ZoneId;
20 import java.time.ZonedDateTime;
21 import java.time.format.DateTimeFormatter;
22 import java.util.Map;
23
24 import org.codelibs.fess.entity.SearchLogEvent;
25 import org.codelibs.fess.es.log.bsentity.BsFavoriteLog;
26
27
28
29
30 public class FavoriteLog extends BsFavoriteLog implements SearchLogEvent {
31
32 private static final long serialVersionUID = 1L;
33
34 private Map<String, Object> fields;
35
36 @Override
37 public String getId() {
38 return asDocMeta().id();
39 }
40
41 public void setId(final String id) {
42 asDocMeta().id(id);
43 }
44
45 @Override
46 public Long getVersionNo() {
47 return asDocMeta().version();
48 }
49
50 public void setVersionNo(final Long version) {
51 asDocMeta().version(version);
52 }
53
54 public void addField(final String key, final Object value) {
55 fields.put(key, value);
56 }
57
58 public String getLogMessage() {
59 return getUrl();
60 }
61
62 public LocalDateTime getRequestedAt() {
63 return getCreatedAt();
64 }
65
66 @Override
67 public Map<String, Object> toSource() {
68 final Map<String, Object> sourceMap = super.toSource();
69 if (fields != null) {
70 sourceMap.putAll(fields);
71 }
72 return sourceMap;
73 }
74
75 @Override
76 protected void addFieldToSource(final Map<String, Object> sourceMap, final String field, final Object value) {
77 if (value instanceof LocalDateTime) {
78 final LocalDateTime ldt = (LocalDateTime) value;
79 final ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
80 super.addFieldToSource(sourceMap, field, DateTimeFormatter.ISO_INSTANT.format(zdt));
81 } else {
82 super.addFieldToSource(sourceMap, field, value);
83 }
84 }
85
86 @Override
87 public String toString() {
88 return "FavoriteLog [createdAt=" + createdAt + ", url=" + url + ", docId=" + docId + ", queryId=" + queryId + ", userInfoId="
89 + userInfoId + ", docMeta=" + docMeta + "]";
90 }
91
92 @Override
93 public String getEventType() {
94 return "favorite";
95 }
96 }