Skip to content

Commit

Permalink
ktfmt formateringsregler i editorconfig, uten trailing commas. No plu…
Browse files Browse the repository at this point in the history
…gin needed
  • Loading branch information
lalimpan committed Nov 27, 2024
1 parent b3f115b commit e82ca3e
Show file tree
Hide file tree
Showing 705 changed files with 47,226 additions and 14,400 deletions.
95 changes: 95 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# This .editorconfig section approximates ktfmt's formatting rules. You can include it in an
# existing .editorconfig file or use it standalone by copying it to <project root>/.editorconfig
# and making sure your editor is set to read settings from .editorconfig files.
#
# It includes editor-specific config options for IntelliJ IDEA.
#
# If any option is wrong, PR are welcome

[{*.kt,*.kts}]
indent_style = space
insert_final_newline = true
max_line_length = 100
indent_size = 4
ij_continuation_indent_size = 4
ij_java_names_count_to_use_import_on_demand = 9999
ij_kotlin_align_in_columns_case_branch = false
ij_kotlin_align_multiline_binary_operation = false
ij_kotlin_align_multiline_extends_list = false
ij_kotlin_align_multiline_method_parentheses = false
ij_kotlin_align_multiline_parameters = true
ij_kotlin_align_multiline_parameters_in_calls = false
ij_kotlin_allow_trailing_comma = false
ij_kotlin_allow_trailing_comma_on_call_site = false
ij_kotlin_assignment_wrap = normal
ij_kotlin_blank_lines_after_class_header = 0
ij_kotlin_blank_lines_around_block_when_branches = 0
ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
ij_kotlin_block_comment_at_first_column = true
ij_kotlin_call_parameters_new_line_after_left_paren = true
ij_kotlin_call_parameters_right_paren_on_new_line = false
ij_kotlin_call_parameters_wrap = on_every_item
ij_kotlin_catch_on_new_line = false
ij_kotlin_class_annotation_wrap = split_into_lines
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_kotlin_continuation_indent_for_chained_calls = true
ij_kotlin_continuation_indent_for_expression_bodies = true
ij_kotlin_continuation_indent_in_argument_lists = true
ij_kotlin_continuation_indent_in_elvis = false
ij_kotlin_continuation_indent_in_if_conditions = false
ij_kotlin_continuation_indent_in_parameter_lists = false
ij_kotlin_continuation_indent_in_supertype_lists = false
ij_kotlin_else_on_new_line = false
ij_kotlin_enum_constants_wrap = off
ij_kotlin_extends_list_wrap = normal
ij_kotlin_field_annotation_wrap = off
ij_kotlin_finally_on_new_line = false
ij_kotlin_if_rparen_on_new_line = false
ij_kotlin_import_nested_classes = false
ij_kotlin_imports_layout = *
ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
ij_kotlin_keep_blank_lines_before_right_brace = 2
ij_kotlin_keep_blank_lines_in_code = 2
ij_kotlin_keep_blank_lines_in_declarations = 2
ij_kotlin_keep_first_column_comment = true
ij_kotlin_keep_indents_on_empty_lines = false
ij_kotlin_keep_line_breaks = true
ij_kotlin_lbrace_on_next_line = false
ij_kotlin_line_comment_add_space = false
ij_kotlin_line_comment_at_first_column = true
ij_kotlin_method_annotation_wrap = split_into_lines
ij_kotlin_method_call_chain_wrap = normal
ij_kotlin_method_parameters_new_line_after_left_paren = true
ij_kotlin_method_parameters_right_paren_on_new_line = true
ij_kotlin_method_parameters_wrap = on_every_item
ij_kotlin_name_count_to_use_star_import = 9999
ij_kotlin_name_count_to_use_star_import_for_members = 9999
ij_kotlin_parameter_annotation_wrap = off
ij_kotlin_space_after_comma = true
ij_kotlin_space_after_extend_colon = true
ij_kotlin_space_after_type_colon = true
ij_kotlin_space_before_catch_parentheses = true
ij_kotlin_space_before_comma = false
ij_kotlin_space_before_extend_colon = true
ij_kotlin_space_before_for_parentheses = true
ij_kotlin_space_before_if_parentheses = true
ij_kotlin_space_before_lambda_arrow = true
ij_kotlin_space_before_type_colon = false
ij_kotlin_space_before_when_parentheses = true
ij_kotlin_space_before_while_parentheses = true
ij_kotlin_spaces_around_additive_operators = true
ij_kotlin_spaces_around_assignment_operators = true
ij_kotlin_spaces_around_equality_operators = true
ij_kotlin_spaces_around_function_type_arrow = true
ij_kotlin_spaces_around_logical_operators = true
ij_kotlin_spaces_around_multiplicative_operators = true
ij_kotlin_spaces_around_range = false
ij_kotlin_spaces_around_relational_operators = true
ij_kotlin_spaces_around_unary_operator = false
ij_kotlin_spaces_around_when_arrow = true
ij_kotlin_variable_annotation_wrap = off
ij_kotlin_while_on_new_line = false
ij_kotlin_wrap_elvis_expressions = 1
ij_kotlin_wrap_expression_body_functions = 1
ij_kotlin_wrap_first_method_in_call_chain = false

2 changes: 1 addition & 1 deletion doc/fimkt/flereIM_kortTid.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@

Vi ønsker altså at de tilfellene der begge/alle IM _ikke_ har satt arbeidsforholdID, så skal vi _ikke_ sette varsler og dermed automatisere. Dette forutsetter at vi bruker dager fra IM 2 / den sist mottatte inntektsmeldingen.

Rel. venting: vi vil _i alle tilfeller_ vente i 30 minutter før vi sender IM fra spedisjon til spleis.
Rel. venting: vi vil _i alle tilfeller_ vente i 30 minutter før vi sender IM fra spedisjon til spleis.
2 changes: 1 addition & 1 deletion doc/tilstandsmaskin/eksperimenterITilstandsdiagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ stateDiagram-v2
```
```
7 changes: 4 additions & 3 deletions jobs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ tasks {

manifest {
attributes["Main-Class"] = mainClass
attributes["Class-Path"] = configurations.runtimeClasspath.get().joinToString(separator = " ") {
it.name
}
attributes["Class-Path"] =
configurations.runtimeClasspath.get().joinToString(separator = " ") {
it.name
}
}
}
}
64 changes: 46 additions & 18 deletions jobs/src/main/kotlin/no/nav/helse/spleis/jobs/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import java.time.Duration
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.UUID
import kotlin.system.measureTimeMillis
import kotlin.time.DurationUnit
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotliquery.Session
Expand All @@ -21,10 +25,6 @@ import no.nav.helse.serde.tilSerialisertPerson
import org.apache.kafka.clients.producer.ProducerRecord
import org.intellij.lang.annotations.Language
import org.slf4j.LoggerFactory
import kotlin.system.measureTimeMillis
import kotlin.time.DurationUnit
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime

val log = LoggerFactory.getLogger("no.nav.helse.spleis.gc.App")
val sikkerlogg = LoggerFactory.getLogger("tjenestekall")
Expand All @@ -39,7 +39,8 @@ fun main(cliArgs: Array<String>) {
)
}

val args = cliArgs.takeIf(Array<*>::isNotEmpty)?.toList() ?: System.getenv("RUNTIME_OPTS").split(" ")
val args =
cliArgs.takeIf(Array<*>::isNotEmpty)?.toList() ?: System.getenv("RUNTIME_OPTS").split(" ")
if (args.isEmpty()) return log.error("Provide a task name as CLI argument")

val factory by lazy { ConsumerProducerFactory(AivenConfig.default) }
Expand Down Expand Up @@ -87,11 +88,18 @@ private fun migrateV2Task(arbeidId: String) {
val dto = SerialisertPerson(data).tilPersonDto()
val gjenopprettetPerson = Person.gjenopprett(EmptyLog, dto)
val resultat = gjenopprettetPerson.dto().tilPersonData().tilSerialisertPerson()
check(1 == txSession.run(queryOf("UPDATE person SET skjema_versjon=:skjemaversjon, data=:data WHERE fnr=:ident", mapOf(
"skjemaversjon" to resultat.skjemaVersjon,
"data" to resultat.json,
"ident" to fnr
)).asUpdate))
check(
1 == txSession.run(
queryOf(
"UPDATE person SET skjema_versjon=:skjemaversjon, data=:data WHERE fnr=:ident",
mapOf(
"skjemaversjon" to resultat.skjemaVersjon,
"data" to resultat.json,
"ident" to fnr
)
).asUpdate
)
)
}
log.info("[$migreringCounter] Utført på $time ms")
}
Expand All @@ -116,26 +124,36 @@ private fun fyllArbeidstabell(session: Session, arbeidId: String) {
"""
session.run(queryOf(query, arbeidId).asExecute)
}

private fun hentArbeid(session: Session, arbeidId: String, size: Int = 500): List<Long> {
@Language("PostgreSQL")
val query = """
select fnr from arbeidstabell where arbeid_startet IS NULL and arbeid_id = ? limit $size for update skip locked;
"""

@Language("PostgreSQL")
val oppdater = "update arbeidstabell set arbeid_startet=now() where arbeid_id=? and fnr IN(%s)"
return session.transaction { txSession ->
txSession.run(queryOf(query, arbeidId).map { it.long("fnr") }.asList).also { personer ->
if (personer.isNotEmpty()) {
txSession.run(queryOf(String.format(oppdater, personer.joinToString { "?" }), arbeidId, *personer.toTypedArray()).asUpdate)
txSession.run(
queryOf(
String.format(oppdater, personer.joinToString { "?" }),
arbeidId,
*personer.toTypedArray()
).asUpdate
)
}
}
}
}

private fun arbeidFullført(session: Session, arbeidId: String, fnr: Long) {
@Language("PostgreSQL")
val query = "update arbeidstabell set arbeid_ferdig=now() where arbeid_id=? and fnr=?"
session.run(queryOf(query, arbeidId, fnr).asUpdate)
}

private fun arbeidFinnes(session: Session, arbeidId: String): Boolean {
@Language("PostgreSQL")
val query = "SELECT COUNT(1) as antall FROM arbeidstabell where arbeid_id=?"
Expand All @@ -156,7 +174,11 @@ private fun klargjørEllerVentPåTilgjengeligArbeid(session: Session, arbeidId:
}
}

fun opprettOgUtførArbeid(arbeidId: String, size: Int = 1, arbeider: (session: Session, fnr: Long) -> Unit) {
fun opprettOgUtførArbeid(
arbeidId: String,
size: Int = 1,
arbeider: (session: Session, fnr: Long) -> Unit
) {
DataSourceConfiguration(DbUser.MIGRATE).dataSource(maximumPoolSize = 1).use { ds ->
sessionOf(ds).use { session ->
klargjørEllerVentPåTilgjengeligArbeid(session, arbeidId)
Expand Down Expand Up @@ -273,12 +295,18 @@ private fun lagAvstemming(fnr: String) = """
private class DataSourceConfiguration(dbUsername: DbUser) {
private val env = System.getenv()

private val gcpProjectId = requireNotNull(env["GCP_TEAM_PROJECT_ID"]) { "gcp project id must be set" }
private val databaseRegion = requireNotNull(env["DATABASE_REGION"]) { "database region must be set" }
private val databaseInstance = requireNotNull(env["DATABASE_INSTANCE"]) { "database instance must be set" }
private val databaseUsername = requireNotNull(env["${dbUsername}_USERNAME"]) { "database username must be set" }
private val databasePassword = requireNotNull(env["${dbUsername}_PASSWORD"]) { "database password must be set"}
private val databaseName = requireNotNull(env["${dbUsername}_DATABASE"]) { "database name must be set"}
private val gcpProjectId =
requireNotNull(env["GCP_TEAM_PROJECT_ID"]) { "gcp project id must be set" }
private val databaseRegion =
requireNotNull(env["DATABASE_REGION"]) { "database region must be set" }
private val databaseInstance =
requireNotNull(env["DATABASE_INSTANCE"]) { "database instance must be set" }
private val databaseUsername =
requireNotNull(env["${dbUsername}_USERNAME"]) { "database username must be set" }
private val databasePassword =
requireNotNull(env["${dbUsername}_PASSWORD"]) { "database password must be set" }
private val databaseName =
requireNotNull(env["${dbUsername}_DATABASE"]) { "database name must be set" }

private val hikariConfig = HikariConfig().apply {
jdbcUrl = String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,33 @@ private fun finnGrunnbeløp(person: PersonInnDto): List<Grunnbeløp> {
val historikk = person.vilkårsgrunnlagHistorikk.historikk
if (historikk.isEmpty()) return emptyList()
val siste = historikk.first()
return siste.vilkårsgrunnlag.filterNot { it.inntektsgrunnlag.vurdertInfotrygd }.map {
spleisVilkårsgrunnlag -> Grunnbeløp(
skjæringstidspunkt = spleisVilkårsgrunnlag.skjæringstidspunkt,
`6G` = spleisVilkårsgrunnlag.inntektsgrunnlag.`6G`.beløp
)
}
return siste.vilkårsgrunnlag.filterNot { it.inntektsgrunnlag.vurdertInfotrygd }
.map { spleisVilkårsgrunnlag ->
Grunnbeløp(
skjæringstidspunkt = spleisVilkårsgrunnlag.skjæringstidspunkt,
`6G` = spleisVilkårsgrunnlag.inntektsgrunnlag.`6G`.beløp
)
}
}


private fun fødselsnummerSomString(fnr: Long) = fnr.toString().let { if (it.length == 11) it else "0$it" }
private fun fødselsnummerSomString(fnr: Long) =
fnr.toString().let { if (it.length == 11) it else "0$it" }

private data class GrunnbeløpEvent(
valdselsnummer: String,
val grunnbeløp: List<Grunnbeløp>
) {
@JsonProperty("@event_name")
val eventName: String = "grunnbeløp"

@JsonProperty("@id")
val id: UUID = UUID.randomUUID()

@JsonProperty("@opprettet")
val opprettet: LocalDateTime = LocalDateTime.now()
}

private data class Grunnbeløp(
val skjæringstidspunkt: LocalDate,
val `6G`: Double
Expand Down
Loading

0 comments on commit e82ca3e

Please sign in to comment.