1818import java .io .IOException ;
1919import java .net .MalformedURLException ;
2020import java .net .URISyntaxException ;
21- import java .util .ArrayList ;
2221import java .util .List ;
2322import java .util .UUID ;
2423
3130import org .joda .time .format .ISODateTimeFormat ;
3231
3332import com .fasterxml .jackson .databind .JsonNode ;
34- import com .fasterxml .jackson .databind .node .ArrayNode ;
3533import 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 ;
3835import com .rusticisoftware .tincan .json .StringOfJSON ;
3936
4037/**
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 }
0 commit comments