Skip to content

Commit

Permalink
🎨 Refactor + CI fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbatovK committed Mar 24, 2024
1 parent a7865b0 commit f7b4ded
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ config:
warningsAsErrors: false

build:
maxIssues: 20
maxIssues: 50

console-reports:
active: true
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
package com.albatros.springsecurity.data.model.database

import com.albatros.springsecurity.data.model.dto.TenderDto
import jakarta.persistence.Entity
import org.springframework.data.annotation.Id
import org.springframework.data.elasticsearch.annotations.Document
import org.springframework.data.elasticsearch.annotations.Field
import org.springframework.data.elasticsearch.annotations.FieldType
import org.springframework.validation.annotation.Validated

@Entity
@Validated
@Document(indexName = "tenders", createIndex = true)
class Tender(
@Field(type = FieldType.Text, name = "api_tender_info")
var apiTenderInfo: String?,
@Field(type = FieldType.Keyword, name = "category")
var category: String?,
@Field(type = FieldType.Keyword, name = "customer")
var customer: String?,
@Field(type = FieldType.Text, name = "date")
var date: String?,
@Field(type = FieldType.Text, name = "end_time")
var endTime: String?,
@Field(type = FieldType.Text, name = "etp")
var etp: String?,
@Field(type = FieldType.Text, name = "fz")
var fz: String?,
@Field(type = FieldType.Text, name = "tender_id")
@Id
var tenderId: String?,
@Field(type = FieldType.Long, name = "price")
var price: String?,
@Field(type = FieldType.Text, name = "region")
var region: String?,
@Field(type = FieldType.Keyword, name = "tender_link")
var tenderLink: String?,
@Field(type = FieldType.Keyword, name = "tender_inner_link")
var tenderInnerLink: String?,
@Field(type = FieldType.Text, name = "tender_name")
var tenderName: String?,
@Field(type = FieldType.Keyword, name = "tender_num_outer")
var tenderNumOuter: String?,
@Field(type = FieldType.Text, name = "user_id")
var userId: String?,
) : AbstractEntity()
)

fun TenderDto.toDomainObject() =
Tender(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import org.springframework.validation.annotation.Validated
@Entity
@Validated
class TenderProvider(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var tenderId: Int,
var etpName: String,
var etpLink: String
)
) : AbstractEntity()

fun TenderProviderDto.toDomainObject() =
TenderProvider(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.albatros.springsecurity.data.repository

import com.albatros.springsecurity.data.model.database.Tender
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
import org.springframework.stereotype.Repository

@Repository
interface TenderRepository : ElasticsearchRepository<Tender, String>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MainRoute(
Notification.show("CDs nuts").open()
},
Grid<TenderProvider>().apply {
addColumn(TenderProvider::tenderId).setHeader("Id")
addColumn(TenderProvider::tenderId).setHeader("Tender Id")
addColumn(TenderProvider::etpName).setHeader("Name")

setItems {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.albatros.springsecurity.presentation.schedule

import com.albatros.springsecurity.data.model.database.toDomainObject
import com.albatros.springsecurity.data.model.dto.TenderDto
import com.albatros.springsecurity.data.model.dto.TenderProviderDto
import com.albatros.springsecurity.data.repository.TenderProviderRepository
import com.albatros.springsecurity.data.repository.TenderRepository
import com.albatros.springsecurity.data.service.TenderApiService
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand All @@ -13,13 +15,14 @@ import org.springframework.scheduling.annotation.Scheduled
@Configuration
class Scheduler(
private val tenderProviderRepository: TenderProviderRepository,
private val tenderRepository: TenderRepository,
private val apiService: TenderApiService,
) {

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

@Async
@Scheduled(fixedDelay = 1_00_000)
@Scheduled(fixedDelay = 100_000)
fun scheduleTenderProvidersData() {
logger.debug("Collecting providers data from external sources.")
apiService.getAllTenderProviders()?.let {
Expand All @@ -32,7 +35,18 @@ class Scheduler(
}

@Async
@Scheduled(fixedDelay = 1_000_000)
@Scheduled(fixedDelay = 100_000)
fun scheduleTendersData() {
logger.debug("Collecting tenders data from external sources.")

tenderProviderRepository.findAll().forEach { provider ->
apiService.getTendersByProviders(provider.tenderId)?.let {
tenderRepository.saveAll(
it.map(TenderDto::toDomainObject)
)
}
}

logger.debug("Collection stopped.")
}
}

0 comments on commit f7b4ded

Please sign in to comment.