Skip to content

Commit

Permalink
GitProperties deles nå i kontroller-modulen. Refakturert ut typescrip…
Browse files Browse the repository at this point in the history
…t-kode til utils-fil.
  • Loading branch information
roar-skinderviken committed Nov 30, 2022
1 parent 178aa2b commit 6890806
Show file tree
Hide file tree
Showing 23 changed files with 202 additions and 176 deletions.
41 changes: 39 additions & 2 deletions kontroller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<spock.version>2.3-groovy-4.0</spock.version>

<kotlinVersion>1.7.21</kotlinVersion>
<kotestVersion>5.5.4</kotestVersion>
<jackson.version>2.14.0</jackson.version>
</properties>

Expand Down Expand Up @@ -61,7 +62,6 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -108,6 +108,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<!-- scope = test -->
Expand Down Expand Up @@ -144,10 +145,46 @@
<version>${spock.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-core-jvm</artifactId>
<version>${kotestVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-runner-junit5-jvm</artifactId>
<version>${kotestVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties
</generateGitPropertiesFilename>
<includeOnlyProperties>
<includeOnlyProperty>^git.tags$</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
Expand All @@ -173,14 +210,14 @@
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
<sourceDir>${project.basedir}/src/test/groovy</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import java.util.Map;
import java.util.TreeMap;

import static no.ssb.kostra.felles.git.GitPropertiesLoader.DEFAULT_GIT_PROPERTIES_FILENAME;
import static no.ssb.kostra.felles.git.GitPropertiesLoader.loadGitProperties;

@SuppressWarnings("SpellCheckingInspection")
public class ErrorReport {
private final List<ErrorReportEntry> entries = new ArrayList<>();
Expand Down Expand Up @@ -82,7 +85,7 @@ public boolean addEntry(final ErrorReportEntry errorReportEntry) {
}

public String generateReport() {
final var VERSION = "v2022.11.16";
final var releaseVersion = loadGitProperties(DEFAULT_GIT_PROPERTIES_FILENAME).getTags();
final var report = new StringBuilder();
final var lf = args.getNewline();

Expand All @@ -98,7 +101,7 @@ public String generateReport() {
.append("<body>").append(lf)
.append("<hr/>").append(lf)
.append("<h2>Kontrollrapport for ").append(this.args.getRegion()).append(" ").append(args.getNavn()).append("</h2>").append(lf)
.append("<hr/>").append(lf).append("<div>Kontrollprogramversjon: ").append(VERSION).append("</div>").append(lf)
.append("<hr/>").append(lf).append("<div>Kontrollprogramversjon: ").append(releaseVersion).append("</div>").append(lf)
.append("<div>Kontroller startet: ").append(startTime).append("</div>").append(lf)
.append("<div>Rapport generert: ").append(Calendar.getInstance().getTime()).append("</div>").append(lf)
.append("<div>Type filuttrekk: ").append(this.args.getSkjema()).append(".").append(this.args.getAargang()).append("</div>").append(lf)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package no.ssb.kostra.felles.git

data class GitProperties(
val tags: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package no.ssb.kostra.felles.git

import java.util.*

object GitPropertiesLoader {
const val DEFAULT_GIT_PROPERTIES_FILENAME = "/git.properties"
const val NOT_AVAILABLE_VALUE = ""
private const val GIT_TAGS_KEY = "git.tags"

@JvmStatic
fun loadGitProperties(gitPropertiesFilename: String): GitProperties =
this::class.java.getResourceAsStream(gitPropertiesFilename)?.use {
GitProperties(tags = Properties().apply { load(it) }.getProperty(GIT_TAGS_KEY, NOT_AVAILABLE_VALUE))
} ?: GitProperties(tags = NOT_AVAILABLE_VALUE)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public void generateErrorReportTest() {
));

assertEquals(Constants.CRITICAL_ERROR, errorReport.getErrorType());
assertTrue(errorReport.generateReport().contains("\n"));

var errorReportHtml = errorReport.generateReport();
assertTrue(errorReportHtml.contains("\n"));
assertTrue(errorReportHtml.contains("Kontrollprogramversjon: LOCAL-SNAPSHOT"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package no.ssb.kostra.web.status
package no.ssb.kostra.felles.git

import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import no.ssb.kostra.web.status.GitPropertiesLoader.Companion.GIT_PROPERTIES_FILENAME
import no.ssb.kostra.web.status.GitPropertiesLoader.Companion.NOT_AVAILABLE_VALUE
import no.ssb.kostra.web.status.GitPropertiesLoader.Companion.initGitProperties
import no.ssb.kostra.felles.git.GitPropertiesLoader.DEFAULT_GIT_PROPERTIES_FILENAME
import no.ssb.kostra.felles.git.GitPropertiesLoader.NOT_AVAILABLE_VALUE
import no.ssb.kostra.felles.git.GitPropertiesLoader.loadGitProperties

class GitPropertiesLoaderTest : BehaviorSpec({

given("initGitProperties") {

`when`("non-existing gitPropertiesFilename") {

val result = initGitProperties("non-existing.properties")
val result = loadGitProperties("non-existing.properties")

then("result should be fallback") {
result shouldBe GitProperties(
Expand All @@ -24,7 +24,7 @@ class GitPropertiesLoaderTest : BehaviorSpec({

`when`("existing gitPropertiesFilename") {

val result = initGitProperties(GIT_PROPERTIES_FILENAME)
val result = loadGitProperties(DEFAULT_GIT_PROPERTIES_FILENAME)

then("result should not be fallback") {
result shouldNotBe GitProperties(
Expand Down
1 change: 1 addition & 0 deletions kontroller/src/test/resources/git.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git.tags=LOCAL-SNAPSHOT
81 changes: 28 additions & 53 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<micronaut.runtime>netty</micronaut.runtime>

<kotlinVersion>1.7.21</kotlinVersion>
<kotestVersion>5.5.4</kotestVersion>
<jackson.version>2.14.0</jackson.version>
<exec.mainClass>no.ssb.kostra.web.ApplicationKt</exec.mainClass>

<frontend-src-dir>${project.basedir}/src/main/vite-project</frontend-src-dir>
Expand Down Expand Up @@ -61,43 +63,34 @@
<artifactId>kotlin-reflect</artifactId>
<version>${kotlinVersion}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.5.0</version>
</dependency>

<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject</artifactId>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.14.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-client</artifactId>
<artifactId>micronaut-http-server-netty</artifactId>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-server-netty</artifactId>
<groupId>io.micronaut.kotlin</groupId>
<artifactId>micronaut-kotlin-extension-functions</artifactId>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>io.micronaut.kotlin</groupId>
<artifactId>micronaut-kotlin-extension-functions</artifactId>
</dependency>
<dependency>
<groupId>io.micronaut.kotlin</groupId>
<artifactId>micronaut-kotlin-runtime</artifactId>
Expand All @@ -107,26 +100,36 @@
<artifactId>micronaut-views-thymeleaf</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>

<!-- scope = test -->
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.micronaut.test</groupId>
<artifactId>micronaut-test-kotest5</artifactId>
<version>3.7.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-core-jvm</artifactId>
<version>5.5.4</version>
<version>${kotestVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-runner-junit5-jvm</artifactId>
<version>5.5.4</version>
<version>${kotestVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -135,12 +138,6 @@
<version>1.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.micronaut.test</groupId>
<artifactId>micronaut-test-kotest5</artifactId>
<version>3.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
Expand All @@ -155,30 +152,6 @@
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>

<plugins>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties
</generateGitPropertiesFilename>
<includeOnlyProperties>
<includeOnlyProperty>^git.tags$</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
</plugin>

<plugin>
<groupId>io.micronaut.build</groupId>
<artifactId>micronaut-maven-plugin</artifactId>
Expand Down Expand Up @@ -348,6 +321,7 @@
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.0</version>
<executions>
Expand Down Expand Up @@ -380,6 +354,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>${project.build.directory}/jar</outputDirectory>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.ssb.kostra.web.controller

import com.fasterxml.jackson.module.kotlin.readValue
import com.fasterxml.jackson.databind.ObjectMapper
import io.micronaut.core.async.annotation.SingleResult
import io.micronaut.http.HttpResponse
Expand All @@ -10,9 +11,9 @@ import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Post
import io.micronaut.http.multipart.StreamingFileUpload
import io.micronaut.validation.validator.Validator
import no.ssb.kostra.felles.git.GitProperties
import no.ssb.kostra.web.config.UiConfig
import no.ssb.kostra.web.service.FileValidator
import no.ssb.kostra.web.status.GitProperties
import no.ssb.kostra.web.viewmodel.FileReportVm
import no.ssb.kostra.web.viewmodel.KostraFormVm
import no.ssb.kostra.web.viewmodel.UiDataVm
Expand Down Expand Up @@ -44,7 +45,7 @@ open class ApiController(
): Mono<HttpResponse<FileReportVm>> {

/** we'll have to deserialize and validate our self because of multipart request */
val kostraForm = objectMapper.readValue(kostraFormAsJson, KostraFormVm::class.java)
val kostraForm = objectMapper.readValue<KostraFormVm>(kostraFormAsJson)
validator.validate(kostraForm).takeIf { it.isNotEmpty() }?.apply {
throw ConstraintViolationException(iterator().asSequence().toSet())
}
Expand Down
8 changes: 0 additions & 8 deletions web/src/main/kotlin/no/ssb/kostra/web/status/GitProperties.kt

This file was deleted.

Loading

0 comments on commit 6890806

Please sign in to comment.