Skip to content

Commit 8ff9078

Browse files
committed
Add internal.StatementBase as super class of Statement and SubStatement (to prevent ghost fields on SubStatement). Remove extraneous whitespace.
1 parent 716fa92 commit 8ff9078

File tree

5 files changed

+185
-120
lines changed

5 files changed

+185
-120
lines changed

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

Lines changed: 1 addition & 2 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");
@@ -51,7 +51,6 @@ public class ActivityDefinition extends JSONBase {
5151
private ArrayList<InteractionComponent> source;
5252
private ArrayList<InteractionComponent> target;
5353
private ArrayList<InteractionComponent> steps;
54-
5554

5655
public ActivityDefinition(JsonNode jsonNode) throws URISyntaxException {
5756
this();

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

Lines changed: 8 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.io.IOException;
1919
import java.net.MalformedURLException;
2020
import java.net.URISyntaxException;
21-
import java.util.ArrayList;
2221
import java.util.List;
2322
import java.util.UUID;
2423

@@ -31,10 +30,8 @@
3130
import org.joda.time.format.ISODateTimeFormat;
3231

3332
import com.fasterxml.jackson.databind.JsonNode;
34-
import com.fasterxml.jackson.databind.node.ArrayNode;
3533
import com.fasterxml.jackson.databind.node.ObjectNode;
36-
import com.rusticisoftware.tincan.json.JSONBase;
37-
import com.rusticisoftware.tincan.json.Mapper;
34+
import com.rusticisoftware.tincan.internal.StatementBase;
3835
import com.rusticisoftware.tincan.json.StringOfJSON;
3936

4037
/**
@@ -43,73 +40,23 @@
4340
@Data
4441
@EqualsAndHashCode(callSuper = false)
4542
@NoArgsConstructor
46-
public class Statement extends JSONBase {
43+
public class Statement extends StatementBase {
4744
private UUID id;
48-
private Agent actor;
49-
private Verb verb;
50-
private StatementTarget object;
51-
private Result result;
52-
private Context context;
53-
private DateTime timestamp;
5445
private DateTime stored;
5546
private Agent authority;
5647
private TCAPIVersion version;
57-
private List<Attachment> attachments;
58-
5948

6049
@Deprecated
6150
private Boolean voided;
6251

6352
public Statement(JsonNode jsonNode) throws URISyntaxException, MalformedURLException {
64-
this();
53+
super(jsonNode);
6554

6655
JsonNode idNode = jsonNode.path("id");
6756
if (! idNode.isMissingNode()) {
6857
this.setId(UUID.fromString(idNode.textValue()));
6958
}
7059

71-
JsonNode actorNode = jsonNode.path("actor");
72-
if (! actorNode.isMissingNode()) {
73-
this.setActor(Agent.fromJson(actorNode));
74-
}
75-
76-
JsonNode verbNode = jsonNode.path("verb");
77-
if (! verbNode.isMissingNode()) {
78-
this.setVerb(new Verb(verbNode));
79-
}
80-
81-
JsonNode objectNode = jsonNode.path("object");
82-
if (! objectNode.isMissingNode()) {
83-
String objectType = objectNode.path("objectType").textValue();
84-
if ("Group".equals(objectType) || "Agent".equals(objectType)){
85-
this.setObject(Agent.fromJson(objectNode));
86-
}
87-
else if ("StatementRef".equals(objectType)){
88-
this.setObject(new StatementRef(objectNode));
89-
}
90-
else if ("SubStatement".equals(objectType)) {
91-
this.setObject(new SubStatement(objectNode));
92-
}
93-
else {
94-
this.setObject(new Activity(objectNode));
95-
}
96-
}
97-
98-
JsonNode resultNode = jsonNode.path("result");
99-
if (! resultNode.isMissingNode()) {
100-
this.setResult(new Result(resultNode));
101-
}
102-
103-
JsonNode contextNode = jsonNode.path("context");
104-
if (! contextNode.isMissingNode()) {
105-
this.setContext(new Context(contextNode));
106-
}
107-
108-
JsonNode timestampNode = jsonNode.path("timestamp");
109-
if (! timestampNode.isMissingNode()) {
110-
this.setTimestamp(new DateTime(timestampNode.textValue()));
111-
}
112-
11360
JsonNode storedNode = jsonNode.path("stored");
11461
if (! storedNode.isMissingNode()) {
11562
this.setStored(new DateTime(storedNode.textValue()));
@@ -129,28 +76,14 @@ else if ("SubStatement".equals(objectType)) {
12976
if (! versionNode.isMissingNode()) {
13077
this.setVersion(TCAPIVersion.fromString(versionNode.textValue()));
13178
}
132-
133-
JsonNode attachmentsNode = jsonNode.path("attachments");
134-
if (! attachmentsNode.isMissingNode()) {
135-
this.attachments = new ArrayList<Attachment>();
136-
for (JsonNode element : attachmentsNode) {
137-
this.attachments.add(new Attachment(element));
138-
}
139-
}
14079
}
14180

14281
public Statement(StringOfJSON jsonStr) throws IOException, URISyntaxException {
143-
this(jsonStr.toJSONNode());
82+
super(jsonStr);
14483
}
14584

14685
public Statement(Agent actor, Verb verb, StatementTarget object, Result result, Context context) {
147-
this();
148-
149-
this.setActor(actor);
150-
this.setVerb(verb);
151-
this.setObject(object);
152-
this.setResult(result);
153-
this.setContext(context);
86+
super(actor, verb, object, result, context);
15487
}
15588

15689
public Statement(Agent actor, Verb verb, StatementTarget object) {
@@ -159,25 +92,12 @@ public Statement(Agent actor, Verb verb, StatementTarget object) {
15992

16093
@Override
16194
public ObjectNode toJSONNode(TCAPIVersion version) {
162-
ObjectNode node = Mapper.getInstance().createObjectNode();
95+
ObjectNode node = super.toJSONNode(version);
16396
DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZoneUTC();
16497

16598
if (this.id != null) {
16699
node.put("id", this.getId().toString());
167100
}
168-
node.put("actor", this.getActor().toJSONNode(version));
169-
node.put("verb", this.getVerb().toJSONNode(version));
170-
node.put("object", this.getObject().toJSONNode(version));
171-
172-
if (this.result != null) {
173-
node.put("result", this.getResult().toJSONNode(version));
174-
}
175-
if (this.context != null) {
176-
node.put("context", this.getContext().toJSONNode(version));
177-
}
178-
if (this.timestamp != null) {
179-
node.put("timestamp", fmt.print(this.getTimestamp()));
180-
}
181101
if (this.stored != null) {
182102
node.put("stored", fmt.print(this.getStored()));
183103
}
@@ -197,13 +117,6 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
197117
if (this.getVersion() != null) {
198118
node.put("version", this.getVersion().toString());
199119
}
200-
if (this.getAttachments() != null && this.getAttachments().size() > 0) {
201-
ArrayNode attachmentsNode = Mapper.getInstance().createArrayNode();
202-
for (Attachment attachment : this.getAttachments()) {
203-
attachmentsNode.add(attachment.toJSONNode(version));
204-
}
205-
node.put("attachments", attachmentsNode);
206-
}
207120
}
208121

209122
return node;
@@ -213,10 +126,10 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
213126
* Method to set a random ID and the current date/time in the 'timestamp'
214127
*/
215128
public void stamp() {
216-
if (this.id == null) {
129+
if (this.getId() == null) {
217130
this.setId(UUID.randomUUID());
218131
}
219-
if (this.timestamp == null) {
132+
if (this.getTimestamp() == null) {
220133
this.setTimestamp(new DateTime());
221134
}
222135
}

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717

1818
import java.net.MalformedURLException;
1919
import java.net.URISyntaxException;
20-
import java.util.UUID;
21-
22-
import org.joda.time.DateTime;
2320

2421
import lombok.Data;
2522
import lombok.EqualsAndHashCode;
2623
import lombok.NoArgsConstructor;
2724

2825
import com.fasterxml.jackson.databind.JsonNode;
2926
import com.fasterxml.jackson.databind.node.ObjectNode;
30-
import com.rusticisoftware.tincan.json.JSONBase;
31-
import com.rusticisoftware.tincan.json.Mapper;
27+
import com.rusticisoftware.tincan.internal.StatementBase;
28+
import com.rusticisoftware.tincan.json.StringOfJSON;
3229

3330
/**
3431
* SubStatement Class used when including a statement like object in another statement,
@@ -37,15 +34,15 @@
3734
@Data
3835
@EqualsAndHashCode(callSuper = false)
3936
@NoArgsConstructor
40-
public class SubStatement extends Statement implements StatementTarget {
37+
public class SubStatement extends StatementBase implements StatementTarget {
4138
private final String objectType = "SubStatement";
4239

4340
public SubStatement (JsonNode jsonNode) throws MalformedURLException, URISyntaxException {
4441
super(jsonNode);
4542
}
4643

47-
public SubStatement (String json) throws Exception {
48-
super(Mapper.getInstance().readValue(json, JsonNode.class));
44+
public SubStatement (StringOfJSON jsonStr) throws Exception {
45+
super(jsonStr);
4946
}
5047

5148
@Override
@@ -54,16 +51,4 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
5451
node.put("objectType", this.getObjectType());
5552
return node;
5653
}
57-
58-
public void setId(UUID id) {
59-
}
60-
61-
public void setAuthority(Agent authority) {
62-
}
63-
64-
public void setStored(DateTime stored) {
65-
}
66-
67-
public void setVersion(TCAPIVersion version) {
68-
}
6954
}

0 commit comments

Comments
 (0)