-
Notifications
You must be signed in to change notification settings - Fork 477
/
LogEvent.java
113 lines (89 loc) · 3.34 KB
/
LogEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Copyright 2014-2016 CyberVision, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kaaproject.kaa.server.appenders.mongo.appender;
import static com.mongodb.util.JSON.parse;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoDaoUtil.decodeReservedCharacteres;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoDaoUtil.encodeReservedCharacteres;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import org.kaaproject.kaa.common.dto.logs.LogEventDto;
import org.kaaproject.kaa.server.common.log.shared.appender.data.ProfileInfo;
import org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoDaoUtil;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.io.Serializable;
@Document
public final class LogEvent implements Serializable {
private static final long serialVersionUID = -2738374699172219071L;
@Id
private String id;
private DBObject header;
private DBObject event;
private DBObject clientProfile;
private DBObject serverProfile;
public LogEvent() {
}
public LogEvent(LogEventDto dto, ProfileInfo clientProfile, ProfileInfo serverProfile) {
this.id = dto.getId();
this.header = encodeReservedCharacteres((DBObject) parse(dto.getHeader()));
this.event = encodeReservedCharacteres((DBObject) parse(dto.getEvent()));
this.clientProfile = (clientProfile != null)
? encodeReservedCharacteres((DBObject) parse(clientProfile.getBody())) : null;
this.serverProfile = (serverProfile != null)
? encodeReservedCharacteres((DBObject) parse(serverProfile.getBody())) : null;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public DBObject getEvent() {
return event;
}
public void setEvent(DBObject event) {
this.event = encodeReservedCharacteres(event);
}
public DBObject getHeader() {
return header;
}
public void setHeader(DBObject header) {
this.header = encodeReservedCharacteres(header);
}
public DBObject getClientProfile() {
return clientProfile;
}
public void setClientProfile(DBObject clientProfile) {
this.clientProfile = encodeReservedCharacteres(clientProfile);
}
public DBObject getServerProfile() {
return serverProfile;
}
public void setServerProfile(DBObject serverProfile) {
this.serverProfile = encodeReservedCharacteres(serverProfile);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("LogEvent[");
sb.append("id='").append(id).append('\'');
sb.append(", header=").append(header);
sb.append(", event=").append(event);
sb.append(", clientProfile=").append(clientProfile);
sb.append(", serverProfile=").append(serverProfile);
sb.append(']');
return sb.toString();
}
}