Skip to content

Commit

Permalink
Start med exposed persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
alpet committed Sep 25, 2023
1 parent 9dace74 commit 38dc81f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
10 changes: 9 additions & 1 deletion cpa-repo/src/main/kotlin/no/nav/emottak/cpa/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.server.plugins.BadRequestException
import io.ktor.server.plugins.NotFoundException
import io.ktor.server.request.*
import io.ktor.server.response.respond
import io.ktor.server.routing.*
import io.ktor.server.routing.get
import io.ktor.server.routing.routing
import no.nav.emottak.cpa.config.DatabaseConfig
import no.nav.emottak.cpa.config.mapHikariConfig
import no.nav.emottak.melding.model.Header

fun main() {
val database = Database(mapHikariConfig(DatabaseConfig()))
Expand All @@ -24,6 +26,12 @@ fun main() {
call.respond(cpa)
}

post("cpa/validate") {
val validateRequest = call.receive(Header::class)
getCpa(validateRequest.cpaId)!!.validate(validateRequest)

}

get("/cpa/{id}/{herId}/certificate/encryption") {
val cpaId = call.parameters["id"] ?: throw BadRequestException("Mangler CPA ID")
val herId = call.parameters["herId"] ?: throw BadRequestException("Mangler HER ID")
Expand Down
11 changes: 11 additions & 0 deletions cpa-repo/src/main/kotlin/no/nav/emottak/cpa/CPAValidator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package no.nav.emottak.cpa

import no.nav.emottak.melding.model.Header
import org.oasis_open.committees.ebxml_cppa.schema.cpp_cpa_2_0.CollaborationProtocolAgreement


fun CollaborationProtocolAgreement.validate(header: Header) {

}

class ValidationException(reason: String) : Exception(reason)
44 changes: 44 additions & 0 deletions cpa-repo/src/main/kotlin/no/nav/emottak/cpa/persistence/CPA.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package no.nav.emottak.cpa.persistence

import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.ColumnType
import org.jetbrains.exposed.sql.Table
import org.oasis_open.committees.ebxml_cppa.schema.cpp_cpa_2_0.CollaborationProtocolAgreement

fun <T> readValue(value: String,clazz: Class<T>) : T? {
return null
}

fun writeValue(value: Any) : String = ""

class CPA : Table("cpa") {
val id: Column<String> = varchar("id",256)
val cpa = json("cpa", CollaborationProtocolAgreement::class.java)
}


private fun <T : Any> Table.json(
name: String,
clazz: Class<T>
): Column<T> =
registerColumn(
name = name,
type = JsonColumnType(clazz)
)


class JsonColumnType<T : Any>(private val clazz: Class<T>) : ColumnType() {
override fun sqlType(): String =
"jsonb"

override fun valueFromDB(value: Any): T = readValue(value as String, clazz)!!

override fun notNullValueToDB(value: Any): String = writeValue(value)

override fun valueToString(value: Any?): String =
when (value) {
is Iterable<*> -> notNullValueToDB(value)
else -> super.valueToString(value)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package no.nav.emottak.cpa.persistence

class CPARepository {


}
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencyResolutionManagement {
library("exposed-dao", "org.jetbrains.exposed", "exposed-dao").versionRef("exposed")
library("exposed-java-time", "org.jetbrains.exposed", "exposed-java-time").versionRef("exposed")
library("exposed-jdbc", "org.jetbrains.exposed", "exposed-jdbc").versionRef("exposed")
library("exposed-json","org.jetbrains.exposed","exposed-json").versionRef("exposed")

library("ktor-server-core", "io.ktor", "ktor-server-core").versionRef("ktor")
library("ktor-server-netty", "io.ktor", "ktor-server-netty").versionRef("ktor")
Expand All @@ -40,7 +41,7 @@ dependencyResolutionManagement {
library("jaxb-runtime", "org.glassfish.jaxb:jaxb-runtime:2.4.0-b180830.0438")

bundle("bouncycastle", listOf("bcpkix-jdk18on", "bcprov-jdk18on"))
bundle("exposed", listOf("exposed-core", "exposed-dao", "exposed-java-time", "exposed-jdbc"))
bundle("exposed", listOf("exposed-core", "exposed-dao", "exposed-java-time", "exposed-jdbc","exposed-json"))
}

create("testLibs") {
Expand Down

0 comments on commit 38dc81f

Please sign in to comment.