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

Bumper ktlint #665

Merged
merged 8 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@
</executions>
<dependencies>
<dependency>
<groupId>com.pinterest</groupId>
<artifactId>ktlint</artifactId>
<version>0.50.0</version>
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-cli</artifactId>
<version>1.1.1</version>
</dependency>
<!-- additional 3rd party ruleset(s) can be specified here -->
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import java.util.Base64
import java.util.UUID

object AvstemmingMapper {

fun encodeUUIDBase64(uuid: UUID): String {
val bb = ByteBuffer.wrap(ByteArray(16))
bb.putLong(uuid.mostSignificantBits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import no.nav.virksomhet.tjenester.avstemming.meldinger.v1.Avstemmingsdata

interface AvstemmingSender {
fun sendGrensesnittAvstemming(avstemmingsdata: Avstemmingsdata)

fun sendKonsistensAvstemming(avstemmingsdata: Konsistensavstemmingsdata)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class AvstemmingSenderMQ(
val jmsTemplateAvstemming: JmsTemplate,
@Value("\${oppdrag.mq.enabled}") val erEnabled: String,
) : AvstemmingSender {

override fun sendGrensesnittAvstemming(avstemmingsdata: Avstemmingsdata) {
val avstemmingXml = JaxbGrensesnittAvstemmingsdata.tilXml(avstemmingsdata)
leggPåKø(avstemmingXml)
}

override fun sendKonsistensAvstemming(avstemmingsdata: Konsistensavstemmingsdata) {
val konsistensavstemmingRequest = SendAsynkronKonsistensavstemmingsdata().apply {
request = SendAsynkronKonsistensavstemmingsdataRequest().apply { konsistensavstemmingsdata = avstemmingsdata }
}
val konsistensavstemmingRequest =
SendAsynkronKonsistensavstemmingsdata().apply {
request = SendAsynkronKonsistensavstemmingsdataRequest().apply { konsistensavstemmingsdata = avstemmingsdata }
}

val requestXml = JaxbKonsistensavstemming.tilXml(konsistensavstemmingRequest)
leggPåKø(requestXml)
Expand Down
33 changes: 19 additions & 14 deletions src/main/kotlin/no/nav/familie/oppdrag/common/RessursUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,37 @@ import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity

object RessursUtils {

private val LOG = LoggerFactory.getLogger(this::class.java)
private val secureLogger = LoggerFactory.getLogger("secureLogger")

fun <T> unauthorized(errorMessage: String): ResponseEntity<Ressurs<T>> =
ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(Ressurs.failure(errorMessage))

fun <T> notFound(errorMessage: String): ResponseEntity<Ressurs<T>> =
errorResponse(HttpStatus.NOT_FOUND, errorMessage, null)
fun <T> notFound(errorMessage: String): ResponseEntity<Ressurs<T>> = errorResponse(HttpStatus.NOT_FOUND, errorMessage, null)

fun <T> badRequest(errorMessage: String, throwable: Throwable?): ResponseEntity<Ressurs<T>> =
errorResponse(HttpStatus.BAD_REQUEST, errorMessage, throwable)
fun <T> badRequest(
errorMessage: String,
throwable: Throwable?,
): ResponseEntity<Ressurs<T>> = errorResponse(HttpStatus.BAD_REQUEST, errorMessage, throwable)

fun <T> forbidden(errorMessage: String): ResponseEntity<Ressurs<T>> =
errorResponse(HttpStatus.FORBIDDEN, errorMessage, null)
fun <T> forbidden(errorMessage: String): ResponseEntity<Ressurs<T>> = errorResponse(HttpStatus.FORBIDDEN, errorMessage, null)

fun <T> conflict(errorMessage: String): ResponseEntity<Ressurs<T>> =
errorResponse(HttpStatus.CONFLICT, errorMessage, null, true)
fun <T> conflict(errorMessage: String): ResponseEntity<Ressurs<T>> = errorResponse(HttpStatus.CONFLICT, errorMessage, null, true)

fun <T> illegalState(errorMessage: String, throwable: Throwable? = null): ResponseEntity<Ressurs<T>> =
errorResponse(HttpStatus.INTERNAL_SERVER_ERROR, errorMessage, throwable)
fun <T> illegalState(
errorMessage: String,
throwable: Throwable? = null,
): ResponseEntity<Ressurs<T>> = errorResponse(HttpStatus.INTERNAL_SERVER_ERROR, errorMessage, throwable)

fun <T> serviceUnavailable(errorMessage: String, throwable: Throwable? = null): ResponseEntity<Ressurs<T>> =
errorResponse(HttpStatus.INTERNAL_SERVER_ERROR, errorMessage, throwable)
fun <T> serviceUnavailable(
errorMessage: String,
throwable: Throwable? = null,
): ResponseEntity<Ressurs<T>> = errorResponse(HttpStatus.INTERNAL_SERVER_ERROR, errorMessage, throwable)

fun <T> ok(data: T, melding: String? = null): ResponseEntity<Ressurs<T>> = ResponseEntity.ok(Ressurs.success(data, melding))
fun <T> ok(
data: T,
melding: String? = null,
): ResponseEntity<Ressurs<T>> = ResponseEntity.ok(Ressurs.success(data, melding))

fun <T> noContent(): ResponseEntity<Ressurs<T>> = ResponseEntity.noContent().build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ private val secureLogger = LoggerFactory.getLogger("secureLogger")

fun logSoapFaultException(e: Exception) {
if (e is SOAPFaultException) {
val details = e.fault.detail?.let { detail ->
detail.detailEntries.asSequence().mapNotNull { it.textContent }.joinToString(",")
}
val details =
e.fault.detail?.let { detail ->
detail.detailEntries.asSequence().mapNotNull { it.textContent }.joinToString(",")
}
secureLogger.error(
"SOAPFaultException -" +
" faultCode=${e.fault.faultCode}" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import org.springframework.web.bind.annotation.ExceptionHandler

@ControllerAdvice
class ApiExceptionHandler {

private val logger: Logger = LoggerFactory.getLogger(this::class.java)
private val secureLogger = LoggerFactory.getLogger("secureLogger")

@ExceptionHandler(JwtTokenUnauthorizedException::class)
fun handleJwtTokenUnauthorizedException(jwtTokenUnauthorizedException: JwtTokenUnauthorizedException): ResponseEntity<Ressurs<Nothing>> {
fun handleJwtTokenUnauthorizedException(
jwtTokenUnauthorizedException: JwtTokenUnauthorizedException,
): ResponseEntity<Ressurs<Nothing>> {
return unauthorized("Unauthorized")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import org.springframework.context.annotation.ComponentScan
import org.springframework.scheduling.annotation.EnableScheduling

@SpringBootConfiguration
@EntityScan(ApplicationConfig.pakkenavn, "no.nav.familie.sikkerhet")
@ComponentScan(ApplicationConfig.pakkenavn, "no.nav.familie.sikkerhet")
@EntityScan(ApplicationConfig.PAKKENAVN, "no.nav.familie.sikkerhet")
@ComponentScan(ApplicationConfig.PAKKENAVN, "no.nav.familie.sikkerhet")
@EnableScheduling
@EnableJwtTokenValidation(ignore = ["org.springframework", "org.springdoc"])
class ApplicationConfig {

@Bean
fun servletWebServerFactory(): ServletWebServerFactory {
val serverFactory = JettyServletWebServerFactory()
Expand All @@ -43,7 +42,7 @@ class ApplicationConfig {
}

companion object {
const val pakkenavn = "no.nav.familie.oppdrag"
val LOKALE_PROFILER = setOf("dev", "e2e", "dev_psql_mq")
const val PAKKENAVN = "no.nav.familie.oppdrag"
val lokaleProfiler = setOf("dev", "e2e", "dev_psql_mq")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import javax.sql.DataSource

@Configuration
class DatabaseConfiguration : AbstractJdbcConfiguration() {

@Bean
fun operations(dataSource: DataSource): NamedParameterJdbcTemplate {
return NamedParameterJdbcTemplate(dataSource)
Expand All @@ -44,15 +43,13 @@ class DatabaseConfiguration : AbstractJdbcConfiguration() {

@ReadingConverter
class PGobjectTilUtbetalingsoppdragConverter : Converter<PGobject, Utbetalingsoppdrag> {

override fun convert(pGobject: PGobject): Utbetalingsoppdrag? {
return pGobject.value?.let { objectMapper.readValue(it) }
}
}

@WritingConverter
class UtbetalingsoppdragTilPGobjectConverter : Converter<Utbetalingsoppdrag, PGobject> {

override fun convert(utbetalingsoppdrag: Utbetalingsoppdrag): PGobject =
PGobject().apply {
type = "json"
Expand All @@ -62,15 +59,13 @@ class DatabaseConfiguration : AbstractJdbcConfiguration() {

@ReadingConverter
class PGobjectTilMmelConverter : Converter<PGobject, Mmel> {

override fun convert(pGobject: PGobject): Mmel? {
return pGobject.value?.let { objectMapper.readValue(it) }
}
}

@WritingConverter
class MmelTilPGobjectConverter : Converter<Mmel, PGobject> {

override fun convert(utbetalingsoppdrag: Mmel): PGobject =
PGobject().apply {
type = "json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import org.springframework.context.annotation.Profile
@Profile("!dev & !dev_psql_mq")
@ConditionalOnProperty("spring.flyway.enabled")
class FlywayConfig {

private val logger = LoggerFactory.getLogger(FlywayConfig::class.java)

@Bean
fun setRole(@Value("\${spring.cloud.vault.database.role}") role: String): FlywayConfigurationCustomizer {
fun setRole(
@Value("\${spring.cloud.vault.database.role}") role: String,
): FlywayConfigurationCustomizer {
logger.info("Setter rolle " + role)
return FlywayConfigurationCustomizer { c -> c.initSql(String.format("SET ROLE \"%s\"", role)) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class OppdragMQConfig(
@Value("\${oppdrag.mq.user}") val user: String,
@Value("\${oppdrag.mq.password}") val password: String,
) {

private val logger = LoggerFactory.getLogger(javaClass)
private val secureLogger = LoggerFactory.getLogger("secureLogger")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ServiceConfig(
@Value("\${SERVICEUSER_PASSWORD}") private val systemuserPwd: String,
@Value("\${OPPDRAG_SERVICE_URL}") private val simulerFpServiceUrl: String,
) {

@Bean
fun stsConfig(): StsConfig {
return StsConfig.builder()
Expand All @@ -26,7 +25,7 @@ class ServiceConfig(
}

@Bean
fun SimulerFpServicePort(): SimulerFpService =
fun simulerFpServicePort(): SimulerFpService =
CXFClient(SimulerFpService::class.java)
.address(simulerFpServiceUrl)
.timeout(20000, 20000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.springframework.context.annotation.Configuration

@Configuration
class SwaggerConfig {

private val bearer = "JWT"

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class VaultHikariConfig(
private val hikariDataSource: HikariDataSource,
private val props: VaultDatabaseProperties,
) : InitializingBean {

private val logger = LoggerFactory.getLogger(VaultHikariConfig::class.java)

override fun afterPropertiesSet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,30 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import javax.xml.namespace.QName

private const val WSDL = "wsdl/no/nav/tilbakekreving/tilbakekreving-v1-tjenestespesifikasjon.wsdl"
private const val NAMESPACE = "http://okonomi.nav.no/tilbakekrevingService/"

@Configuration
class ØkonomiClientConfig(
@Value("\${TILBAKEKREVING_V1_URL}") private val tilbakekrevingUrl: String,
) {

private val WSDL = "wsdl/no/nav/tilbakekreving/tilbakekreving-v1-tjenestespesifikasjon.wsdl"
private val NAMESPACE = "http://okonomi.nav.no/tilbakekrevingService/"
private val SERVICE = QName(NAMESPACE, "TilbakekrevingService")
private val PORT = QName(NAMESPACE, "TilbakekrevingServicePort")
private val service = QName(NAMESPACE, "TilbakekrevingService")
private val port = QName(NAMESPACE, "TilbakekrevingServicePort")

@Bean
fun økonomiService(stsConfig: StsConfig): TilbakekrevingPortType {
val factoryBean = JaxWsProxyFactoryBean().apply {
wsdlURL = WSDL
serviceName = SERVICE
endpointName = PORT
serviceClass = TilbakekrevingPortType::class.java
address = tilbakekrevingUrl
features.add(WSAddressingFeature())
features.add(loggingFeature())
outInterceptors.add(LoggingOutInterceptor())
inInterceptors.add(LoggingInInterceptor())
}
val factoryBean =
JaxWsProxyFactoryBean().apply {
wsdlURL = WSDL
serviceName = service
endpointName = port
serviceClass = TilbakekrevingPortType::class.java
address = tilbakekrevingUrl
features.add(WSAddressingFeature())
features.add(loggingFeature())
outInterceptors.add(LoggingOutInterceptor())
inInterceptors.add(LoggingInInterceptor())
}
return wrapWithSts(factoryBean.create(TilbakekrevingPortType::class.java), stsConfig).apply {
disableCnCheck()
}
Expand All @@ -59,7 +60,10 @@ class ØkonomiClientConfig(
conduit.tlsClientParameters = tlsParams
}

private fun wrapWithSts(port: TilbakekrevingPortType, stsConfig: StsConfig): TilbakekrevingPortType {
private fun wrapWithSts(
port: TilbakekrevingPortType,
stsConfig: StsConfig,
): TilbakekrevingPortType {
val client = ClientProxy.getClient(port)
STSConfigurationUtil.configureStsForSystemUserInFSS(client, stsConfig)
return port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import no.nav.familie.kontrakter.felles.oppdrag.OppdragId
import no.trygdeetaten.skjema.oppdrag.Oppdrag

val Oppdrag.id: OppdragId
get() = OppdragId(
this.oppdrag110.kodeFagomraade,
this.oppdrag110.oppdragGjelderId,
this.oppdrag110.oppdragsLinje150?.get(0)?.henvisning!!,
)
get() =
OppdragId(
this.oppdrag110.kodeFagomraade,
this.oppdrag110.oppdragGjelderId,
this.oppdrag110.oppdragsLinje150?.get(0)?.henvisning!!,
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.UUID

private const val ANTALL_DETALJER_PER_MELDING = 70

class GrensesnittavstemmingMapper(
private val fagområde: String,
private val fom: LocalDateTime,
private val tom: LocalDateTime,
) {

private val ANTALL_DETALJER_PER_MELDING = 70
private val tidspunktFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH.mm.ss.SSSSSS")
val avstemmingId = AvstemmingMapper.encodeUUIDBase64(UUID.randomUUID())

Expand All @@ -37,11 +37,12 @@ class GrensesnittavstemmingMapper(

fun lagStartmelding() = lagMelding(AksjonType.START)

fun lagTotalMelding() = lagMelding(AksjonType.DATA).apply {
this.total = opprettTotalData()
this.periode = opprettPeriodeData()
this.grunnlag = opprettGrunnlagsData()
}
fun lagTotalMelding() =
lagMelding(AksjonType.DATA).apply {
this.total = opprettTotalData()
this.periode = opprettPeriodeData()
this.grunnlag = opprettGrunnlagsData()
}

fun lagSluttmelding() = lagMelding(AksjonType.AVSL)

Expand Down Expand Up @@ -167,10 +168,12 @@ class GrensesnittavstemmingMapper(
}

private fun opprettPeriodeData(): Periodedata {
val fom = avstemmingstidspunkt.fom
?: error("Mangler avstemmingstidspunkt::fom, vi skal ikke opprette meldinger hvis listen med oppdrag er tom")
val tom = avstemmingstidspunkt.tom
?: error("Mangler avstemmingstidspunkt::tom, vi skal ikke opprette meldinger hvis listen med oppdrag er tom")
val fom =
avstemmingstidspunkt.fom
?: error("Mangler avstemmingstidspunkt::fom, vi skal ikke opprette meldinger hvis listen med oppdrag er tom")
val tom =
avstemmingstidspunkt.tom
?: error("Mangler avstemmingstidspunkt::tom, vi skal ikke opprette meldinger hvis listen med oppdrag er tom")
return Periodedata().apply {
this.datoAvstemtFom = formaterTilPeriodedataFormat(fom.format(tidspunktFormatter))
this.datoAvstemtTom = formaterTilPeriodedataFormat(tom.format(tidspunktFormatter))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import no.nav.virksomhet.tjenester.avstemming.meldinger.v1.ObjectFactory
import java.io.StringWriter

object JaxbGrensesnittAvstemmingsdata {

val jaxbContext = JAXBContext.newInstance(Avstemmingsdata::class.java)

fun tilXml(avstemmingsmelding: Avstemmingsdata): String {
Expand Down
Loading