-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
da kan spleis bruke den i testene sine og bekrefte at ting funker fint
- Loading branch information
1 parent
195feb5
commit 2653c70
Showing
14 changed files
with
247 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: build & publish fabrikk | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'fabrikk/**' | ||
- 'build.gradle.kts' | ||
- 'settings.gradle.kts' | ||
- '.github/workflows/fabrikk.yml' | ||
|
||
env: | ||
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
jobs: | ||
build: | ||
name: build | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '21.x' | ||
cache: 'gradle' | ||
- name: gradle | ||
run: ./gradlew :fabrikk:build | ||
- name: Genererer versjon | ||
run: | | ||
TIME=$(TZ="Europe/Oslo" date +%Y.%m.%d-%H.%M) | ||
COMMIT=$(git rev-parse --short=8 HEAD) | ||
VERSION=$TIME-$COMMIT | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
- name: upload artifacts | ||
run: ./gradlew :fabrikk:publish -Pversion="$(echo $VERSION)" | ||
env: | ||
GITHUB_USERNAME: x-access-token | ||
GITHUB_PASSWORD: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
plugins { | ||
`maven-publish` | ||
} | ||
|
||
configure<JavaPluginExtension> { | ||
withSourcesJar() | ||
} | ||
|
||
configure<PublishingExtension> { | ||
publications { | ||
create<MavenPublication>("maven") { | ||
from(components["java"]) | ||
groupId = "com.github.navikt.spekemat" | ||
artifactId = project.name | ||
version = "${project.version}" | ||
} | ||
} | ||
repositories { | ||
maven { | ||
url = uri("https://maven.pkg.github.com/navikt/spekemat") | ||
credentials { | ||
username = "x-access-token" | ||
password = System.getenv("GITHUB_PASSWORD") | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
fabrikk/src/main/kotlin/no/nav/helse/spekemat/fabrikk/Pølse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package no.nav.helse.spekemat.fabrikk | ||
|
||
import java.util.* | ||
|
||
data class Pølse( | ||
val vedtaksperiodeId: UUID, | ||
val generasjonId: UUID, | ||
// hvorvidt generasjonen er åpen for endringer (dvs. til behandling) eller ikke (vedtak fattet / generasjon avsluttet) | ||
val status: Pølsestatus, | ||
// tingen som gjorde at generasjonen ble opprettet | ||
val kilde: UUID | ||
) { | ||
fun erNyPølseAv(other: Pølse): Boolean { | ||
// må være samme vedtaksperiode | ||
return this.vedtaksperiodeId == other.vedtaksperiodeId | ||
} | ||
fun dto() = PølseDto( | ||
vedtaksperiodeId = vedtaksperiodeId, | ||
generasjonId = generasjonId, | ||
status = status, | ||
kilde = kilde | ||
) | ||
|
||
fun oppdaterPølse(vedtaksperiodeId: UUID, generasjonId: UUID, status: Pølsestatus): Pølse { | ||
if (this.vedtaksperiodeId != vedtaksperiodeId) return this | ||
check(this.generasjonId == generasjonId) { | ||
"Det er gjort forsøk på å oppdatere en generasjon som ikke samsvarer med den som er registrert i nyeste rad" | ||
} | ||
return this.copy(status = status) | ||
} | ||
|
||
companion object { | ||
fun fraDto(dto: PølseDto) = Pølse( | ||
vedtaksperiodeId = dto.vedtaksperiodeId, | ||
generasjonId = dto.generasjonId, | ||
status = dto.status, | ||
kilde = dto.kilde | ||
) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
fabrikk/src/main/kotlin/no/nav/helse/spekemat/fabrikk/PølseDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package no.nav.helse.spekemat.fabrikk | ||
|
||
import java.util.* | ||
|
||
data class PølseDto( | ||
val vedtaksperiodeId: UUID, | ||
val generasjonId: UUID, | ||
val status: Pølsestatus, | ||
// tingen som gjorde at generasjonen ble opprettet | ||
val kilde: UUID | ||
) |
45 changes: 45 additions & 0 deletions
45
fabrikk/src/main/kotlin/no/nav/helse/spekemat/fabrikk/Pølsefabrikk.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package no.nav.helse.spekemat.fabrikk | ||
|
||
import java.util.* | ||
|
||
class Pølsefabrikk private constructor( | ||
private val pakken: MutableList<Pølserad> | ||
) { | ||
constructor() : this(mutableListOf()) | ||
|
||
companion object { | ||
fun gjenopprett(rader: List<PølseradDto>) = | ||
Pølsefabrikk(rader.map { Pølserad.fraDto(it) }.toMutableList()) | ||
} | ||
|
||
fun nyPølse(pølse: Pølse) { | ||
if (håndtertFør(pølse)) return | ||
if (skalLageNyrad(pølse)) return lagNyRad(pølse) | ||
pakken[0] = pakken[0].nyPølse(pølse) | ||
} | ||
|
||
private fun håndtertFør(pølse: Pølse) = | ||
pakken.any { rad -> | ||
rad.pølser.any { it.generasjonId == pølse.generasjonId } | ||
} | ||
|
||
fun oppdaterPølse(vedtaksperiodeId: UUID, generasjonId: UUID, status: Pølsestatus): PølseDto { | ||
pakken[0] = pakken[0].oppdaterPølse(vedtaksperiodeId, generasjonId, status) | ||
return pakken[0].pølser.single { it.vedtaksperiodeId == vedtaksperiodeId }.dto() | ||
} | ||
|
||
private fun skalLageNyrad(pølse: Pølse) = | ||
pakken.isEmpty() || pakken[0].skalLageNyRad(pølse) | ||
|
||
private fun lagNyRad(pølse: Pølse) { | ||
if (pakken.isEmpty()) { | ||
pakken.add(Pølserad(listOf(pølse), pølse.kilde)) | ||
return | ||
} | ||
|
||
val pølserad = pakken[0].nyPølserad(pølse) | ||
pakken[0] = pakken[0].fjernPølserTilBehandling() | ||
pakken.add(0, pølserad) | ||
} | ||
fun pakke() = pakken.map { it.dto() } | ||
} |
41 changes: 41 additions & 0 deletions
41
fabrikk/src/main/kotlin/no/nav/helse/spekemat/fabrikk/Pølserad.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package no.nav.helse.spekemat.fabrikk | ||
|
||
import java.util.* | ||
|
||
data class Pølserad( | ||
val pølser: List<Pølse>, | ||
val kildeTilRad: UUID | ||
) { | ||
fun skalLageNyRad(other: Pølse) = | ||
pølser.any { pølse -> other.erNyPølseAv(pølse) && this.kildeTilRad != other.kilde } | ||
|
||
fun fjernPølserTilBehandling() = | ||
this.copy(pølser = pølser.filterNot { it.status == Pølsestatus.ÅPEN }) | ||
|
||
fun nyPølserad(pølse: Pølse): Pølserad { | ||
return this | ||
.nyPølse(pølse) | ||
.copy(kildeTilRad = pølse.kilde) | ||
} | ||
fun nyPølse(pølse: Pølse): Pølserad { | ||
return this.copy( | ||
pølser = pølser | ||
.filterNot { it.vedtaksperiodeId == pølse.vedtaksperiodeId } | ||
.plusElement(pølse) | ||
) | ||
} | ||
|
||
fun oppdaterPølse(vedtaksperiodeId: UUID, generasjonId: UUID, status: Pølsestatus): Pølserad { | ||
return this.copy( | ||
pølser = pølser.map { it.oppdaterPølse(vedtaksperiodeId, generasjonId, status) } | ||
) | ||
} | ||
fun dto() = PølseradDto(pølser.map { it.dto() }, kildeTilRad) | ||
|
||
companion object { | ||
fun fraDto(dto: PølseradDto) = Pølserad( | ||
pølser = dto.pølser.map { Pølse.fraDto(it) }, | ||
kildeTilRad = dto.kildeTilRad | ||
) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
fabrikk/src/main/kotlin/no/nav/helse/spekemat/fabrikk/PølseradDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package no.nav.helse.spekemat.fabrikk | ||
|
||
import java.util.* | ||
|
||
data class PølseradDto( | ||
val pølser: List<PølseDto>, | ||
val kildeTilRad: UUID | ||
) |
3 changes: 3 additions & 0 deletions
3
fabrikk/src/main/kotlin/no/nav/helse/spekemat/fabrikk/Pølsestatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package no.nav.helse.spekemat.fabrikk | ||
|
||
enum class Pølsestatus { ÅPEN, LUKKET, FORKASTET } |
2 changes: 1 addition & 1 deletion
2
...ekemat/foredler/DuplikathåndteringTest.kt → ...pekemat/fabrikk/DuplikathåndteringTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../nav/helse/spekemat/foredler/PølseTest.kt → ...o/nav/helse/spekemat/fabrikk/PølseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lse/spekemat/foredler/PølsefabrikkTest.kt → ...else/spekemat/fabrikk/PølsefabrikkTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
rootProject.name = "pølsefabrikk" | ||
include("foredler", "slakter") | ||
include("foredler", "fabrikk", "slakter") | ||
|