Skip to content

Commit

Permalink
Separate dlp input endpoints for result and job
Browse files Browse the repository at this point in the history
  • Loading branch information
p4skal committed Jan 9, 2024
1 parent 877479b commit 73b3d70
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
44 changes: 26 additions & 18 deletions src/main/kotlin/io/hawk/service/dlp/DlpInputRestController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/io/hawk/service/dlp/DlpJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DlpJob {
@JvmSuppressWildcards
@OneToMany(mappedBy = "job", cascade = [CascadeType.ALL])
@JsonSerialize(using = DlpResultOverviewSerializer::class)
lateinit var results: List<DlpResult>
var results: MutableList<DlpResult> = mutableListOf()

class DlpResultOverviewSerializer : JsonSerializer<List<DlpResult>>() {
override fun serialize(result: List<DlpResult>, generator: JsonGenerator, provider: SerializerProvider) {
Expand Down

0 comments on commit 73b3d70

Please sign in to comment.