Move all file in fr.dcproject.
This commit is contained in:
14
src/main/kotlin/fr/dcproject/common/entity/CreatedBy.kt
Normal file
14
src/main/kotlin/fr/dcproject/common/entity/CreatedBy.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityI
|
||||
|
||||
/**
|
||||
* TODO remove EntityCreatedBy<EntityI>
|
||||
*/
|
||||
interface CreatedBy<T : CitizenI> : EntityCreatedBy<EntityI> {
|
||||
override val createdBy: T
|
||||
}
|
||||
|
||||
class CreatedByImp<T : CitizenI>(override val createdBy: T) : CreatedBy<T>
|
||||
8
src/main/kotlin/fr/dcproject/common/entity/EntityI.kt
Normal file
8
src/main/kotlin/fr/dcproject/common/entity/EntityI.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import java.util.UUID
|
||||
|
||||
interface EntityI : EntityI {
|
||||
val id: UUID
|
||||
}
|
||||
66
src/main/kotlin/fr/dcproject/common/entity/Extra.kt
Normal file
66
src/main/kotlin/fr/dcproject/common/entity/Extra.kt
Normal file
@@ -0,0 +1,66 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.dcproject.component.article.ArticleRef
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.comment.generic.CommentRef
|
||||
import fr.dcproject.component.constitution.ConstitutionRef
|
||||
import fr.dcproject.component.opinion.entity.OpinionRef
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
|
||||
interface ExtraI<T : TargetI, C : CitizenI> :
|
||||
UuidEntityI,
|
||||
HasTarget<T>,
|
||||
EntityCreatedAt,
|
||||
EntityCreatedBy<C>
|
||||
|
||||
interface HasTarget<T : TargetI> {
|
||||
val target: T
|
||||
}
|
||||
|
||||
open class TargetRef(id: UUID? = null, reference: String = "") : TargetI, UuidEntity(id) {
|
||||
|
||||
final override val reference: String
|
||||
get() = if (field != "") field else TargetI.getReference(this)
|
||||
|
||||
init {
|
||||
this.reference = reference
|
||||
}
|
||||
}
|
||||
|
||||
interface TargetI : UuidEntityI {
|
||||
enum class TargetName(val targetReference: String) {
|
||||
Article("article"),
|
||||
Constitution("constitution"),
|
||||
Comment("comment"),
|
||||
Opinion("opinion")
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun <T : TargetI> getReference(t: KClass<T>): String {
|
||||
return when {
|
||||
t.isSubclassOf(ArticleRef::class) -> TargetName.Article.targetReference
|
||||
t.isSubclassOf(ConstitutionRef::class) -> TargetName.Constitution.targetReference
|
||||
t.isSubclassOf(CommentRef::class) -> TargetName.Comment.targetReference
|
||||
t.isSubclassOf(OpinionRef::class) -> TargetName.Opinion.targetReference
|
||||
else -> throw error("target not implemented: ${t.qualifiedName} \nImplement it or return 'reference' from SQL")
|
||||
}
|
||||
}
|
||||
|
||||
fun getReference(t: TargetI): String {
|
||||
val ref = this.getReference(t::class)
|
||||
return if (t is ExtraI<*, *>) {
|
||||
"${ref}_on_${t.target.reference}"
|
||||
} else {
|
||||
ref
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val reference: String
|
||||
}
|
||||
17
src/main/kotlin/fr/dcproject/common/entity/Versionable.kt
Normal file
17
src/main/kotlin/fr/dcproject/common/entity/Versionable.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityVersioning
|
||||
import java.util.UUID
|
||||
|
||||
interface VersionableRef {
|
||||
val versionId: UUID
|
||||
}
|
||||
|
||||
class VersionableRefImp(
|
||||
override val versionId: UUID
|
||||
) : VersionableRef
|
||||
|
||||
interface Versionable : VersionableRef, EntityVersioning<UUID, Int> {
|
||||
override val versionId: UUID
|
||||
override val versionNumber: Int
|
||||
}
|
||||
Reference in New Issue
Block a user