-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimelineController.java
More file actions
91 lines (81 loc) · 3.15 KB
/
TimelineController.java
File metadata and controls
91 lines (81 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.tracepcap.analysis.controller;
import com.tracepcap.analysis.dto.TimelineDataDto;
import com.tracepcap.analysis.service.TimelineService;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/** REST controller for timeline/traffic analysis operations */
@Slf4j
@RestController
@RequestMapping("/api/timeline")
@RequiredArgsConstructor
public class TimelineController {
private final TimelineService timelineService;
/**
* Get timeline data for a file with binned traffic statistics
*
* @param fileId The file ID
* @param interval The time interval in seconds for binning (default: 60)
* @param maxDataPoints Maximum number of data points to return (optional, uses config default if
* not provided)
* @return List of timeline data points
*/
@GetMapping("/{fileId}")
public ResponseEntity<List<TimelineDataDto>> getTimeline(
@PathVariable UUID fileId,
@RequestParam(defaultValue = "60") Integer interval,
@RequestParam(required = false) Integer maxDataPoints) {
log.info(
"GET /api/timeline/{} with interval {}s and maxDataPoints {}",
fileId,
interval,
maxDataPoints);
// Validate maxDataPoints if provided
if (maxDataPoints != null && (maxDataPoints < 10 || maxDataPoints > 10000)) {
throw new IllegalArgumentException("maxDataPoints must be between 10 and 10000");
}
List<TimelineDataDto> timeline =
timelineService.getTimelineData(fileId, interval, maxDataPoints);
return ResponseEntity.ok(timeline);
}
/**
* Get timeline data for a specific time range
*
* @param fileId The file ID
* @param start Start timestamp (ISO 8601 format)
* @param end End timestamp (ISO 8601 format)
* @param interval The time interval in seconds for binning (default: 60)
* @param maxDataPoints Maximum number of data points to return (optional, uses config default if
* not provided)
* @return List of timeline data points
*/
@GetMapping("/{fileId}/range")
public ResponseEntity<List<TimelineDataDto>> getTimelineRange(
@PathVariable UUID fileId,
@RequestParam String start,
@RequestParam String end,
@RequestParam(defaultValue = "60") Integer interval,
@RequestParam(required = false) Integer maxDataPoints) {
log.info(
"GET /api/timeline/{}/range from {} to {} with interval {}s and maxDataPoints {}",
fileId,
start,
end,
interval,
maxDataPoints);
// Validate maxDataPoints if provided
if (maxDataPoints != null && (maxDataPoints < 10 || maxDataPoints > 10000)) {
throw new IllegalArgumentException("maxDataPoints must be between 10 and 10000");
}
LocalDateTime startTime = LocalDateTime.parse(start);
LocalDateTime endTime = LocalDateTime.parse(end);
List<TimelineDataDto> timeline =
timelineService.getTimelineDataForRange(
fileId, startTime, endTime, interval, maxDataPoints);
return ResponseEntity.ok(timeline);
}
}