3535import org .sensorhub .impl .service .consys .resource .ResourceBindingJson ;
3636import org .sensorhub .impl .service .consys .resource .ResourceLink ;
3737import org .sensorhub .impl .service .consys .task .CommandHandler .CommandHandlerContextData ;
38+ import org .sensorhub .utils .SWEDataUtils ;
3839import org .vast .cdm .common .DataStreamWriter ;
3940import org .vast .swe .BinaryDataWriter ;
4041import org .vast .swe .IComponentFilter ;
4142import org .vast .swe .SWEConstants ;
43+ import org .vast .swe .ScalarIndexer ;
4244import org .vast .swe .fast .JsonDataParserGson ;
4345import org .vast .swe .fast .JsonDataWriterGson ;
4446import org .vast .util .ReaderException ;
@@ -56,6 +58,7 @@ public class CommandBindingJson extends ResourceBindingJson<BigId, ICommandData>
5658 ICommandStore cmdStore ;
5759 JsonDataParserGson paramsReader ;
5860 Map <BigId , DataStreamWriter > paramsWriters ;
61+ ScalarIndexer timeStampIndexer ;
5962 String userID ;
6063
6164
@@ -68,6 +71,7 @@ public CommandBindingJson(RequestContext ctx, IdEncoders idEncoders, boolean for
6871 if (forReading )
6972 {
7073 this .paramsReader = getSweCommonParser (contextData .csInfo , reader );
74+ this .timeStampIndexer = SWEDataUtils .getTimeStampIndexer (contextData .csInfo .getRecordStructure ());
7175
7276 var user = ctx .getSecurityHandler ().getCurrentUser ();
7377 this .userID = user != null ? user .getId () : "api" ;
@@ -104,16 +108,21 @@ public ICommandData deserialize(JsonReader reader) throws IOException
104108 try
105109 {
106110 reader .beginObject ();
107-
111+
108112 while (reader .hasNext ())
109113 {
110114 var propName = reader .nextName ();
111115
112- if ("issueTime" .equals (propName ))
113- cmd .withIssueTime (OffsetDateTime .parse (reader .nextString ()).toInstant ());
116+ if ("issueTime" .equals (propName )) {
117+ if (reader .peek () != JsonToken .NULL ) {
118+ cmd .withIssueTime (OffsetDateTime .parse (reader .nextString ()).toInstant ());
119+ } else {
120+ reader .nextNull ();
121+ }
122+ }
114123 //else if ("foi".equals(propName))
115124 // obs.withFoi(id)
116- else if ("params " .equals (propName ))
125+ else if ("parameters " .equals (propName ))
117126 {
118127 var result = paramsReader .parseNextBlock ();
119128 cmd .withParams (result );
@@ -133,11 +142,18 @@ else if ("params".equals(propName))
133142 throw new ResourceParseException (INVALID_JSON_ERROR_MSG + e .getMessage ());
134143 }
135144
136- if (contextData .foiId != null )
145+ if (contextData .foiId != null && contextData . foiId != BigId . NONE )
137146 cmd .withFoi (contextData .foiId );
138147
139- // also set timestamp
140- return cmd .build ();
148+ // set timestamp in params data if present in schema
149+ var newCmd = cmd .build ();
150+ if (timeStampIndexer != null )
151+ {
152+ var issueTimeIdx = timeStampIndexer .getDataIndex (newCmd .getParams ());
153+ newCmd .getParams ().setDoubleValue (issueTimeIdx , newCmd .getIssueTime ().toEpochMilli () / 1000.0 );
154+ }
155+
156+ return newCmd ;
141157 }
142158
143159
0 commit comments