Skip to content

Commit

Permalink
apply ktlintFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
sondrele committed Apr 19, 2023
1 parent 2f550dc commit 4b39c08
Show file tree
Hide file tree
Showing 167 changed files with 720 additions and 705 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package no.nav.mulighetsrommet.database
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import no.nav.mulighetsrommet.slack_notifier.SlackNotifier
import no.nav.mulighetsrommet.slack.SlackNotifier
import org.flywaydb.core.Flyway
import org.slf4j.LoggerFactory
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime

class FlywayDatabaseAdapter(
config: Config,
private val slackNotifier: SlackNotifier? = null
private val slackNotifier: SlackNotifier? = null,
) : DatabaseAdapter(config) {

data class Config(
Expand All @@ -23,12 +23,12 @@ class FlywayDatabaseAdapter(
override val password: Password,
override val maximumPoolSize: Int,
override val googleCloudSqlInstance: String? = null,
val migrationConfig: MigrationConfig = MigrationConfig()
val migrationConfig: MigrationConfig = MigrationConfig(),
) : DatabaseConfig

data class MigrationConfig(
val cleanDisabled: Boolean = true,
val strategy: InitializationStrategy = InitializationStrategy.Migrate
val strategy: InitializationStrategy = InitializationStrategy.Migrate,
)

enum class InitializationStrategy {
Expand All @@ -49,8 +49,8 @@ class FlywayDatabaseAdapter(
.configuration(
mapOf(
// Disable transactional locks in order to support concurrent indexes
"flyway.postgresql.transactional.lock" to "false"
)
"flyway.postgresql.transactional.lock" to "false",
),
)
.dataSource(config.jdbcUrl, config.user, config.password.value)
.apply {
Expand Down Expand Up @@ -94,9 +94,14 @@ class FlywayDatabaseAdapter(
val time = measureTime {
run()
}
logger.info("Flyway task finished in ${time}ms")
logger.info("Flyway task finished in $time")
} catch (e: Throwable) {
slackNotifier?.sendMessage("Async Flyway-migrering feilet. Sjekk med utviklerne på teamet om noen kjører en stor async migrering.")
slackNotifier?.sendMessage(
"""
Async Flyway-migrering feilet.
Sjekk med utviklerne på teamet om noen kjører en stor async migrering.
""".trimIndent(),
)
logger.warn("Flyway task was cancelled with exception", e)
throw e
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ enum class Avslutningsstatus {
AVLYST,
AVBRUTT,
AVSLUTTET,
IKKE_AVSLUTTET;
IKKE_AVSLUTTET,
;

companion object {
fun fromArenastatus(arenaStatus: String): Avslutningsstatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sealed class TiltakshistorikkDbo {
@Serializable(with = LocalDateTimeSerializer::class)
override val tilDato: LocalDateTime? = null,
@Serializable(with = UUIDSerializer::class)
val tiltaksgjennomforingId: UUID
val tiltaksgjennomforingId: UUID,
) : TiltakshistorikkDbo()

@Serializable
Expand All @@ -48,6 +48,6 @@ sealed class TiltakshistorikkDbo {
val beskrivelse: String,
@Serializable(with = UUIDSerializer::class)
val tiltakstypeId: UUID,
val virksomhetsnummer: String
val virksomhetsnummer: String,
) : TiltakshistorikkDbo()
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ data class TiltakstypeDbo(
val fraDato: LocalDate,
@Serializable(with = LocalDateSerializer::class)
val tilDato: LocalDate,
val rettPaaTiltakspenger: Boolean
val rettPaaTiltakspenger: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import kotlinx.serialization.Serializable

@Serializable
data class ArenaTiltaksgjennomforingsstatusDto(
val status: String
val status: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data class AvtaleAdminDto(
@Serializable
data class NavEnhet(
val enhetsnummer: String,
val navn: String? = null
val navn: String? = null,
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ enum class Avtalestatus {
Planlagt,
Aktiv,
Avsluttet,
Avbrutt;
Avbrutt,
;

companion object {
fun resolveFromDatesAndAvslutningsstatus(
now: LocalDate,
startDato: LocalDate,
sluttDato: LocalDate,
avslutningsstatus: Avslutningsstatus
avslutningsstatus: Avslutningsstatus,
): Avtalestatus = when {
avslutningsstatus == Avslutningsstatus.AVBRUTT -> Avbrutt
avslutningsstatus == Avslutningsstatus.AVSLUTTET -> Avsluttet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ import java.util.*
@Serializable
data class ExchangeArenaIdForIdResponse(
@Serializable(with = UUIDSerializer::class)
val id: UUID
val id: UUID,
)

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ data class TiltaksgjennomforingAdminDto(
@Serializable(with = UUIDSerializer::class)
val id: UUID,
val navn: String,
val arenaKode: String
val arenaKode: String,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ data class TiltaksgjennomforingDto(
@Serializable(with = LocalDateSerializer::class)
val sluttDato: LocalDate? = null,
val status: Tiltaksgjennomforingsstatus,
val virksomhetsnummer: String
val virksomhetsnummer: String,
) {
@Serializable
data class Tiltakstype(
@Serializable(with = UUIDSerializer::class)
val id: UUID,
val navn: String,
val arenaKode: String
val arenaKode: String,
)

companion object {
Expand All @@ -40,7 +40,7 @@ data class TiltaksgjennomforingDto(
startDato = tiltaksgjennomforing.startDato,
sluttDato = tiltaksgjennomforing.sluttDato,
status = tiltaksgjennomforing.status,
virksomhetsnummer = tiltaksgjennomforing.virksomhetsnummer
virksomhetsnummer = tiltaksgjennomforing.virksomhetsnummer,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class TiltaksgjennomforingsArenadataDto(
val lopenr: Int?,
val virksomhetsnummer: String?,
val ansvarligNavEnhetId: String,
val status: String
val status: String,
) {
companion object {
fun from(tiltaksgjennomforing: TiltaksgjennomforingAdminDto, status: String) = tiltaksgjennomforing.run {
Expand All @@ -17,7 +17,7 @@ data class TiltaksgjennomforingsArenadataDto(
lopenr = tiltaksnummer?.split("#")?.get(1)?.toInt(),
virksomhetsnummer = virksomhetsnummer,
ansvarligNavEnhetId = enhet,
status = status
status = status,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ enum class Tiltaksgjennomforingsstatus {
AVBRUTT,
AVLYST,
AVSLUTTET,
APENT_FOR_INNSOK;
APENT_FOR_INNSOK,
;

companion object {
fun fromDbo(
dagensDato: LocalDate,
startDato: LocalDate,
sluttDato: LocalDate?,
avslutningsStatus: Avslutningsstatus
avslutningsStatus: Avslutningsstatus,
): Tiltaksgjennomforingsstatus {
return when {
avslutningsStatus == Avslutningsstatus.AVLYST -> AVLYST
Expand All @@ -30,4 +31,3 @@ enum class Tiltaksgjennomforingsstatus {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class TiltakstypeDto(
@Serializable(with = LocalDateSerializer::class)
val tilDato: LocalDate,
val rettPaaTiltakspenger: Boolean,
val status: Tiltakstypestatus
val status: Tiltakstypestatus,
) {
companion object {
fun from(tiltakstype: TiltakstypeDbo) = tiltakstype.run {
Expand All @@ -37,10 +37,8 @@ data class TiltakstypeDto(
fraDato = fraDato,
tilDato = tilDato,
rettPaaTiltakspenger = rettPaaTiltakspenger,
status = Tiltakstypestatus.resolveFromDates(LocalDate.now(), fraDato, tilDato)
status = Tiltakstypestatus.resolveFromDates(LocalDate.now(), fraDato, tilDato),
)
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class KafkaConsumerRepository(private val db: Database) : KafkaConsumerRepositor
record.key,
record.value,
record.headersJson,
record.timestamp
record.timestamp,
).asUpdate
return db.run(queryResult).toLong()
}
Expand Down Expand Up @@ -101,7 +101,7 @@ class KafkaConsumerRepository(private val db: Database) : KafkaConsumerRepositor
row.stringOrNull("headers_json"),
row.int("retries"),
row.sqlTimestampOrNull("last_retry"),
row.long("record_timestamp")
row.long("record_timestamp"),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package no.nav.mulighetsrommet.kafka

import kotlinx.coroutines.runBlocking
import no.nav.common.kafka.consumer.util.KafkaConsumerClientBuilder
import no.nav.common.kafka.consumer.util.KafkaConsumerClientBuilder.TopicConfig
import org.apache.kafka.common.serialization.Deserializer
import java.util.function.Consumer

abstract class KafkaTopicConsumer<K, V>(
val config: Config,
private val keyDeserializer: Deserializer<K>,
private val valueDeserializer: Deserializer<V>
private val valueDeserializer: Deserializer<V>,
) {

data class Config(
Expand All @@ -17,8 +17,8 @@ abstract class KafkaTopicConsumer<K, V>(
val initialRunningState: Boolean = false,
)

internal fun toTopicConfig(kafkaConsumerRepository: KafkaConsumerRepository): KafkaConsumerClientBuilder.TopicConfig<K, V> {
return KafkaConsumerClientBuilder.TopicConfig<K, V>()
internal fun toTopicConfig(kafkaConsumerRepository: KafkaConsumerRepository): TopicConfig<K, V> {
return TopicConfig<K, V>()
.withLogging()
.withStoreOnFailure(kafkaConsumerRepository)
.withConsumerConfig(
Expand All @@ -29,7 +29,7 @@ abstract class KafkaTopicConsumer<K, V>(
runBlocking {
consume(event.key(), event.value())
}
}
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ data class Topic(
val id: String,
val topic: String,
val type: TopicType,
val running: Boolean
val running: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ class TopicRepository(private val db: Database) {
id = string("id"),
topic = string("topic"),
type = TopicType.valueOf(string("type")),
running = boolean("running")
running = boolean("running"),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import kotlin.time.Duration.Companion.seconds
class KafkaConsumerOrchestratorTest : FunSpec({
val kafka = install(
TestContainerExtension(
KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1"))
)
KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:6.2.1")),
),
) { withEmbeddedZookeeper() }

val database = extension(FlywayDatabaseTestListener(createDatabaseTestConfig()))
Expand Down Expand Up @@ -70,8 +70,8 @@ class KafkaConsumerOrchestratorTest : FunSpec({
id = "foo",
topic = "foo",
type = TopicType.CONSUMER,
running = true
)
running = true,
),
)
}

Expand All @@ -88,7 +88,7 @@ class KafkaConsumerOrchestratorTest : FunSpec({
orchestrator.getConsumers().first().isRunning shouldBe true

orchestrator.updateRunningTopics(
orchestrator.getTopics().map { it.copy(running = false) }
orchestrator.getTopics().map { it.copy(running = false) },
)

eventually(3.seconds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KafkaConsumerRepositoryTest : FunSpec({
"key$it".toByteArray(),
"value$it".toByteArray(),
"{}",
LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)
LocalDateTime.now().toEpochSecond(ZoneOffset.UTC),
)
}

Expand Down Expand Up @@ -67,8 +67,8 @@ class KafkaConsumerRepositoryTest : FunSpec({
"key1".toByteArray(),
"value1".toByteArray(),
"{}",
LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)
)
LocalDateTime.now().toEpochSecond(ZoneOffset.UTC),
),
)

val result = kafkaConsumerRepository.getTopicPartitions(mutableListOf("topic1"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import no.nav.common.kafka.consumer.util.deserializer.Deserializers.stringDeseri
import no.nav.mulighetsrommet.kafka.serialization.JsonElementDeserializer

class TestConsumer(name: String) : KafkaTopicConsumer<String?, String?>(
Config(name, name, true), stringDeserializer(), stringDeserializer()
Config(name, name, true),
stringDeserializer(),
stringDeserializer(),
) {
override suspend fun consume(key: String?, message: String?) {
if (message != "true") {
Expand All @@ -18,7 +20,9 @@ class TestConsumer(name: String) : KafkaTopicConsumer<String?, String?>(
}

class JsonTestConsumer(name: String) : KafkaTopicConsumer<String?, JsonElement>(
Config(name, name, true), stringDeserializer(), JsonElementDeserializer()
Config(name, name, true),
stringDeserializer(),
JsonElementDeserializer(),
) {
override suspend fun consume(key: String?, message: JsonElement) {
val success = message.jsonObject.getValue("success").jsonPrimitive.boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TopicRepositoryTest : FunSpec({

val updatedTopics = listOf(
topic0.copy(running = true),
Topic(id = "new-id", topic = "new-topic", type = TopicType.CONSUMER, running = false)
Topic(id = "new-id", topic = "new-topic", type = TopicType.CONSUMER, running = false),
)

repository.setAll(updatedTopics)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun httpJsonClient(engine: HttpClientEngine = CIO.create()) = HttpClient(engine)
json(
Json {
ignoreUnknownKeys = true
}
},
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.mulighetsrommet.audit_log
package no.nav.mulighetsrommet.auditlog

import no.nav.common.audit_log.log.AuditLoggerImpl

Expand Down
Loading

0 comments on commit 4b39c08

Please # to comment.