Skip to content

Commit

Permalink
feat: Enhance download link retrieval by using historic variable inst…
Browse files Browse the repository at this point in the history
…ance and update history level in configuration
  • Loading branch information
MarcWeberFS committed Nov 11, 2024
1 parent 5a5d462 commit 43b98e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,14 +33,23 @@ public ResponseEntity<Map<String, String>> startDownloadProcess(@RequestParam("u
return ResponseEntity.ok(response);
}

@Autowired
private HistoryService historyService;

@GetMapping("/download-link")
public ResponseEntity<Map<String, String>> 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."));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ camunda.bpm.admin-user:

camunda:
bpm:
history-level: full
generic-properties:
properties:
historyTimeToLive: 5
Expand Down

0 comments on commit 43b98e1

Please sign in to comment.