1
|
|
|
/** |
2
|
|
|
* |
3
|
|
|
*/ |
4
|
|
|
package unicon.matthews.caliper.service.repository; |
5
|
|
|
|
6
|
|
|
import java.io.Serializable; |
7
|
|
|
|
8
|
|
|
import org.apache.commons.lang3.StringUtils; |
9
|
|
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
10
|
|
|
import org.apache.commons.lang3.builder.ToStringStyle; |
11
|
|
|
import org.springframework.data.annotation.Id; |
12
|
|
|
import org.springframework.data.mongodb.core.mapping.Document; |
13
|
|
|
|
14
|
|
|
import unicon.matthews.caliper.Event; |
15
|
|
|
|
16
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
17
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude; |
18
|
|
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author ggilbert |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
@JsonIgnoreProperties(ignoreUnknown=true) |
25
|
|
|
@JsonInclude(JsonInclude.Include.NON_EMPTY) |
26
|
|
|
@JsonDeserialize(builder = MongoEvent.Builder.class) |
27
|
|
|
@Document |
28
|
|
|
public class MongoEvent implements Serializable { |
29
|
|
|
|
30
|
|
|
private static final long serialVersionUID = 1L; |
31
|
|
|
|
32
|
|
|
@Id |
33
|
|
|
private String id; |
34
|
|
|
private String userId; |
35
|
|
|
private String classId; |
36
|
|
|
private String organizationId; |
37
|
|
|
private String tenantId; |
38
|
|
|
private Event event; |
39
|
|
|
|
40
|
|
|
private MongoEvent() {} |
41
|
|
|
|
42
|
|
|
public String getId() { |
43
|
|
|
return id; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public String getUserId() { |
47
|
|
|
return userId; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public String getClassId() { |
51
|
|
|
return classId; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public String getOrganizationId() { |
55
|
|
|
return organizationId; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public String getTenantId() { |
59
|
|
|
return tenantId; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public Event getEvent() { |
63
|
|
|
return event; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
@Override |
67
|
|
|
public String toString() { |
68
|
|
|
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
@Override |
72
|
|
|
public int hashCode() { |
73
|
|
|
final int prime = 31; |
74
|
|
|
int result = 1; |
75
|
|
|
result = prime * result + ((classId == null) ? 0 : classId.hashCode()); |
76
|
|
|
result = prime * result + ((event == null) ? 0 : event.hashCode()); |
77
|
|
|
result = prime * result + ((id == null) ? 0 : id.hashCode()); |
78
|
|
|
result = prime * result + ((organizationId == null) ? 0 : organizationId.hashCode()); |
79
|
|
|
result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode()); |
80
|
|
|
result = prime * result + ((userId == null) ? 0 : userId.hashCode()); |
81
|
|
|
return result; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
@Override |
85
|
|
|
public boolean equals(Object obj) { |
86
|
|
|
if (this == obj) |
87
|
|
|
return true; |
88
|
|
|
if (obj == null) |
89
|
|
|
return false; |
90
|
|
|
if (getClass() != obj.getClass()) |
91
|
|
|
return false; |
92
|
|
|
MongoEvent other = (MongoEvent) obj; |
93
|
|
|
if (classId == null) { |
94
|
|
|
if (other.classId != null) |
95
|
|
|
return false; |
96
|
|
|
} else if (!classId.equals(other.classId)) |
97
|
|
|
return false; |
98
|
|
|
if (event == null) { |
99
|
|
|
if (other.event != null) |
100
|
|
|
return false; |
101
|
|
|
} else if (!event.equals(other.event)) |
102
|
|
|
return false; |
103
|
|
|
if (id == null) { |
104
|
|
|
if (other.id != null) |
105
|
|
|
return false; |
106
|
|
|
} else if (!id.equals(other.id)) |
107
|
|
|
return false; |
108
|
|
|
if (organizationId == null) { |
109
|
|
|
if (other.organizationId != null) |
110
|
|
|
return false; |
111
|
|
|
} else if (!organizationId.equals(other.organizationId)) |
112
|
|
|
return false; |
113
|
|
|
if (tenantId == null) { |
114
|
|
|
if (other.tenantId != null) |
115
|
|
|
return false; |
116
|
|
|
} else if (!tenantId.equals(other.tenantId)) |
117
|
|
|
return false; |
118
|
|
|
if (userId == null) { |
119
|
|
|
if (other.userId != null) |
120
|
|
|
return false; |
121
|
|
|
} else if (!userId.equals(other.userId)) |
122
|
|
|
return false; |
123
|
|
|
return true; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public static class Builder { |
127
|
|
|
private MongoEvent _mongoEvent = new MongoEvent(); |
128
|
|
|
|
129
|
|
|
public Builder withId(String id) { |
130
|
|
|
_mongoEvent.id = id; |
131
|
|
|
return this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public Builder withUserId(String userId) { |
135
|
|
|
_mongoEvent.userId = userId; |
136
|
|
|
return this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public Builder withClassId(String classId) { |
140
|
|
|
_mongoEvent.classId = classId; |
141
|
|
|
return this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public Builder withOrganizationId(String organizationId) { |
145
|
|
|
_mongoEvent.organizationId = organizationId; |
146
|
|
|
return this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public Builder withTenantId(String tenantId) { |
150
|
|
|
_mongoEvent.tenantId = tenantId; |
151
|
|
|
return this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public Builder withEvent(Event event) { |
155
|
|
|
_mongoEvent.event = event; |
156
|
|
|
return this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public MongoEvent build() { |
160
|
|
|
|
161
|
|
|
if (_mongoEvent.event == null |
162
|
|
|
|| StringUtils.isBlank(_mongoEvent.tenantId)) { |
163
|
|
|
throw new IllegalStateException(_mongoEvent.toString()); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return _mongoEvent; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|