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

com.infobip.kafkistry.sql.sources.AclPrincipalsDataSource.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.PrincipalId
import com.infobip.kafkistry.service.acl.AclsInspectionService
import com.infobip.kafkistry.service.acl.PrincipalAclsInspection
import com.infobip.kafkistry.sql.SqlDataSource
import org.springframework.stereotype.Component
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table

@Component
class AclPrincipalsDataSource(
    private val aclsInspectionService: AclsInspectionService,
) : SqlDataSource {

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

    override fun supplyEntities(): List {
        val allPrincipals = aclsInspectionService.inspectAllPrincipals()
        val unknownPrincipals = aclsInspectionService.inspectUnknownPrincipals()
        return (allPrincipals + unknownPrincipals).map { mapPrincipal(it) }
    }

    private fun mapPrincipal(
        principalAclsInspection: PrincipalAclsInspection
    ): Principal {
        return Principal().apply {
            principal = principalAclsInspection.principal
            inRegistry = principalAclsInspection.principalAcls != null
            description = principalAclsInspection.principalAcls?.description
            owner = principalAclsInspection.principalAcls?.owner
        }
    }

}

@Entity
@Table(name = "Principals")
class Principal {

    @Id
    lateinit var principal: PrincipalId

    @Column(nullable = false)
    var inRegistry: Boolean? = null

    var description: String? = null
    var owner: String? = null
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy