Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
alehuo committed Dec 16, 2024
1 parent f2795cb commit bfe3c91
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import fi.oph.koski.json.JsonSerializer
import fi.oph.koski.log.Logging
import fi.oph.koski.schema.LocalizedString
import fi.oph.koski.omaopintopolkuloki.AuditLogDynamoDB.AuditLogTableName
import fi.oph.scalaschema.Serializer.format
import org.json4s.{Extraction, JValue}
import org.json4s.jackson.JsonMethods.compact
import software.amazon.awssdk.services.dynamodb.DynamoDbClient
import software.amazon.awssdk.services.dynamodb.model.QueryResponse
import software.amazon.awssdk.services.dynamodb.model.{AttributeValue, QueryRequest}
Expand Down Expand Up @@ -48,10 +51,28 @@ class AuditLogService(app: KoskiApplication) extends Logging {
}
}
}
private def convertToAuditLogRow(item: QueryResponse): AuditlogRow = {
val auditLogRow = item.items().asScala.headOption.map(item => {
val organizationOid = item.asScala.view.collectFirst {
case ("organizationOid", value) if value.ss() != null => value.ss().asScala.toList
}.getOrElse(List.empty[String])

val raw = item.asScala.view.collectFirst {
case ("raw", value) if value.ss() != null => value.s()
}.getOrElse("")

val time = item.asScala.view.collectFirst {
case ("time", value) if value.s() != null => value.s()
}.getOrElse("")

AuditlogRow(organizationOid, raw, time)
})
auditLogRow.getOrElse(AuditlogRow(List(), "", ""))
}

private def buildLogs(queryResults: Seq[QueryResponse]): Iterable[Either[HttpStatus, OrganisaationAuditLogit]] = {
val timestampsGroupedByListOfOidsAndServiceName = queryResults.map(item => {
val parsedRow = JsonSerializer.parse[AuditlogRow](item.toString, ignoreExtras = true)
val parsedRow = convertToAuditLogRow(item)
val parsedRaw = JsonSerializer.parse[AuditlogRaw](parsedRow.raw, ignoreExtras = true)
val organisaatioOidit = parsedRow.organizationOid
val timestampString = parsedRow.time
Expand Down

0 comments on commit bfe3c91

Please sign in to comment.