41
41
import org .springframework .web .bind .annotation .RequestParam ;
42
42
import org .springframework .web .bind .annotation .RestController ;
43
43
44
+ import org .springframework .web .client .HttpServerErrorException ;
44
45
import springfox .documentation .annotations .ApiIgnore ;
45
46
import us .dot .its .jpo .ode .plugin .j2735 .timstorage .FrameType .TravelerInfoType ;
46
47
@@ -74,9 +75,8 @@ public void InjectDependencies(TimDbTables _timDbTables, SQLNullHandler _sqlNull
74
75
* @return List of ActiveTim objects
75
76
*/
76
77
@ RequestMapping (value = "/expiring" , method = RequestMethod .GET , produces = "application/json" , headers = "Accept=application/json" )
77
- public ResponseEntity <List <TimUpdateModel >> GetExpiringActiveTims () throws SQLException {
78
- TimUpdateModel activeTim ;
79
- List <TimUpdateModel > activeTims = new ArrayList <TimUpdateModel >();
78
+ public ResponseEntity <List <TimUpdateModel >> GetExpiringActiveTims () {
79
+ List <TimUpdateModel > activeTims = new ArrayList <>();
80
80
81
81
String selectStatement = "SELECT atim.*, tt.type as tim_type_name, tt.description as tim_type_description" ;
82
82
selectStatement += ", t.msg_cnt, t.url_b, t.is_satellite, t.sat_record_id, t.packet_id" ;
@@ -100,72 +100,18 @@ public ResponseEntity<List<TimUpdateModel>> GetExpiringActiveTims() throws SQLEx
100
100
try (Connection connection = dbInteractions .getConnectionPool (); Statement statement = connection .createStatement (); ResultSet rs = statement .executeQuery (selectStatement )) {
101
101
// convert to ActiveTim object
102
102
while (rs .next ()) {
103
- activeTim = new TimUpdateModel ();
104
-
105
- // Active_Tim properties
106
- activeTim .setActiveTimId (rs .getLong ("ACTIVE_TIM_ID" ));
107
- activeTim .setTimId (rs .getLong ("TIM_ID" ));
108
- activeTim .setDirection (rs .getString ("DIRECTION" ));
109
- activeTim .setStartDateTime (rs .getString ("TIM_START" ));
110
- activeTim .setEndDateTime (rs .getString ("TIM_END" ));
111
- activeTim .setExpirationDateTime (rs .getString ("EXPIRATION_DATE" ));
112
- activeTim .setSatRecordId (rs .getString ("SAT_RECORD_ID" ));
113
- activeTim .setClientId (rs .getString ("CLIENT_ID" ));
114
- activeTim .setRoute (rs .getString ("ROUTE" ));
115
-
116
- Coordinate startPoint = null ;
117
- Coordinate endPoint = null ;
118
- BigDecimal startLat = rs .getBigDecimal ("START_LATITUDE" );
119
- BigDecimal startLon = rs .getBigDecimal ("START_LONGITUDE" );
120
- if (!rs .wasNull ()) {
121
- startPoint = new Coordinate (startLat , startLon );
122
- }
123
- activeTim .setStartPoint (startPoint );
124
-
125
- BigDecimal endLat = rs .getBigDecimal ("END_LATITUDE" );
126
- BigDecimal endLon = rs .getBigDecimal ("END_LONGITUDE" );
127
- if (!rs .wasNull ()) {
128
- endPoint = new Coordinate (endLat , endLon );
129
- }
130
- activeTim .setEndPoint (endPoint );
131
-
132
- activeTim .setStartDate_Timestamp (rs .getTimestamp ("TIM_START" , UTCCalendar ));
133
- activeTim .setEndDate_Timestamp (rs .getTimestamp ("TIM_END" , UTCCalendar ));
134
-
135
- // Tim properties
136
- activeTim .setMsgCnt (rs .getInt ("MSG_CNT" ));
137
- activeTim .setUrlB (rs .getString ("URL_B" ));
138
- activeTim .setPacketId (rs .getString ("PACKET_ID" ));
139
-
140
- // Tim Type properties
141
- activeTim .setTimTypeName (rs .getString ("TIM_TYPE_NAME" ));
142
- activeTim .setTimTypeDescription (rs .getString ("TIM_TYPE_DESCRIPTION" ));
143
-
144
- // Region Properties
145
- activeTim .setRegionId (rs .getInt ("REGION_ID" ));
146
- activeTim .setAnchorLat (rs .getBigDecimal ("ANCHOR_LAT" ));
147
- activeTim .setAnchorLong (rs .getBigDecimal ("ANCHOR_LONG" ));
148
-
149
- activeTim .setLaneWidth (rs .getBigDecimal ("LANE_WIDTH" ));
150
- activeTim .setRegionDirection (rs .getString ("REGION_DIRECTION" ));
151
- activeTim .setDirectionality (rs .getString ("DIRECTIONALITY" ));
152
- activeTim .setClosedPath (rs .getBoolean ("CLOSED_PATH" ));
153
- activeTim .setPathId (rs .getInt ("PATH_ID" ));
154
- activeTim .setRegionDescription (rs .getString ("REGION_DESCRIPTION" ));
155
-
156
- // DataFrame properties
157
- activeTim .setDataFrameId (rs .getInt ("DATA_FRAME_ID" ));
158
- activeTim .setDurationTime (rs .getInt ("DURATION_TIME" ));
159
- activeTim .setNotUsed1 ((short ) 0 ); // as of J2735 this should be set to 0 and is ignored
160
- activeTim .setNotUsed ((short ) 0 ); // as of J2735 this should be set to 0 and is ignored
161
- activeTim .setNotUsed3 ((short ) 0 ); // as of J2735 this should be set to 0 and is ignored
162
- activeTim .setNotUsed2 ((short ) 0 ); // as of J2735 this should be set to 0 and is ignored
163
- activeTim .setUrl (rs .getString ("URL" ));
103
+ var activeTim = buildTimUpdateModelFromResultSet (rs );
164
104
165
105
int frameTypeValue = rs .getInt ("FRAME_TYPE" );
166
106
if (!rs .wasNull () && frameTypeValue >= 0 && frameTypeValue < TravelerInfoType .values ().length ) {
167
107
activeTim .setFrameType (TravelerInfoType .values ()[frameTypeValue ]);
168
108
}
109
+ else {
110
+ log .warn ("Could not set frame type from value {} for active tim id {}. Assuming Advisory." , frameTypeValue ,
111
+ activeTim .getActiveTimId ());
112
+ // assume advisory
113
+ activeTim .setFrameType (TravelerInfoType .advisory );
114
+ }
169
115
170
116
// set dataFrame content. it's required for the ODE, so if we didn't record it,
171
117
// assume Advisory
@@ -210,72 +156,18 @@ public ResponseEntity<TimUpdateModel> GetUpdateModelFromActiveTimId(@PathVariabl
210
156
try (Connection connection = dbInteractions .getConnectionPool (); Statement statement = connection .createStatement (); ResultSet rs = statement .executeQuery (selectStatement )) {
211
157
// convert to ActiveTim object
212
158
while (rs .next ()) {
213
- activeTim = new TimUpdateModel ();
214
-
215
159
// Active_Tim properties
216
- activeTim .setActiveTimId (rs .getLong ("ACTIVE_TIM_ID" ));
217
- activeTim .setTimId (rs .getLong ("TIM_ID" ));
218
- activeTim .setDirection (rs .getString ("DIRECTION" ));
219
- activeTim .setStartDateTime (rs .getString ("TIM_START" ));
220
- activeTim .setEndDateTime (rs .getString ("TIM_END" ));
221
- activeTim .setExpirationDateTime (rs .getString ("EXPIRATION_DATE" ));
222
- activeTim .setSatRecordId (rs .getString ("SAT_RECORD_ID" ));
223
- activeTim .setClientId (rs .getString ("CLIENT_ID" ));
224
- activeTim .setRoute (rs .getString ("ROUTE" ));
225
-
226
- Coordinate startPoint = null ;
227
- Coordinate endPoint = null ;
228
- BigDecimal startLat = rs .getBigDecimal ("START_LATITUDE" );
229
- BigDecimal startLon = rs .getBigDecimal ("START_LONGITUDE" );
230
- if (!rs .wasNull ()) {
231
- startPoint = new Coordinate (startLat , startLon );
232
- }
233
- activeTim .setStartPoint (startPoint );
234
-
235
- BigDecimal endLat = rs .getBigDecimal ("END_LATITUDE" );
236
- BigDecimal endLon = rs .getBigDecimal ("END_LONGITUDE" );
237
- if (!rs .wasNull ()) {
238
- endPoint = new Coordinate (endLat , endLon );
239
- }
240
- activeTim .setEndPoint (endPoint );
241
-
242
- activeTim .setStartDate_Timestamp (rs .getTimestamp ("TIM_START" , UTCCalendar ));
243
- activeTim .setEndDate_Timestamp (rs .getTimestamp ("TIM_END" , UTCCalendar ));
244
-
245
- // Tim properties
246
- activeTim .setMsgCnt (rs .getInt ("MSG_CNT" ));
247
- activeTim .setUrlB (rs .getString ("URL_B" ));
248
- activeTim .setPacketId (rs .getString ("PACKET_ID" ));
249
-
250
- // Tim Type properties
251
- activeTim .setTimTypeName (rs .getString ("TIM_TYPE_NAME" ));
252
- activeTim .setTimTypeDescription (rs .getString ("TIM_TYPE_DESCRIPTION" ));
253
-
254
- // Region Properties
255
- activeTim .setRegionId (rs .getInt ("REGION_ID" ));
256
- activeTim .setAnchorLat (rs .getBigDecimal ("ANCHOR_LAT" ));
257
- activeTim .setAnchorLong (rs .getBigDecimal ("ANCHOR_LONG" ));
258
-
259
- activeTim .setLaneWidth (rs .getBigDecimal ("LANE_WIDTH" ));
260
- activeTim .setRegionDirection (rs .getString ("REGION_DIRECTION" ));
261
- activeTim .setDirectionality (rs .getString ("DIRECTIONALITY" ));
262
- activeTim .setClosedPath (rs .getBoolean ("CLOSED_PATH" ));
263
- activeTim .setPathId (rs .getInt ("PATH_ID" ));
264
- activeTim .setRegionDescription (rs .getString ("REGION_DESCRIPTION" ));
265
-
266
- // DataFrame properties
267
- activeTim .setDataFrameId (rs .getInt ("DATA_FRAME_ID" ));
268
- activeTim .setDurationTime (rs .getInt ("DURATION_TIME" ));
269
- activeTim .setNotUsed1 ((short ) 0 ); // as of J2735 2020 this should be set to 0 and is ignored
270
- activeTim .setNotUsed ((short ) 0 ); // as of J2735 2020 this should be set to 0 and is ignored
271
- activeTim .setNotUsed3 ((short ) 0 ); // as of J2735 2020 this should be set to 0 and is ignored
272
- activeTim .setNotUsed2 ((short ) 0 ); // as of J2735 2020 this should be set to 0 and is ignored
273
- activeTim .setUrl (rs .getString ("URL" ));
160
+ activeTim = buildTimUpdateModelFromResultSet (rs );
274
161
275
162
int frameTypeValue = rs .getInt ("FRAME_TYPE" );
276
163
if (!rs .wasNull () && frameTypeValue >= 0 && frameTypeValue < TravelerInfoType .values ().length ) {
277
164
activeTim .setFrameType (TravelerInfoType .values ()[frameTypeValue ]);
278
165
}
166
+ else {
167
+ log .warn ("Could not set frame type from value {} for active tim id {}. Assuming Advisory." , frameTypeValue , activeTimId );
168
+ // assume advisory
169
+ activeTim .setFrameType (TravelerInfoType .advisory );
170
+ }
279
171
280
172
// set dataFrame content. it's required for the ODE, so if we didn't record it,
281
173
// assume Advisory
@@ -373,22 +265,19 @@ public ResponseEntity<List<ActiveTim>> GetActiveTimsNotSent() {
373
265
return ResponseEntity .ok (activeTims );
374
266
}
375
267
376
- @ RequestMapping (value = "/expired" , method = RequestMethod .GET )
377
- public ResponseEntity <List <ActiveTim >> GetExpiredActiveTims () {
378
- List <ActiveTim > activeTims = new ArrayList <ActiveTim >();
379
-
380
- String selectStatement = "select * from ACTIVE_TIM" ;
381
- selectStatement += " WHERE TIM_END <= (NOW() AT TIME ZONE 'UTC')" ;
382
-
383
- try (Connection connection = dbInteractions .getConnectionPool (); Statement statement = connection .createStatement (); ResultSet rs = statement .executeQuery (selectStatement )) {
384
- activeTims = getActiveTimFromRS (rs , false );
385
- } catch (SQLException e ) {
386
- log .error ("Error getting expired active tims" , e );
387
- return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).body (activeTims );
388
- }
389
-
390
- return ResponseEntity .ok (activeTims );
391
- }
268
+ @ RequestMapping (value = "/expired" , method = RequestMethod .GET )
269
+ public ResponseEntity <List <ActiveTim >> GetExpiredActiveTims (@ RequestParam (required = false , defaultValue = "100" ) Integer limit ) {
270
+ String query = "SELECT * FROM ACTIVE_TIM WHERE TIM_END <= (NOW() AT TIME ZONE 'UTC') LIMIT ?" ;
271
+ try (Connection connection = dbInteractions .getConnectionPool (); PreparedStatement preparedStatement = connection .prepareStatement (query )) {
272
+ preparedStatement .setInt (1 , limit );
273
+ try (ResultSet rs = preparedStatement .executeQuery ()) {
274
+ return ResponseEntity .ok (getActiveTimFromRS (rs , false ));
275
+ }
276
+ } catch (SQLException e ) {
277
+ log .error ("Error retrieving expired active tims" , e );
278
+ throw new HttpServerErrorException (HttpStatus .INTERNAL_SERVER_ERROR , "Error retrieving expired active tims" );
279
+ }
280
+ }
392
281
393
282
@ RequestMapping (value = "/indices-rsu/{rsuTarget}" , method = RequestMethod .GET )
394
283
public ResponseEntity <List <Integer >> GetActiveTimIndicesByRsu (@ PathVariable String rsuTarget ) {
@@ -1134,4 +1023,63 @@ public ResponseEntity<Boolean> MarkForDeletion(@PathVariable Long activeTimId) {
1134
1023
}
1135
1024
return ResponseEntity .ok (success );
1136
1025
}
1026
+
1027
+ private TimUpdateModel buildTimUpdateModelFromResultSet (ResultSet rs ) throws SQLException {
1028
+ TimUpdateModel timUpdateModel = new TimUpdateModel ();
1029
+ timUpdateModel .setActiveTimId (rs .getLong ("ACTIVE_TIM_ID" ));
1030
+ timUpdateModel .setTimId (rs .getLong ("TIM_ID" ));
1031
+ timUpdateModel .setDirection (rs .getString ("DIRECTION" ));
1032
+ timUpdateModel .setStartDateTime (rs .getString ("TIM_START" ));
1033
+ timUpdateModel .setEndDateTime (rs .getString ("TIM_END" ));
1034
+ timUpdateModel .setExpirationDateTime (rs .getString ("EXPIRATION_DATE" ));
1035
+ timUpdateModel .setSatRecordId (rs .getString ("SAT_RECORD_ID" ));
1036
+ timUpdateModel .setClientId (rs .getString ("CLIENT_ID" ));
1037
+ timUpdateModel .setRoute (rs .getString ("ROUTE" ));
1038
+
1039
+ Coordinate startPoint = null ;
1040
+ Coordinate endPoint = null ;
1041
+ BigDecimal startLat = rs .getBigDecimal ("START_LATITUDE" );
1042
+ BigDecimal startLon = rs .getBigDecimal ("START_LONGITUDE" );
1043
+ if (!rs .wasNull ()) {
1044
+ startPoint = new Coordinate (startLat , startLon );
1045
+ }
1046
+ timUpdateModel .setStartPoint (startPoint );
1047
+
1048
+ BigDecimal endLat = rs .getBigDecimal ("END_LATITUDE" );
1049
+ BigDecimal endLon = rs .getBigDecimal ("END_LONGITUDE" );
1050
+ if (!rs .wasNull ()) {
1051
+ endPoint = new Coordinate (endLat , endLon );
1052
+ }
1053
+ timUpdateModel .setEndPoint (endPoint );
1054
+
1055
+ timUpdateModel .setStartDate_Timestamp (rs .getTimestamp ("TIM_START" , UTCCalendar ));
1056
+ timUpdateModel .setEndDate_Timestamp (rs .getTimestamp ("TIM_END" , UTCCalendar ));
1057
+
1058
+ // Tim properties
1059
+ timUpdateModel .setMsgCnt (rs .getInt ("MSG_CNT" ));
1060
+ timUpdateModel .setUrlB (rs .getString ("URL_B" ));
1061
+ timUpdateModel .setPacketId (rs .getString ("PACKET_ID" ));
1062
+
1063
+ // Tim Type properties
1064
+ timUpdateModel .setTimTypeName (rs .getString ("TIM_TYPE_NAME" ));
1065
+ timUpdateModel .setTimTypeDescription (rs .getString ("TIM_TYPE_DESCRIPTION" ));
1066
+
1067
+ // Region Properties
1068
+ timUpdateModel .setRegionId (rs .getInt ("REGION_ID" ));
1069
+ timUpdateModel .setAnchorLat (rs .getBigDecimal ("ANCHOR_LAT" ));
1070
+ timUpdateModel .setAnchorLong (rs .getBigDecimal ("ANCHOR_LONG" ));
1071
+
1072
+ timUpdateModel .setLaneWidth (rs .getBigDecimal ("LANE_WIDTH" ));
1073
+ timUpdateModel .setRegionDirection (rs .getString ("REGION_DIRECTION" ));
1074
+ timUpdateModel .setDirectionality (rs .getString ("DIRECTIONALITY" ));
1075
+ timUpdateModel .setClosedPath (rs .getBoolean ("CLOSED_PATH" ));
1076
+ timUpdateModel .setPathId (rs .getInt ("PATH_ID" ));
1077
+ timUpdateModel .setRegionDescription (rs .getString ("REGION_DESCRIPTION" ));
1078
+
1079
+ // DataFrame properties
1080
+ timUpdateModel .setDataFrameId (rs .getInt ("DATA_FRAME_ID" ));
1081
+ timUpdateModel .setDurationTime (rs .getInt ("DURATION_TIME" ));
1082
+ timUpdateModel .setUrl (rs .getString ("URL" ));
1083
+ return timUpdateModel ;
1084
+ }
1137
1085
}
0 commit comments