Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5779: Støtte for Kotlin #666

Closed
wants to merge 11 commits into from
  •  
  •  
  •  
124 changes: 123 additions & 1 deletion melosys-eessi-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<artifactId>melosys-eessi-app</artifactId>


<dependencies>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
Expand Down Expand Up @@ -187,6 +186,43 @@
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>io.github.microutils</groupId>
<artifactId>kotlin-logging-jvm</artifactId>
<version>${kotlin-logging.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-core-jvm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-json-jvm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.mockk</groupId>
<artifactId>mockk</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ninja-squad</groupId>
<artifactId>springmockk</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -205,6 +241,92 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/java</source>
<source>target/generated-sources/annotations</source>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/test/java</source>
<source>target/generated-test-sources/test-annotations</source>
</sourceDirs>
</configuration>
</execution>
</executions>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
<plugin>no-arg</plugin>
</compilerPlugins>
<pluginOptions>
<option>no-arg:annotation=jakarta.persistence.Entity</option>
</pluginOptions>
<jvmTarget>${java.version}</jvmTarget>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,75 @@
// Generated by delombok at Thu Jul 04 12:27:09 CEST 2024
package no.nav.melosys.eessi.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "melosys.systemuser")
public class AppCredentials {
private String username;
private String password;

private String username;
private String password;
@java.lang.SuppressWarnings("all")
public AppCredentials() {
}

@java.lang.SuppressWarnings("all")
public String getUsername() {
return this.username;
}

@java.lang.SuppressWarnings("all")
public String getPassword() {
return this.password;
}

@java.lang.SuppressWarnings("all")
public void setUsername(final String username) {
this.username = username;
}

@java.lang.SuppressWarnings("all")
public void setPassword(final String password) {
this.password = password;
}

@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof AppCredentials)) return false;
final AppCredentials other = (AppCredentials) o;
if (!other.canEqual((java.lang.Object) this)) return false;
final java.lang.Object this$username = this.getUsername();
final java.lang.Object other$username = other.getUsername();
if (this$username == null ? other$username != null : !this$username.equals(other$username)) return false;
final java.lang.Object this$password = this.getPassword();
final java.lang.Object other$password = other.getPassword();
if (this$password == null ? other$password != null : !this$password.equals(other$password)) return false;
return true;
}

@java.lang.SuppressWarnings("all")
protected boolean canEqual(final java.lang.Object other) {
return other instanceof AppCredentials;
}

@java.lang.Override
@java.lang.SuppressWarnings("all")
public int hashCode() {
final int PRIME = 59;
int result = 1;
final java.lang.Object $username = this.getUsername();
result = result * PRIME + ($username == null ? 43 : $username.hashCode());
final java.lang.Object $password = this.getPassword();
result = result * PRIME + ($password == null ? 43 : $password.hashCode());
return result;
}

@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "AppCredentials(username=" + this.getUsername() + ", password=" + this.getPassword() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Configuration
@EnableConfigurationProperties(AppCredentials.class)
@EnableJwtTokenValidation(ignore={"org.springframework", "org.springdoc.webmvc"})
@EnableJwtTokenValidation(ignore = {"org.springframework", "org.springdoc.webmvc"})
@EnableRetry
@EnableJpaAuditing
public class ApplicationConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.melosys.eessi.config;

import java.util.concurrent.TimeUnit;

import com.google.common.cache.CacheBuilder;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
Expand All @@ -20,8 +21,8 @@ public CacheManager cacheManager() {
@Override
protected Cache createConcurrentMapCache(String name) {
return new ConcurrentMapCache(name,
CacheBuilder.newBuilder().expireAfterWrite(24, TimeUnit.HOURS).build().asMap(),
false);
CacheBuilder.newBuilder().expireAfterWrite(24, TimeUnit.HOURS).build().asMap(),
false);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Generated by delombok at Thu Jul 04 12:27:09 CEST 2024
package no.nav.melosys.eessi.config;

import jakarta.persistence.EntityManagerFactory;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import lombok.SneakyThrows;
import no.nav.vault.jdbc.hikaricp.HikariCPVaultUtil;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -25,16 +25,12 @@
@Configuration
@EnableJpaRepositories(basePackages = "no.nav.melosys.eessi")
public class DatabaseConfig {

private static final String PROD_MOUNT_PATH = "postgresql/prod-fss";
private static final String PREPROD_MOUNT_PATH = "postgresql/preprod-fss";

@Value("${NAIS_CLUSTER_NAME}")
private String cluster;

@Value("${spring.datasource.url}")
private String jdbcUrl;

@Value("${DATABASE_NAME}")
private String databaseName;

Expand All @@ -51,21 +47,17 @@ public DataSource userDataSource() {

@Bean
public FlywayConfigurationCustomizer flywayConfig(@Qualifier("adminDataSource") DataSource adminDataSource) {
return config ->
config.initSql(String.format("SET ROLE \"%s-admin\"", databaseName))
.dataSource(adminDataSource);
return config -> config.initSql(String.format("SET ROLE \"%s-admin\"", databaseName)).dataSource(adminDataSource);
}

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(userDataSource());
entityManagerFactoryBean.setPackagesToScan("no.nav.melosys.eessi");

HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabase(Database.POSTGRESQL);
entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);

return entityManagerFactoryBean;
}

Expand All @@ -76,15 +68,18 @@ public PlatformTransactionManager jpaTransactionManager(EntityManagerFactory ent
return transactionManager;
}

@SneakyThrows
private HikariDataSource dataSource(String userType) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(jdbcUrl);
config.setMaximumPoolSize(3);
config.setMinimumIdle(1);
String mountPath = isProduction() ? PROD_MOUNT_PATH : PREPROD_MOUNT_PATH;
String dbRole = String.join("-", databaseName, userType);
return HikariCPVaultUtil.createHikariDataSourceWithVaultIntegration(config, mountPath, dbRole);
try {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(jdbcUrl);
config.setMaximumPoolSize(3);
config.setMinimumIdle(1);
String mountPath = isProduction() ? PROD_MOUNT_PATH : PREPROD_MOUNT_PATH;
String dbRole = String.join("-", databaseName, userType);
return HikariCPVaultUtil.createHikariDataSourceWithVaultIntegration(config, mountPath, dbRole);
} catch (final java.lang.Throwable $ex) {
throw lombok.Lombok.sneakyThrow($ex);
}
}

private boolean isProduction() {
Expand Down
Loading
Loading