Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5e8958

Browse files
Merge pull request #6 from yetanalytics/lang-tags
Language Tag class
2 parents f234797 + d0080ed commit c5e8958

19 files changed

+557
-105
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@
5252
<artifactId>json-path</artifactId>
5353
<version>2.9.0</version>
5454
</dependency>
55+
<dependency>
56+
<groupId>jakarta.activation</groupId>
57+
<artifactId>jakarta.activation-api</artifactId>
58+
<version>2.1.3</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.semver4j</groupId>
62+
<artifactId>semver4j</artifactId>
63+
<version>5.4.1</version>
64+
</dependency>
5565
<dependency>
5666
<groupId>junit</groupId>
5767
<artifactId>junit</artifactId>

src/main/java/com/yetanalytics/xapi/model/AbstractActor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public abstract class AbstractActor extends AbstractObject {
1515

1616
//IFI
1717
private URI mbox;
18+
// TODO: Validate that mbox_sha1sum is a SHA1, 40-char hex string
1819
private String mbox_sha1sum;
1920
private URI openid;
2021
private Account account;

src/main/java/com/yetanalytics/xapi/model/Attachment.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
import com.fasterxml.jackson.annotation.JsonInclude;
66
import com.fasterxml.jackson.annotation.JsonInclude.Include;
7+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
8+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
9+
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
10+
import com.yetanalytics.xapi.model.deserializers.MimeTypeDeserializer;
11+
12+
import jakarta.activation.MimeType;
713

814
/**
915
* Class representation of the Attachment Component of the
@@ -15,8 +21,11 @@ public class Attachment {
1521
private URI usageType;
1622
private LangMap display;
1723
private LangMap description;
18-
private String contentType;
24+
@JsonDeserialize(using = MimeTypeDeserializer.class)
25+
@JsonSerialize(using = ToStringSerializer.class)
26+
private MimeType contentType;
1927
private Integer length;
28+
// TODO: Validate that sha2 is a SHA256, 64-char hex string
2029
private String sha2;
2130
private URI fileUrl;
2231

@@ -38,10 +47,10 @@ public LangMap getDescription() {
3847
public void setDescription(LangMap description) {
3948
this.description = description;
4049
}
41-
public String getContentType() {
50+
public MimeType getContentType() {
4251
return contentType;
4352
}
44-
public void setContentType(String contentType) {
53+
public void setContentType(MimeType contentType) {
4554
this.contentType = contentType;
4655
}
4756
public Integer getLength() {

src/main/java/com/yetanalytics/xapi/model/Context.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Context {
1717
private ContextActivities contextActivities;
1818
private String revision;
1919
private String platform;
20-
private String language;
20+
private LangTag language;
2121
private StatementRef statement;
2222
private Extensions extensions;
2323

@@ -57,10 +57,10 @@ public String getPlatform() {
5757
public void setPlatform(String platform) {
5858
this.platform = platform;
5959
}
60-
public String getLanguage() {
60+
public LangTag getLanguage() {
6161
return language;
6262
}
63-
public void setLanguage(String language) {
63+
public void setLanguage(LangTag language) {
6464
this.language = language;
6565
}
6666
public StatementRef getStatement() {

src/main/java/com/yetanalytics/xapi/model/Extensions.java

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.jayway.jsonpath.JsonPath;
1212
import com.jayway.jsonpath.PathNotFoundException;
1313
import com.yetanalytics.xapi.model.deserializers.ExtensionDeserializer;
14-
import com.yetanalytics.xapi.model.serializers.ExtensionSerializer;
14+
import com.yetanalytics.xapi.model.serializers.FreeMapSerializer;
1515
import com.yetanalytics.xapi.util.Mapper;
1616

1717
/**
@@ -22,8 +22,8 @@
2222
* or through a JSONPath API.
2323
*/
2424
@JsonDeserialize(using = ExtensionDeserializer.class)
25-
@JsonSerialize(using = ExtensionSerializer.class)
26-
public class Extensions {
25+
@JsonSerialize(using = FreeMapSerializer.class)
26+
public class Extensions implements IFreeMap<URI, Object>{
2727

2828
private Map<URI, Object> extMap = new HashMap<>();
2929

@@ -33,25 +33,49 @@ public Extensions(Map<URI, Object> input) {
3333

3434
/**
3535
* Sets an entry in the Extensions Map
36-
* @param key the IRI key of the extension
36+
* @param key the URI key of the extension
3737
* @param value The Collections API representation of the JSON Data
3838
*/
39+
@Override
3940
public void put(URI key, Object value) {
4041
extMap.put(key, value);
4142
}
4243

44+
/**
45+
* Sets an entry in the Extensions Map
46+
* @param key the IRI String key of the extension
47+
* @param value The Collections API representation of the JSON Data
48+
* @throws IllegalArgumentException
49+
*/
50+
@Override
51+
public void put(String key, Object value) throws IllegalArgumentException {
52+
put(URI.create(key), value);
53+
}
54+
4355
/**
4456
* Retrieve extension data
45-
* @param key The IRI of the extension
57+
* @param key The URI key of the extension
4658
* @return The Collections API representation of the JSON Data
4759
*/
60+
@Override
4861
public Object get(URI key) {
4962
return extMap.get(key);
5063
}
5164

65+
/**
66+
* Retrieve extension data
67+
* @param key The IRI string key of the extension
68+
* @return The Collections API representation of the JSON Data
69+
* @throws IllegalArgumentException
70+
*/
71+
@Override
72+
public Object get(String key) throws IllegalArgumentException {
73+
return get(URI.create(key));
74+
}
75+
5276
/**
5377
* Attempt a JSONPath query of the Extension data.
54-
* @param key The IRI key of the extension in which to perform the query
78+
* @param key The URI key of the extension in which to perform the query
5579
* @param jsonPathExpression A JSONPath query to perform in the Extension data
5680
* @param typeKey The typereference for the type that the query is expecting to retrieve
5781
* @param <T> The type that the query is expecting to convert the results to
@@ -73,25 +97,52 @@ public <T> T read(URI key, String jsonPathExpression, Class<T> typeKey) {
7397
return null;
7498
}
7599

100+
/**
101+
* Attempt a JSONPath query of the Extension data.
102+
* @param key The IRI String key of the extension in which to perform the query
103+
* @param jsonPathExpression A JSONPath query to perform in the Extension data
104+
* @param typeKey The typereference for the type that the query is expecting to retrieve
105+
* @param <T> The type that the query is expecting to convert the results to
106+
* @return Object of type T that is the result of deserialization from the query
107+
* @throws IllegalArgumentException
108+
*/
109+
public <T> T read(String key, String jsonPathExpression, Class<T> typeKey) throws IllegalArgumentException {
110+
return read(URI.create(key), jsonPathExpression, typeKey);
111+
}
112+
76113
/**
77114
* Remove an extension by IRI key
78-
* @param key the IRI of the extension to remove
115+
* @param key the URI key of the extension to remove
79116
*/
117+
@Override
80118
public void remove(URI key) {
81119
extMap.remove(key);
82120
}
83121

122+
/**
123+
* Remove an extension by IRI key
124+
* @param key the IRI String key of the extension to remove
125+
* @throws IllegalArgumentException
126+
*/
127+
@Override
128+
public void remove(String key) throws IllegalArgumentException {
129+
remove(URI.create(key));
130+
}
131+
84132
/**
85133
* Returns a set of all IRI Extension keys
86134
* @return Set of IRI keys
87135
*/
136+
@Override
88137
public Set<URI> getKeys() {
89138
return extMap.keySet();
90139
}
140+
91141
/**
92142
* Returns the full raw Extension Map as a HashMap&lt;URI, Object&gt;
93143
* @return The raw Extensions Map
94144
*/
145+
@Override
95146
public Map<URI, Object> getMap() {
96147
return extMap;
97148
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.yetanalytics.xapi.model;
2+
3+
import java.util.Map;
4+
import java.util.Set;
5+
6+
/**
7+
* Interface for all freeform maps (Extensions and LangMaps) in xAPI Statements.
8+
*/
9+
public interface IFreeMap<K, V> {
10+
/**
11+
* Sets an entry in the map
12+
* @param key
13+
* @param value
14+
*/
15+
public void put(K key, V value);
16+
17+
/**
18+
* Sets an entry in the map with a String key
19+
* @param key
20+
* @param value
21+
*/
22+
public void put(String key, V value);
23+
24+
/**
25+
* Retrieve value at key
26+
* @param key
27+
* @return The value at the key
28+
*/
29+
public V get(K key);
30+
31+
/**
32+
* Retrieve value at String key
33+
* @param key
34+
* @return The value at the key
35+
*/
36+
public V get(String key);
37+
38+
/**
39+
* Remove a value at the key
40+
* @param key
41+
*/
42+
public void remove(K key);
43+
44+
/**
45+
* Remove a value at the String key
46+
* @param key
47+
*/
48+
public void remove(String key);
49+
50+
/**
51+
* Returns a Set of all the keys
52+
* @return Set of all the keys
53+
*/
54+
public Set<K> getKeys();
55+
56+
/**
57+
* Returns the full Map of the key-value pairs
58+
* @return The full Map
59+
*/
60+
public Map<K, V> getMap();
61+
}

0 commit comments

Comments
 (0)