From 43b98e1d3affe2c1c1ccc461ae90c34c034cbdf0 Mon Sep 17 00:00:00 2001 From: MarcWeberFS Date: Mon, 11 Nov 2024 16:51:35 +0100 Subject: [PATCH] feat: Enhance download link retrieval by using historic variable instance and update history level in configuration --- .../controller/VideoDownloadController.java | 19 +++++++++++++++---- .../src/main/resources/application.yaml | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/video-downloader-backend/src/main/java/ch/marc/controller/VideoDownloadController.java b/video-downloader-backend/src/main/java/ch/marc/controller/VideoDownloadController.java index cf24529..15a891f 100644 --- a/video-downloader-backend/src/main/java/ch/marc/controller/VideoDownloadController.java +++ b/video-downloader-backend/src/main/java/ch/marc/controller/VideoDownloadController.java @@ -1,6 +1,8 @@ package ch.marc.controller; +import org.camunda.bpm.engine.HistoryService; import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.history.HistoricVariableInstance; import org.camunda.bpm.engine.runtime.ProcessInstance; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -31,14 +33,23 @@ public ResponseEntity> startDownloadProcess(@RequestParam("u return ResponseEntity.ok(response); } + @Autowired + private HistoryService historyService; + @GetMapping("/download-link") public ResponseEntity> getDownloadLink(@RequestParam("processInstanceId") String processInstanceId) { - String downloadLink = (String) runtimeService.getVariable(processInstanceId, "downloadLink"); - - if (downloadLink != null) { + HistoricVariableInstance historicVariableInstance = historyService + .createHistoricVariableInstanceQuery() + .processInstanceId(processInstanceId) + .variableName("downloadLink") + .singleResult(); + + if (historicVariableInstance != null && historicVariableInstance.getValue() != null) { + String downloadLink = (String) historicVariableInstance.getValue(); return ResponseEntity.ok(Collections.singletonMap("downloadLink", downloadLink)); } else { - return ResponseEntity.status(HttpStatus.NO_CONTENT).body(Collections.singletonMap("message", "Download link is not ready yet.")); + return ResponseEntity.status(HttpStatus.NO_CONTENT).body(Collections.singletonMap("message", "Download link is not ready yet or process not found.")); } } + } diff --git a/video-downloader-backend/src/main/resources/application.yaml b/video-downloader-backend/src/main/resources/application.yaml index 78bcd0d..95eb084 100644 --- a/video-downloader-backend/src/main/resources/application.yaml +++ b/video-downloader-backend/src/main/resources/application.yaml @@ -6,6 +6,7 @@ camunda.bpm.admin-user: camunda: bpm: + history-level: full generic-properties: properties: historyTimeToLive: 5