All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.infobip.kafkistry.sql.sources.RegistryQuotaEntitiesDataSource.kt Maven / Gradle / Ivy

There is a newer version: 0.8.0
Show newest version
@file:Suppress("JpaDataSourceORMInspection")

package com.infobip.kafkistry.sql.sources

import com.infobip.kafkistry.model.*
import com.infobip.kafkistry.service.cluster.ClustersRegistryService
import com.infobip.kafkistry.service.quotas.QuotasRegistryService
import com.infobip.kafkistry.sql.SqlDataSource
import org.springframework.stereotype.Component
import jakarta.persistence.*

@Component
class RegistryQuotaEntitiesDataSource(
    private val clustersRegistry: ClustersRegistryService,
    private val quotasRegistry: QuotasRegistryService,
) : SqlDataSource {

    override fun modelAnnotatedClass(): Class = RegistryQuotaEntity::class.java

    override fun supplyEntities(): List {
        val allClustersRefs = clustersRegistry.listClustersRefs()
        val allQuotas = quotasRegistry.listAllQuotas()
        return allQuotas.map { mapQuotaEntity(it, allClustersRefs) }
    }

    private fun mapQuotaEntity(quotaDescription: QuotaDescription, allClusters: List): RegistryQuotaEntity {
        return RegistryQuotaEntity().apply {
            quotaEntityID = quotaDescription.entity.asID()
            owner = quotaDescription.owner
            user = quotaDescription.entity.user ?: ""
            clientId = quotaDescription.entity.clientId ?: ""
            presenceType = quotaDescription.presence.type
            presenceClusters = allClusters
                .filter { quotaDescription.presence.needToBeOnCluster(it) }
                .map { PresenceCluster().apply { cluster = it.identifier } }
            presenceTag = quotaDescription.presence.tag
        }
    }

}

@Entity
@Table(name = "RegistryQuotaEntities")
class RegistryQuotaEntity {

    @Id
    lateinit var quotaEntityID: QuotaEntityID

    lateinit var user: KafkaUser
    lateinit var clientId: KafkaUser

    lateinit var owner: String

    @Enumerated(EnumType.STRING)
    lateinit var presenceType: PresenceType

    @ElementCollection
    @JoinTable(name = "RegistryQuotaEntities_PresenceClusters")
    lateinit var presenceClusters: List

    var presenceTag: Tag? = null
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy