Skip to content

Commit c1c7ea8

Browse files
committed
Add getSnapshotAsJson() for uncompressed JSON access to order book snapshots
Scripts can now export snapshots as JSON files instead of SQLite BLOBs.
1 parent 9c7f57f commit c1c7ea8

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

projectforge-business/src/main/kotlin/org/projectforge/business/fibu/orderbooksnapshots/OrderbookSnapshotScriptingService.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,14 @@ class OrderbookSnapshotScriptingService(private val __service: OrderbookSnapshot
7373
fun getSerializedOrderBook(date: LocalDate): ByteArray? {
7474
return __service.getSerializedOrderBook(date)
7575
}
76+
77+
/**
78+
* Returns the order book snapshot as uncompressed JSON string for a given date.
79+
*
80+
* @param date The date of the snapshot.
81+
* @return The JSON string containing all orders, or null if not found.
82+
*/
83+
fun getSnapshotAsJson(date: LocalDate): String? {
84+
return __service.getSnapshotAsJson(date)
85+
}
7686
}

projectforge-business/src/main/kotlin/org/projectforge/business/fibu/orderbooksnapshots/OrderbookSnapshotsService.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,18 @@ class OrderbookSnapshotsService {
290290
return findEntry(date)?.serializedOrderBook
291291
}
292292

293+
/**
294+
* Returns the order book snapshot as uncompressed JSON string for a given date.
295+
* @param date The date of the snapshot.
296+
* @return The JSON string, or null if not found or empty.
297+
*/
298+
fun getSnapshotAsJson(date: LocalDate): String? {
299+
val entry = findEntry(date) ?: return null
300+
val serialized = entry.serializedOrderBook ?: return null
301+
if (serialized.isEmpty()) return null
302+
return gunzip(serialized)
303+
}
304+
293305
private fun findEntry(date: LocalDate): OrderbookSnapshotDO? {
294306
return persistenceService.find(OrderbookSnapshotDO::class.java, date)
295307
}

0 commit comments

Comments
 (0)