refactor: restrict default raw history protocols
This commit is contained in:
@@ -29,6 +29,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@RestController
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.event-history", name = "enabled", havingValue = "true")
|
||||
@@ -41,6 +42,10 @@ public final class RawFrameHistoryController {
|
||||
private static final TypeReference<Map<String, Object>> MAP_TYPE = new TypeReference<>() {};
|
||||
private static final int LOCATION_ENRICH_LIMIT = 1;
|
||||
private static final int TELEMETRY_ENRICH_LIMIT = 500;
|
||||
private static final Set<String> DEFAULT_PRODUCTION_PROTOCOLS = Set.of(
|
||||
"GB32960",
|
||||
"JT808",
|
||||
"MQTT_YUTONG");
|
||||
|
||||
private final TdengineHistoryReader reader;
|
||||
|
||||
@@ -88,9 +93,14 @@ public final class RawFrameHistoryController {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
|
||||
"vehicleKey, vin, phone, messageId or parseStatus is required for raw frame query");
|
||||
}
|
||||
String normalizedProtocol = normalize(protocol).toUpperCase(Locale.ROOT);
|
||||
if (!DEFAULT_PRODUCTION_PROTOCOLS.contains(normalizedProtocol)) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
|
||||
"protocol must be one of GB32960, JT808, MQTT_YUTONG");
|
||||
}
|
||||
QueryTimeRange range = QueryTimeRange.parse(dateFrom, dateTo);
|
||||
TdenginePage<TdengineRawFrameRow> page = reader.queryRawFrames(new TdengineRawFrameQuery(
|
||||
normalize(protocol).toUpperCase(Locale.ROOT),
|
||||
normalizedProtocol,
|
||||
normalize(vehicleKey),
|
||||
normalize(vin),
|
||||
normalize(phone),
|
||||
|
||||
@@ -34,7 +34,7 @@ class RawFrameHistoryControllerTest {
|
||||
RawFrameHistoryController controller = new RawFrameHistoryController(reader);
|
||||
|
||||
RawFrameHistoryController.RawFramePageResponse response = controller.rawFrames(
|
||||
"xinda_push",
|
||||
"mqtt_yutong",
|
||||
null,
|
||||
"LB9A32A24P0LS1270",
|
||||
null,
|
||||
@@ -48,7 +48,7 @@ class RawFrameHistoryControllerTest {
|
||||
"2026-06-29T12:00:00Z",
|
||||
"frame-0");
|
||||
|
||||
assertThat(reader.query.protocol()).isEqualTo("XINDA_PUSH");
|
||||
assertThat(reader.query.protocol()).isEqualTo("MQTT_YUTONG");
|
||||
assertThat(reader.query.vin()).isEqualTo("LB9A32A24P0LS1270");
|
||||
assertThat(reader.query.messageId()).isEqualTo(0x0200);
|
||||
assertThat(reader.query.parseStatus()).isEqualTo("NOT_PARSED");
|
||||
@@ -58,7 +58,7 @@ class RawFrameHistoryControllerTest {
|
||||
RawFrameHistoryController.RawFrameResponse item = response.items().getFirst();
|
||||
assertThat(item.messageId()).isEqualTo(0x0200);
|
||||
assertThat(item.messageIdHex()).isEqualTo("0x0200");
|
||||
assertThat(item.rawUri()).contains("XINDA_PUSH");
|
||||
assertThat(item.rawUri()).contains("MQTT_YUTONG");
|
||||
assertThat(item.metadataJson()).contains("rawArchiveUri");
|
||||
assertThat(item.metadata())
|
||||
.containsEntry("rawArchiveUri", item.rawUri())
|
||||
@@ -212,6 +212,29 @@ class RawFrameHistoryControllerTest {
|
||||
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsLegacyXindaProtocolOnDefaultRawFrameApi() {
|
||||
RawFrameHistoryController controller = new RawFrameHistoryController(
|
||||
new CapturingReader(new TdenginePage<>(List.of(), Optional.empty())));
|
||||
|
||||
assertThatThrownBy(() -> controller.rawFrames(
|
||||
"XINDA_PUSH",
|
||||
null,
|
||||
"LB9A32A24P0LS1270",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"2026-06-29",
|
||||
"2026-06-30",
|
||||
TdengineQueryOrder.DESC,
|
||||
20,
|
||||
false,
|
||||
null,
|
||||
null))
|
||||
.isInstanceOfSatisfying(ResponseStatusException.class, ex ->
|
||||
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST));
|
||||
}
|
||||
|
||||
private static TdengineRawFrameRow row(String frameId, String ts) {
|
||||
Instant instant = Instant.parse(ts);
|
||||
return new TdengineRawFrameRow(
|
||||
@@ -221,16 +244,16 @@ class RawFrameHistoryControllerTest {
|
||||
0x0200,
|
||||
0,
|
||||
instant,
|
||||
"archive://2026/06/29/XINDA_PUSH/unknown/" + frameId + ".bin",
|
||||
"archive://2026/06/29/MQTT_YUTONG/VEHICLE-MQTT-1/" + frameId + ".bin",
|
||||
"sha256:" + frameId,
|
||||
72,
|
||||
"NOT_PARSED",
|
||||
"",
|
||||
"xinda",
|
||||
"{\"rawArchiveUri\":\"archive://2026/06/29/XINDA_PUSH/unknown/" + frameId
|
||||
"mqtt-yutong",
|
||||
"{\"rawArchiveUri\":\"archive://2026/06/29/MQTT_YUTONG/VEHICLE-MQTT-1/" + frameId
|
||||
+ ".bin\",\"plateNo\":\"粤BD12345\",\"rawJson\":\"{\\\"carName\\\":\\\"粤BD12345\\\"}\"}",
|
||||
"",
|
||||
"XINDA_PUSH",
|
||||
"MQTT_YUTONG",
|
||||
"LB9A32A24P0LS1270",
|
||||
"LB9A32A24P0LS1270",
|
||||
"");
|
||||
|
||||
Reference in New Issue
Block a user