-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStatement.java
More file actions
323 lines (262 loc) · 6.91 KB
/
Statement.java
File metadata and controls
323 lines (262 loc) · 6.91 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
* Copyright 2016-2023 Berry Cloud Ltd. All rights reserved.
*/
package dev.learning.xapi.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import dev.learning.xapi.model.validation.constraints.ValidActor;
import dev.learning.xapi.model.validation.constraints.ValidAuthority;
import dev.learning.xapi.model.validation.constraints.ValidStatementPlatform;
import dev.learning.xapi.model.validation.constraints.ValidStatementRevision;
import dev.learning.xapi.model.validation.constraints.ValidStatementVerb;
import dev.learning.xapi.model.validation.constraints.Variant;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.With;
/**
* This class represents the xAPI Statement object.
*
* @author Thomas Turrell-Croft
* @author István Rátkai (Selindek)
*
* @see <a href=
* "https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#statement-properties">xAPI
* Statement</a>
*/
@With
@Value
@ValidStatementPlatform
@ValidStatementRevision
@ValidStatementVerb
@Builder(toBuilder = true)
@JsonInclude(Include.NON_EMPTY)
@EqualsAndHashCode(of = {"actor", "verb", "object", "result", "context"})
public class Statement implements CoreStatement {
/**
* UUID assigned by LRS if not set by the Learning Record Provider.
*/
@Variant(2)
private UUID id;
/**
* Whom the Statement is about, as an Agent or Group Object.
*/
@NotNull
@Valid
@ValidActor
private Actor actor;
/**
* Action taken by the Actor.
*/
@NotNull
@Valid
private Verb verb;
/**
* Activity, Agent, or another Statement that is the Object of the Statement.
*/
@NotNull
@Valid
@ValidActor
private StatementObject object;
/**
* Result Object, further details representing a measured outcome.
*/
@Valid
private Result result;
/**
* Context that gives the Statement more meaning.
*/
@Valid
private Context context;
/**
* Timestamp of when the events described within this Statement occurred.
*/
private Instant timestamp;
/**
* Timestamp of when this Statement was recorded.
*/
private Instant stored;
/**
* Agent or Group who is asserting this Statement is true.
*/
@ValidActor
@ValidAuthority
private Actor authority;
/**
* The Statement’s associated xAPI version.
*/
@Pattern(regexp = "^1\\.0(\\.\\d)?$")
private String version;
/**
* Headers for Attachments to the Statement.
*/
@JsonFormat(without = {JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY})
private List<Attachment> attachments;
// **Warning** do not add fields that are not required by the xAPI specification.
/**
* Builder for Statement.
*/
public static class Builder {
// This static class extends the lombok builder.
/**
* Consumer Builder for agent.
*
* @param agent The Consumer Builder for agent
*
* @return This builder
*
* @see Statement#actor
*/
public Builder actor(Consumer<Agent.Builder<?, ?>> agent) {
// TODO Handle a Group Builder
final Agent.Builder<?, ?> builder = Agent.builder();
agent.accept(builder);
return actor(builder.build());
}
/**
* Sets the agent.
*
* @param actor The actor of the Statement
*
* @return This builder
*
* @see Statement#actor
*/
public Builder actor(Actor actor) {
this.actor = actor;
return this;
}
/**
* Consumer Builder for verb.
*
* @param verb The Consumer Builder for verb
*
* @return This builder
*
* @see Statement#verb
*/
public Builder verb(Consumer<Verb.Builder> verb) {
final Verb.Builder builder = Verb.builder();
verb.accept(builder);
return verb(builder.build());
}
/**
* Sets the verb.
*
* @param verb The definition of the Statement
*
* @return This builder
*
* @see Statement#verb
*/
public Builder verb(Verb verb) {
this.verb = verb;
return this;
}
/**
* Consumer Builder for result.
*
* @param result The Consumer Builder for result
*
* @return This builder
*
* @see Statement#result
*/
public Builder result(Consumer<Result.Builder> result) {
final Result.Builder builder = Result.builder();
result.accept(builder);
return result(builder.build());
}
/**
* Sets the result.
*
* @param result The result of the Statement
*
* @return This builder
*
* @see Statement#result
*/
public Builder result(Result result) {
this.result = result;
return this;
}
/**
* Consumer Builder for context.
*
* @param authority The Consumer Builder for authority
*
* @return This builder
*
* @see Statement#authority
*/
public Builder agentAuthority(Consumer<Agent.Builder<?, ?>> authority) {
final Agent.Builder<?, ?> builder = Agent.builder();
authority.accept(builder);
return authority(builder.build());
}
/**
* Consumer Builder for activity object.
*
* @param activity The Consumer Builder for activity object
*
* @return This builder
*
* @see Statement#object
*/
public Builder activityObject(Consumer<Activity.Builder> activity) {
final Activity.Builder builder = Activity.builder();
activity.accept(builder);
return object(builder.build());
}
/**
* Consumer Builder for statement reference object.
*
* @param statementReference The Consumer Builder for statement reference object
*
* @return This builder
*
* @see Statement#object
*/
public Builder statementReferenceObject(
Consumer<StatementReference.Builder> statementReference) {
final StatementReference.Builder builder = StatementReference.builder();
statementReference.accept(builder);
return object(builder.build());
}
/**
* Consumer Builder for context.
*
* @param context The Consumer Builder for context
*
* @return This builder
*
* @see Statement#context
*/
public Builder context(Consumer<Context.Builder> context) {
final Context.Builder builder = Context.builder();
context.accept(builder);
return context(builder.build());
}
/**
* Sets the context.
*
* @param context The context of the Statement
*
* @return This builder
*
* @see Statement#context
*/
public Builder context(Context context) {
this.context = context;
return this;
}
}
}