From 73b3d7077bdb74232bfc25e4dd1f3f6ee2dd4e01 Mon Sep 17 00:00:00 2001 From: Paskal Paesler Date: Tue, 9 Jan 2024 17:34:44 +0100 Subject: [PATCH] Separate dlp input endpoints for result and job --- .../service/dlp/DlpInputRestController.kt | 44 +++++++++++-------- src/main/kotlin/io/hawk/service/dlp/DlpJob.kt | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/io/hawk/service/dlp/DlpInputRestController.kt b/src/main/kotlin/io/hawk/service/dlp/DlpInputRestController.kt index 93bcfa3..df1fc8e 100644 --- a/src/main/kotlin/io/hawk/service/dlp/DlpInputRestController.kt +++ b/src/main/kotlin/io/hawk/service/dlp/DlpInputRestController.kt @@ -2,14 +2,18 @@ package io.hawk.service.dlp import io.hawk.dlp.common.InspectResult import io.hawk.dlp.common.Job +import io.hawk.dlp.common.Result +import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +import java.util.* @RestController @RequestMapping("/api/dlp") class DlpInputRestController( - private val dlpJobRepository: DlpJobRepository + private val dlpJobRepository: DlpJobRepository, + private val dlpResultRepository: DlpResultRepository ) { @PostMapping fun input(job: Job) { @@ -18,25 +22,29 @@ class DlpInputRestController( created = job.created status = job.status error = job.error?.replace("\u0000", "") - results = job.results?.values?.mapNotNull { - if(it is InspectResult) { - InspectDlpResult().apply { - id = it.id - this.job = this@dlp - timestamp = it.timestamp + } + dlpJobRepository.save(dlpJob) + } + + @PostMapping("/{jobId}/result") + fun result(@PathVariable jobId: UUID, result: Result) { + val dlpJob = dlpJobRepository.findById(jobId).orElseThrow { error("Job does not exist") } + if(result is InspectResult) { + val dlpResult = InspectDlpResult().apply { + id = result.id + job = dlpJob + timestamp = result.timestamp + additional = result.additional + findings = result.findings.map { + DlpFinding().apply { + infoType = it.infoType + likelihood = it.likelihood + occurrences = it.occurrences additional = it.additional - findings = it.findings.map { - DlpFinding().apply { - infoType = it.infoType - likelihood = it.likelihood - occurrences = it.occurrences - additional = it.additional - } - } } - } else null - } ?: emptyList() + } + } + dlpResultRepository.save(dlpResult) } - dlpJobRepository.save(dlpJob) } } \ No newline at end of file diff --git a/src/main/kotlin/io/hawk/service/dlp/DlpJob.kt b/src/main/kotlin/io/hawk/service/dlp/DlpJob.kt index 222fd03..fc8e933 100644 --- a/src/main/kotlin/io/hawk/service/dlp/DlpJob.kt +++ b/src/main/kotlin/io/hawk/service/dlp/DlpJob.kt @@ -29,7 +29,7 @@ class DlpJob { @JvmSuppressWildcards @OneToMany(mappedBy = "job", cascade = [CascadeType.ALL]) @JsonSerialize(using = DlpResultOverviewSerializer::class) - lateinit var results: List + var results: MutableList = mutableListOf() class DlpResultOverviewSerializer : JsonSerializer>() { override fun serialize(result: List, generator: JsonGenerator, provider: SerializerProvider) {