Skip to content
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
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[*.{kt,kts}]
ktlint_disabled_rules=no-wildcard-imports
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ on:

jobs:
build:
uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v2
uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v3
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ on:

jobs:
build-and-deploy:
uses: valitydev/java-workflow/.github/workflows/maven-service-deploy.yml@v2
uses: valitydev/java-workflow/.github/workflows/maven-service-deploy.yml@v3
with:
ignore-coverage: true
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}
mm-webhook-url: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
31 changes: 22 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>dev.vality</groupId>
<artifactId>service-parent-pom</artifactId>
<version>2.0.3</version>
<version>3.1.0</version>
</parent>
<artifactId>rate-boss</artifactId>
<version>0.0.1-SNAPSHOT</version>
Expand All @@ -14,8 +14,8 @@
<properties>
<server.port>8022</server.port>
<management.port>8023</management.port>
<java.version>17</java.version>
<kotlin.version>1.7.10</kotlin.version>
<java.version>21</java.version>
<kotlin.version>2.1.21</kotlin.version>
<testcontainers.version>1.17.3</testcontainers.version>
<exposed.ports>${server.port} ${management.port}</exposed.ports>
<db.port>5432</db.port>
Expand Down Expand Up @@ -94,14 +94,18 @@
<dependency>
<groupId>dev.vality.geck</groupId>
<artifactId>common</artifactId>
<version>0.0.1</version>
<version>1.0.2</version>
</dependency>

<!--Third party-->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down Expand Up @@ -150,6 +154,10 @@
<version>1.4</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>

<!--Test/Dev-->
<dependency>
Expand Down Expand Up @@ -238,7 +246,7 @@
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>dev.vality.maven.plugins</groupId>
<groupId>dev.crashteam.maven.plugins</groupId>
<artifactId>pg-embedded-plugin</artifactId>
<version>1.0.1</version>
<configuration>
Expand All @@ -258,12 +266,19 @@
</execution>
<execution>
<id>PG_server_stop</id>
<phase>compile</phase>
<phase>generate-resources</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.18.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.flywaydb</groupId>
Expand Down Expand Up @@ -332,7 +347,6 @@
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
Expand All @@ -341,7 +355,6 @@
<plugin>spring</plugin>
<plugin>jpa</plugin>
</compilerPlugins>
<jvmTarget>1.8</jvmTarget>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -386,7 +399,7 @@
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>1.15.1</version>
<version>3.5.0</version>
<executions>
<execution>
<phase>validate</phase>
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/dev/vality/rateboss/client/cbr/CbrApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import java.time.format.DateTimeFormatter
@Component
class CbrApiClient(
private val restTemplate: RestTemplate,
private val ratesProperties: RatesProperties
private val ratesProperties: RatesProperties,
) {

fun getExchangeRates(time: Instant): CbrExchangeRateData {
val baseUrl = ratesProperties.source.cbr.rootUrl
val timezone = ratesProperties.source.cbr.timeZone
Expand All @@ -26,13 +25,15 @@ class CbrApiClient(
return restTemplate.exchange<CbrExchangeRateData>(url, HttpMethod.GET, HttpEntity(null, null)).body!!
}

private fun buildUrl(endpoint: String, date: LocalDate): String {
return UriComponentsBuilder
private fun buildUrl(
endpoint: String,
date: LocalDate,
): String =
UriComponentsBuilder
.fromUriString(endpoint)
.queryParam("date_req", date.format(DATE_TIME_FORMATTER))
.build()
.toUriString()
}

companion object {
val DATE_TIME_FORMATTER: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import java.math.BigDecimal
import javax.xml.bind.annotation.adapters.XmlAdapter

class CbrBigDecimalXmlAdapter : XmlAdapter<String, BigDecimal>() {

override fun unmarshal(stringValue: String?): BigDecimal? {
return stringValue?.let {
override fun unmarshal(stringValue: String?): BigDecimal? =
stringValue?.let {
BigDecimal(it.replace(',', '.'))
}
}

override fun marshal(bigDecimalValue: BigDecimal?): String? {
return bigDecimalValue?.toString()?.replace('.', ',')
}
override fun marshal(bigDecimalValue: BigDecimal?): String? = bigDecimalValue?.toString()?.replace('.', ',')
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ import java.time.format.DateTimeFormatter
import javax.xml.bind.annotation.adapters.XmlAdapter

class CbrLocalDateXmlAdapter : XmlAdapter<String, LocalDate>() {

override fun unmarshal(stringValue: String?): LocalDate? {
return stringValue?.let {
override fun unmarshal(stringValue: String?): LocalDate? =
stringValue?.let {
LocalDate.from(DATE_FORMATTER.parse(it))
}
}

override fun marshal(dateValue: LocalDate?): String? {
return dateValue?.let {
override fun marshal(dateValue: LocalDate?): String? =
dateValue?.let {
DATE_FORMATTER.format(it)
}
}

companion object {
val DATE_FORMATTER: DateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter
@XmlRootElement(name = "Valute")
@XmlAccessorType(XmlAccessType.FIELD)
class CbrCurrencyData {

@XmlAttribute(name = "ID")
var id: String? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter
@XmlRootElement(name = "ValCurs")
@XmlAccessorType(XmlAccessType.FIELD)
class CbrExchangeRateData {

@XmlAttribute
var name: String? = null

Expand Down
43 changes: 24 additions & 19 deletions src/main/kotlin/dev/vality/rateboss/client/fixer/FixerApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,31 @@ import org.springframework.web.util.UriComponentsBuilder
@Component
class FixerApiClient(
private val ratesProperties: RatesProperties,
private val restTemplate: RestTemplate
private val restTemplate: RestTemplate,
) {

fun getLatest(base: String, symbols: String? = null): FixerLatestResponse {
val urlTemplate = UriComponentsBuilder.fromHttpUrl(ratesProperties.source.fixer.rootUrl).apply {
path("/latest")
queryParam("base", base)
if (symbols != null) {
queryParam("symbols", symbols)
fun getLatest(
base: String,
symbols: String? = null,
): FixerLatestResponse {
val urlTemplate =
UriComponentsBuilder.fromHttpUrl(ratesProperties.source.fixer.rootUrl).apply {
path("/latest")
queryParam("base", base)
if (symbols != null) {
queryParam("symbols", symbols)
}
encode()
toUriString()
}
val httpHeaders =
HttpHeaders().apply {
set("apiKey", ratesProperties.source.fixer.apiKey)
}
encode()
toUriString()
}
val httpHeaders = HttpHeaders().apply {
set("apiKey", ratesProperties.source.fixer.apiKey)
}
return restTemplate.exchange<FixerLatestResponse>(
urlTemplate.toUriString(),
HttpMethod.GET,
HttpEntity(null, httpHeaders)
).body!!
return restTemplate
.exchange<FixerLatestResponse>(
urlTemplate.toUriString(),
HttpMethod.GET,
HttpEntity(null, httpHeaders),
).body!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ data class FixerLatestResponse(
val date: LocalDate?,
val rates: Map<String, BigDecimal>?,
val success: Boolean,
val timestamp: Long?
val timestamp: Long?,
)
3 changes: 1 addition & 2 deletions src/main/kotlin/dev/vality/rateboss/config/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import org.springframework.web.client.RestTemplate

@Configuration
class AppConfig {

@Bean
fun restTemplate() = RestTemplate()

@Bean
fun retryTemplate(
@Value("\${retryTemplate.backOffPeriod}") backOffPeriod: Long,
@Value("\${retryTemplate.maxAttempts}") maxAttempts: Int
@Value("\${retryTemplate.maxAttempts}") maxAttempts: Int,
): RetryTemplate {
val retryTemplate = RetryTemplate()
val fixedBackOffPolicy = FixedBackOffPolicy()
Expand Down
13 changes: 6 additions & 7 deletions src/main/kotlin/dev/vality/rateboss/config/JobConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import javax.annotation.PostConstruct

@Configuration
class JobConfig {

@Autowired
private lateinit var schedulerFactoryBean: Scheduler

Expand Down Expand Up @@ -43,13 +42,13 @@ class JobConfig {
return jobDetail
}

fun fixerExchangeRateGrabberMasterTrigger(): CronTrigger {
return TriggerBuilder.newTrigger()
fun fixerExchangeRateGrabberMasterTrigger(): CronTrigger =
TriggerBuilder
.newTrigger()
.forJob(fixerExchangeRateGrabberMasterJob())
.withIdentity(ratesProperties.fixerJob.jobTriggerName)
.withSchedule(CronScheduleBuilder.cronSchedule(ratesProperties.fixerJob.jobCron))
.build()
}

fun cbrExchangeRateGrabberMasterJob(): JobDetailImpl {
val jobDetail = JobDetailImpl()
Expand All @@ -58,11 +57,11 @@ class JobConfig {
return jobDetail
}

fun cbrExchangeRateGrabberMasterTrigger(): CronTrigger {
return TriggerBuilder.newTrigger()
fun cbrExchangeRateGrabberMasterTrigger(): CronTrigger =
TriggerBuilder
.newTrigger()
.forJob(cbrExchangeRateGrabberMasterJob())
.withIdentity(ratesProperties.cbrJob.jobTriggerName)
.withSchedule(CronScheduleBuilder.cronSchedule(ratesProperties.cbrJob.jobCron))
.build()
}
}
17 changes: 7 additions & 10 deletions src/main/kotlin/dev/vality/rateboss/config/KafkaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.springframework.kafka.core.ProducerFactory

@Configuration
class KafkaConfig {

@Autowired
lateinit var kafkaProperties: KafkaProperties

Expand All @@ -27,7 +26,7 @@ class KafkaConfig {
retryBackoffMs: Long,
batchSize: Int,
acks: String,
deliveryTimeout: Int
deliveryTimeout: Int,
): Map<String, Any> {
val props: MutableMap<String, Any> = HashMap(kafkaProperties.buildProducerProperties())
props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java
Expand All @@ -41,22 +40,20 @@ class KafkaConfig {
}

@Bean
fun producerFactory(): ProducerFactory<String, CurrencyEvent> {
return DefaultKafkaProducerFactory(
fun producerFactory(): ProducerFactory<String, CurrencyEvent> =
DefaultKafkaProducerFactory(
producerConfigs(
kafkaCustomProperties.producer.maxRetries,
kafkaCustomProperties.producer.retryBackoffMs,
kafkaCustomProperties.producer.batchSize,
ACKS_CONFIG,
kafkaCustomProperties.producer.deliveryTimeoutMs
)
kafkaCustomProperties.producer.deliveryTimeoutMs,
),
)
}

@Bean
fun kafkaTemplate(producerFactory: ProducerFactory<String, CurrencyEvent>): KafkaTemplate<String, CurrencyEvent> {
return KafkaTemplate(producerFactory)
}
fun kafkaTemplate(producerFactory: ProducerFactory<String, CurrencyEvent>): KafkaTemplate<String, CurrencyEvent> =
KafkaTemplate(producerFactory)

private companion object {
const val ACKS_CONFIG = "1"
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/dev/vality/rateboss/config/QuartzConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import javax.sql.DataSource

@Configuration
class QuartzConfig {

@Autowired
private lateinit var quartzProperties: QuartzProperties

Expand Down
Loading