16
16
package org .trellisldp .api ;
17
17
18
18
import static java .util .Collections .emptySet ;
19
+ import static java .util .Collections .unmodifiableMap ;
19
20
import static java .util .Objects .requireNonNull ;
20
21
import static java .util .Optional .ofNullable ;
21
22
23
+ import java .util .HashMap ;
24
+ import java .util .Map ;
22
25
import java .util .Optional ;
23
26
import java .util .Set ;
24
27
@@ -36,9 +39,11 @@ public final class Metadata {
36
39
private final IRI membershipResource ;
37
40
private final IRI memberOfRelation ;
38
41
private final IRI insertedContentRelation ;
42
+ private final IRI agent ;
39
43
private final BinaryMetadata binary ;
40
44
private final Set <IRI > graphNames ;
41
45
private final String revision ;
46
+ private final Map <String , String > properties ;
42
47
43
48
/**
44
49
* A Metadata-bearing data structure for use with resource manipulation.
@@ -50,26 +55,31 @@ public final class Metadata {
50
55
* @param memberRelation an LDP hasMemberRelation predicate, may be {@code null}
51
56
* @param memberOfRelation an LDP isMemberOfRelation predicate, may be {@code null}
52
57
* @param insertedContentRelation an LDP insertedContentRelation, may be {@code null}
58
+ * @param agent the agent associated with the operation, may be {@code null}
53
59
* @param binary metadata about a BinaryMetadata, may be {@code null}
54
60
* @param revision a revision value, may be {@code null}. This value may be used by a
55
61
* {@link ResourceService} implementation for additional concurrency control.
56
62
* This value would typically be used in tandem with the {@link Resource#getRevision}
57
63
* method.
58
64
* @param graphNames a collection of metadata graphNames
65
+ * @param properties a collection of additional properties
59
66
*/
60
67
private Metadata (final IRI identifier , final IRI ixnModel , final IRI container , final IRI membershipResource ,
61
- final IRI memberRelation , final IRI memberOfRelation , final IRI insertedContentRelation ,
62
- final BinaryMetadata binary , final String revision , final Set <IRI > graphNames ) {
68
+ final IRI memberRelation , final IRI memberOfRelation , final IRI insertedContentRelation , final IRI agent ,
69
+ final BinaryMetadata binary , final String revision , final Set <IRI > graphNames ,
70
+ final Map <String , String > properties ) {
63
71
this .identifier = requireNonNull (identifier , "Identifier cannot be null!" );
64
72
this .ixnModel = requireNonNull (ixnModel , "Interaction model cannot be null!" );
65
73
this .container = container ;
66
74
this .membershipResource = membershipResource ;
67
75
this .memberRelation = memberRelation ;
68
76
this .memberOfRelation = memberOfRelation ;
69
77
this .insertedContentRelation = insertedContentRelation ;
78
+ this .agent = agent ;
70
79
this .binary = binary ;
71
80
this .revision = revision ;
72
81
this .graphNames = graphNames ;
82
+ this .properties = properties ;
73
83
}
74
84
75
85
/**
@@ -129,6 +139,14 @@ public Optional<IRI> getContainer() {
129
139
return ofNullable (container );
130
140
}
131
141
142
+ /**
143
+ * Retrieve the agent associated with this opertation, if known.
144
+ * @return the agent identified with a WebID
145
+ */
146
+ public Optional <IRI > getAgent () {
147
+ return ofNullable (agent );
148
+ }
149
+
132
150
/**
133
151
* Retrieve the membership resource if this is an LDP Direct or Indirect container.
134
152
*
@@ -194,6 +212,14 @@ public Optional<String> getRevision() {
194
212
return ofNullable (revision );
195
213
}
196
214
215
+ /**
216
+ * Retrieve any additional properties.
217
+ * @return an immutable collection of properties
218
+ */
219
+ public Map <String , String > getProperties () {
220
+ return properties ;
221
+ }
222
+
197
223
/**
198
224
* A mutable builder for a {@link Metadata} object.
199
225
*/
@@ -205,9 +231,11 @@ public static final class Builder {
205
231
private IRI membershipResource ;
206
232
private IRI memberOfRelation ;
207
233
private IRI insertedContentRelation ;
234
+ private IRI agent ;
208
235
private BinaryMetadata binary ;
209
236
private String revision ;
210
237
private Set <IRI > graphNames = emptySet ();
238
+ private Map <String , String > properties = new HashMap <>();
211
239
212
240
/**
213
241
* Create a Metadata builder with the provided identifier.
@@ -277,6 +305,16 @@ public Builder insertedContentRelation(final IRI insertedContentRelation) {
277
305
return this ;
278
306
}
279
307
308
+ /**
309
+ * Set the agent value.
310
+ * @param agent the agent associated with the operation
311
+ * @return this builder
312
+ */
313
+ public Builder agent (final IRI agent ) {
314
+ this .agent = agent ;
315
+ return this ;
316
+ }
317
+
280
318
/**
281
319
* Set the binary metadata.
282
320
* @param binary the binary metadata
@@ -307,13 +345,24 @@ public Builder revision(final String revision) {
307
345
return this ;
308
346
}
309
347
348
+ /**
349
+ * Set a property on the resource metadata.
350
+ * @param key the property key
351
+ * @param value the property value
352
+ * @return this builder
353
+ */
354
+ public Builder property (final String key , final String value ) {
355
+ this .properties .put (key , value );
356
+ return this ;
357
+ }
358
+
310
359
/**
311
360
* Build the Metadata object, transitioning this builder to the built state.
312
361
* @return the built Metadata
313
362
*/
314
363
public Metadata build () {
315
364
return new Metadata (identifier , ixnModel , container , membershipResource , memberRelation , memberOfRelation ,
316
- insertedContentRelation , binary , revision , graphNames );
365
+ insertedContentRelation , agent , binary , revision , graphNames , unmodifiableMap ( properties ) );
317
366
}
318
367
}
319
368
}
0 commit comments