Skip to content

Commit f1ffaeb

Browse files
committed
Merge pull request #10 from RusticiSoftware/ells/further-1.0-changes
Further 1.0 Changes
2 parents b48307a + 8ff9078 commit f1ffaeb

39 files changed

+942
-654
lines changed

src/main/java/com/rusticisoftware/tincan/ActivityDefinition.java

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
Copyright 2013 Rustici Software
33
44
Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,6 +17,7 @@
1717

1818
import static com.rusticisoftware.tincan.InteractionType.getByString;
1919

20+
import java.net.URI;
2021
import java.net.URISyntaxException;
2122
import java.util.ArrayList;
2223
import java.util.Iterator;
@@ -41,7 +42,7 @@
4142
public class ActivityDefinition extends JSONBase {
4243
private LanguageMap name;
4344
private LanguageMap description;
44-
private String type;
45+
private URI type;
4546
private Extensions extensions;
4647
private InteractionType interactionType;
4748
private ArrayList<String> correctResponsesPattern;
@@ -50,13 +51,13 @@ public class ActivityDefinition extends JSONBase {
5051
private ArrayList<InteractionComponent> source;
5152
private ArrayList<InteractionComponent> target;
5253
private ArrayList<InteractionComponent> steps;
53-
54+
5455
public ActivityDefinition(JsonNode jsonNode) throws URISyntaxException {
5556
this();
5657

5758
JsonNode typeNode = jsonNode.path("type");
5859
if (! typeNode.isMissingNode()) {
59-
this.setType(typeNode.textValue());
60+
this.setType(new URI(typeNode.textValue()));
6061
}
6162

6263
JsonNode nameNode = jsonNode.path("name");
@@ -84,60 +85,48 @@ public ActivityDefinition(JsonNode jsonNode) throws URISyntaxException {
8485
JsonNode correctResponsesPatternNode = jsonNode.path("correctResponsesPattern");
8586
if (! correctResponsesPatternNode.isMissingNode()) {
8687
this.correctResponsesPattern = new ArrayList<String>();
87-
88-
Iterator it = correctResponsesPatternNode.elements();
89-
while(it.hasNext()) {
90-
this.correctResponsesPattern.add(((JsonNode) it.next()).textValue());
88+
for (JsonNode element : correctResponsesPatternNode) {
89+
this.correctResponsesPattern.add(element.textValue());
9190
}
9291
}
9392

9493
JsonNode choicesNode = jsonNode.path("choices");
9594
if (! choicesNode.isMissingNode()) {
9695
this.choices = new ArrayList<InteractionComponent>();
97-
98-
Iterator it = choicesNode.elements();
99-
while(it.hasNext()) {
100-
this.choices.add(new InteractionComponent((JsonNode) it.next()));
96+
for (JsonNode element : choicesNode) {
97+
this.choices.add(new InteractionComponent(element));
10198
}
10299
}
103100

104101
JsonNode scaleNode = jsonNode.path("scale");
105102
if (! scaleNode.isMissingNode()) {
106103
this.scale = new ArrayList<InteractionComponent>();
107-
108-
Iterator it = scaleNode.elements();
109-
while(it.hasNext()) {
110-
this.scale.add(new InteractionComponent((JsonNode) it.next()));
104+
for (JsonNode element : scaleNode) {
105+
this.scale.add(new InteractionComponent(element));
111106
}
112107
}
113108

114109
JsonNode sourceNode = jsonNode.path("source");
115110
if (! sourceNode.isMissingNode()) {
116111
this.source = new ArrayList<InteractionComponent>();
117-
118-
Iterator it = sourceNode.elements();
119-
while(it.hasNext()) {
120-
this.source.add(new InteractionComponent((JsonNode) it.next()));
112+
for (JsonNode element : sourceNode) {
113+
this.source.add(new InteractionComponent(element));
121114
}
122115
}
123116

124117
JsonNode targetNode = jsonNode.path("target");
125118
if (! targetNode.isMissingNode()) {
126119
this.target = new ArrayList<InteractionComponent>();
127-
128-
Iterator it = targetNode.elements();
129-
while(it.hasNext()) {
130-
this.target.add(new InteractionComponent((JsonNode) it.next()));
120+
for (JsonNode element : targetNode) {
121+
this.target.add(new InteractionComponent(element));
131122
}
132123
}
133124

134125
JsonNode stepsNode = jsonNode.path("steps");
135126
if (! stepsNode.isMissingNode()) {
136127
this.steps = new ArrayList<InteractionComponent>();
137-
138-
Iterator it = stepsNode.elements();
139-
while(it.hasNext()) {
140-
this.steps.add(new InteractionComponent((JsonNode) it.next()));
128+
for (JsonNode element : stepsNode) {
129+
this.steps.add(new InteractionComponent(element));
141130
}
142131
}
143132
}
@@ -165,7 +154,7 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
165154
node.put("description", this.getDescription().toJSONNode(version));
166155
}
167156
if (this.type != null) {
168-
node.put("type", this.getType());
157+
node.put("type", this.getType().toString());
169158
}
170159
if (this.extensions != null) {
171160
node.put("extensions", this.getExtensions().toJSONNode(version));
@@ -244,4 +233,12 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
244233
}
245234
return node;
246235
}
236+
237+
public void setType(URI type) {
238+
this.type = type;
239+
}
240+
241+
public void setType(String type) throws URISyntaxException {
242+
this.setType(new URI(type));
243+
}
247244
}

src/main/java/com/rusticisoftware/tincan/Agent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected Agent(JsonNode jsonNode) {
6161
this.setMbox(mboxNode.textValue());
6262
}
6363

64-
JsonNode mboxSHA1SumNode = jsonNode.path("mboxSHA1Sum");
64+
JsonNode mboxSHA1SumNode = jsonNode.path("mbox_sha1sum");
6565
if (! mboxSHA1SumNode.isMissingNode()) {
6666
this.setMboxSHA1Sum(mboxSHA1SumNode.textValue());
6767
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
Copyright 2013 Rustici Software
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package com.rusticisoftware.tincan;
17+
18+
import java.net.MalformedURLException;
19+
import java.net.URI;
20+
import java.net.URISyntaxException;
21+
import java.net.URL;
22+
23+
import com.fasterxml.jackson.databind.JsonNode;
24+
import com.fasterxml.jackson.databind.node.ObjectNode;
25+
import com.rusticisoftware.tincan.json.JSONBase;
26+
import com.rusticisoftware.tincan.json.Mapper;
27+
28+
import lombok.Data;
29+
import lombok.EqualsAndHashCode;
30+
import lombok.NoArgsConstructor;
31+
32+
/**
33+
* Attachment Class
34+
*/
35+
@Data
36+
@EqualsAndHashCode(callSuper = false)
37+
@NoArgsConstructor
38+
public class Attachment extends JSONBase {
39+
private URI usageType;
40+
private LanguageMap display;
41+
private LanguageMap description;
42+
private String contentType;
43+
private Integer length;
44+
private String sha2;
45+
private URL fileUrl;
46+
47+
public Attachment(JsonNode jsonNode) throws URISyntaxException, MalformedURLException {
48+
JsonNode usageTypeNode = jsonNode.path("usageType");
49+
if (! usageTypeNode.isMissingNode()) {
50+
this.setUsageType(new URI(usageTypeNode.textValue()));
51+
}
52+
53+
JsonNode displayNode = jsonNode.path("display");
54+
if (! displayNode.isMissingNode()) {
55+
this.setDisplay(new LanguageMap(displayNode));
56+
}
57+
58+
JsonNode descriptionNode = jsonNode.path("description");
59+
if (! descriptionNode.isMissingNode()) {
60+
this.setDescription(new LanguageMap(descriptionNode));
61+
}
62+
63+
JsonNode contentTypeNode = jsonNode.path("contentType");
64+
if (! contentTypeNode.isMissingNode()) {
65+
this.setContentType(contentTypeNode.textValue());
66+
}
67+
68+
JsonNode lengthNode = jsonNode.path("length");
69+
if (! lengthNode.isMissingNode()) {
70+
this.setLength(lengthNode.intValue());
71+
}
72+
73+
JsonNode sha2Node = jsonNode.path("sha2");
74+
if (! sha2Node.isMissingNode()) {
75+
this.setSha2(sha2Node.textValue());
76+
}
77+
78+
JsonNode fileUrlNode = jsonNode.path("fileUrl");
79+
if (! fileUrlNode.isMissingNode()) {
80+
this.setFileUrl(new URL(fileUrlNode.textValue()));
81+
}
82+
}
83+
84+
@Override
85+
public ObjectNode toJSONNode(TCAPIVersion version) {
86+
ObjectNode node = Mapper.getInstance().createObjectNode();
87+
if (this.getUsageType() != null) {
88+
node.put("usageType", this.getUsageType().toString());
89+
}
90+
if (this.getDisplay() != null) {
91+
node.put("display", this.getDisplay().toJSONNode(version));
92+
}
93+
if (this.getDescription() != null) {
94+
node.put("description", this.getDescription().toJSONNode(version));
95+
}
96+
if (this.getContentType() != null) {
97+
node.put("contentType", this.getContentType());
98+
}
99+
if (this.getLength() != null) {
100+
node.put("length", this.getLength());
101+
}
102+
if (this.getSha2() != null) {
103+
node.put("sha2", this.getSha2());
104+
}
105+
if (this.getFileUrl() != null) {
106+
node.put("fileUrl", this.getFileUrl().toString());
107+
}
108+
return node;
109+
}
110+
}

src/main/java/com/rusticisoftware/tincan/Context.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.rusticisoftware.tincan;
1717

18+
import java.net.MalformedURLException;
1819
import java.net.URISyntaxException;
1920
import java.util.UUID;
2021

@@ -44,7 +45,7 @@ public class Context extends JSONBase {
4445
private SubStatement statement;
4546
private Extensions extensions;
4647

47-
public Context(JsonNode jsonNode) throws URISyntaxException {
48+
public Context(JsonNode jsonNode) throws MalformedURLException, URISyntaxException {
4849
this();
4950

5051
JsonNode registrationNode = jsonNode.path("registration");

src/main/java/com/rusticisoftware/tincan/ContextActivities.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.net.URISyntaxException;
1919
import java.util.ArrayList;
20-
import java.util.Iterator;
2120
import java.util.List;
2221

2322
import lombok.Data;
@@ -42,6 +41,7 @@ public class ContextActivities extends JSONBase {
4241
private List<Activity> parent;
4342
private List<Activity> grouping;
4443
private List<Activity> other;
44+
private List<Activity> category;
4545

4646
public ContextActivities(JsonNode jsonNode) throws URISyntaxException {
4747
this();
@@ -51,9 +51,8 @@ public ContextActivities(JsonNode jsonNode) throws URISyntaxException {
5151
this.parent = new ArrayList<Activity>();
5252

5353
if (parentNode.isArray()) {
54-
Iterator it = parentNode.elements();
55-
while(it.hasNext()) {
56-
this.parent.add(new Activity((JsonNode) it.next()));
54+
for (JsonNode element : parentNode) {
55+
this.parent.add(new Activity(element));
5756
}
5857
}
5958
else {
@@ -66,9 +65,8 @@ public ContextActivities(JsonNode jsonNode) throws URISyntaxException {
6665
this.grouping = new ArrayList<Activity>();
6766

6867
if (groupingNode.isArray()) {
69-
Iterator it = groupingNode.elements();
70-
while(it.hasNext()) {
71-
this.grouping.add(new Activity((JsonNode) it.next()));
68+
for (JsonNode element : groupingNode) {
69+
this.grouping.add(new Activity(element));
7270
}
7371
}
7472
else {
@@ -80,16 +78,29 @@ public ContextActivities(JsonNode jsonNode) throws URISyntaxException {
8078
if (! otherNode.isMissingNode()) {
8179
this.other = new ArrayList<Activity>();
8280

83-
if (parentNode.isArray()) {
84-
Iterator it = otherNode.elements();
85-
while(it.hasNext()) {
86-
this.other.add(new Activity((JsonNode) it.next()));
81+
if (otherNode.isArray()) {
82+
for (JsonNode element : otherNode) {
83+
this.other.add(new Activity(element));
8784
}
8885
}
8986
else {
9087
this.other.add(new Activity(otherNode));
9188
}
9289
}
90+
91+
JsonNode categoryNode = jsonNode.path("category");
92+
if (! categoryNode.isMissingNode()) {
93+
this.category = new ArrayList<Activity>();
94+
95+
if (categoryNode.isArray()) {
96+
for (JsonNode element : otherNode) {
97+
this.category.add(new Activity(element));
98+
}
99+
}
100+
else {
101+
this.category.add(new Activity(otherNode));
102+
}
103+
}
93104
}
94105

95106
@Override
@@ -148,6 +159,16 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
148159
}
149160
}
150161
}
162+
if (this.category != null && this.category.size() > 0) {
163+
if (version.ordinal() <= TCAPIVersion.V100.ordinal()) {
164+
ArrayNode category = mapper.createArrayNode();
165+
node.put("category", category);
166+
167+
for (Activity element : this.getOther()) {
168+
category.add(element.toJSONNode(version));
169+
}
170+
}
171+
}
151172

152173
return node;
153174
}

src/main/java/com/rusticisoftware/tincan/Extensions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
import com.fasterxml.jackson.databind.JsonNode;
2828
import com.fasterxml.jackson.databind.node.ObjectNode;
29+
import com.rusticisoftware.tincan.json.JSONBase;
2930
import com.rusticisoftware.tincan.json.Mapper;
3031
import com.rusticisoftware.tincan.json.StringOfJSON;
3132

3233
/**
3334
* Extensions model class
3435
*/
3536
@NoArgsConstructor
36-
public class Extensions {
37+
public class Extensions extends JSONBase {
3738
private final HashMap<URI,JsonNode> _map = new HashMap<URI,JsonNode>();
3839

3940
public Extensions(JsonNode jsonNode) throws URISyntaxException {

src/main/java/com/rusticisoftware/tincan/Group.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Group(JsonNode jsonNode) {
5656
@Override
5757
public ObjectNode toJSONNode(TCAPIVersion version) {
5858
ObjectNode node = super.toJSONNode(version);
59-
if (this.getMembers() != null) {
59+
if (this.getMembers() != null && this.getMembers().size() > 0) {
6060
ArrayNode memberNode = Mapper.getInstance().createArrayNode();
6161
for (Agent member : this.getMembers()) {
6262
memberNode.add(member.toJSONNode(version));

0 commit comments

Comments
 (0)