Lint
This commit is contained in:
@@ -8,7 +8,7 @@ import java.util.*
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.full.isSubclassOf
|
import kotlin.reflect.full.isSubclassOf
|
||||||
|
|
||||||
interface ExtraI<T : TargetI, C: CitizenI> :
|
interface ExtraI<T : TargetI, C : CitizenI> :
|
||||||
UuidEntityI,
|
UuidEntityI,
|
||||||
EntityCreatedAt,
|
EntityCreatedAt,
|
||||||
EntityCreatedBy<C> {
|
EntityCreatedBy<C> {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Follow<T : TargetI>(
|
|||||||
) : ExtraI<T, CitizenBasicI>,
|
) : ExtraI<T, CitizenBasicI>,
|
||||||
FollowSimple<T, CitizenBasicI>(id, createdBy, target)
|
FollowSimple<T, CitizenBasicI>(id, createdBy, target)
|
||||||
|
|
||||||
open class FollowSimple<T : TargetI, C: CitizenI>(
|
open class FollowSimple<T : TargetI, C : CitizenI>(
|
||||||
id: UUID = UUID.randomUUID(),
|
id: UUID = UUID.randomUUID(),
|
||||||
override val createdBy: C,
|
override val createdBy: C,
|
||||||
override var target: T
|
override var target: T
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ open class Opinion<T : TargetI>(
|
|||||||
override val createdBy: CitizenBasic,
|
override val createdBy: CitizenBasic,
|
||||||
override val target: T,
|
override val target: T,
|
||||||
val choice: OpinionChoice
|
val choice: OpinionChoice
|
||||||
) : ExtraI<T,CitizenBasicI>,
|
) : ExtraI<T, CitizenBasicI>,
|
||||||
TargetRef(id),
|
TargetRef(id),
|
||||||
EntityCreatedAt by EntityCreatedAtImp(),
|
EntityCreatedAt by EntityCreatedAtImp(),
|
||||||
EntityCreatedBy<CitizenBasicI> by EntityCreatedByImp(createdBy) {
|
EntityCreatedBy<CitizenBasicI> by EntityCreatedByImp(createdBy) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import kotlinx.coroutines.runBlocking
|
|||||||
import kotlinx.io.errors.IOException
|
import kotlinx.io.errors.IOException
|
||||||
import fr.dcproject.repository.FollowArticle as FollowArticleRepository
|
import fr.dcproject.repository.FollowArticle as FollowArticleRepository
|
||||||
|
|
||||||
|
|
||||||
class ArticleUpdate(
|
class ArticleUpdate(
|
||||||
target: Article
|
target: Article
|
||||||
) : EntityEvent(target, "article", "update") {
|
) : EntityEvent(target, "article", "update") {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ abstract class EntityEvent(
|
|||||||
class EventSubscriber {
|
class EventSubscriber {
|
||||||
class Configuration(private val monitor: ApplicationEvents) {
|
class Configuration(private val monitor: ApplicationEvents) {
|
||||||
private val subscribers = mutableListOf<DisposableHandle>()
|
private val subscribers = mutableListOf<DisposableHandle>()
|
||||||
fun <T: Event> subscribe(definition: EventDefinition<T>, handler: EventHandler<T>): DisposableHandle {
|
fun <T : Event> subscribe(definition: EventDefinition<T>, handler: EventHandler<T>): DisposableHandle {
|
||||||
return monitor.subscribe(definition, handler).also {
|
return monitor.subscribe(definition, handler).also {
|
||||||
subscribers.add(it)
|
subscribers.add(it)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,14 @@ class Publisher(
|
|||||||
private val factory: ConnectionFactory,
|
private val factory: ConnectionFactory,
|
||||||
private val logger: Logger = LoggerFactory.getLogger(Publisher::class.qualifiedName)
|
private val logger: Logger = LoggerFactory.getLogger(Publisher::class.qualifiedName)
|
||||||
) {
|
) {
|
||||||
fun <T: EntityEvent>publish(it: T): Job {
|
fun <T : EntityEvent> publish(it: T): Job {
|
||||||
return GlobalScope.launch {
|
return GlobalScope.launch {
|
||||||
factory.newConnection().use { connection -> connection.createChannel().use { channel ->
|
factory.newConnection().use { connection ->
|
||||||
channel.basicPublish(config.exchangeNotificationName, "", null, it.serialize().toByteArray())
|
connection.createChannel().use { channel ->
|
||||||
logger.debug("Publish message ${it.target.id}")
|
channel.basicPublish(config.exchangeNotificationName, "", null, it.serialize().toByteArray())
|
||||||
} }
|
logger.debug("Publish message ${it.target.id}")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ sealed class Follow<IN : TargetRef, OUT : TargetRef>(override var requester: Req
|
|||||||
): Paginated<FollowEntity<OUT>> {
|
): Paginated<FollowEntity<OUT>> {
|
||||||
return requester
|
return requester
|
||||||
.getFunction("find_follows_by_citizen")
|
.getFunction("find_follows_by_citizen")
|
||||||
.select(
|
.select(
|
||||||
page, limit,
|
page, limit,
|
||||||
"created_by_id" to citizenId
|
"created_by_id" to citizenId
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun follow(follow: FollowEntity<IN>) {
|
fun follow(follow: FollowEntity<IN>) {
|
||||||
@@ -74,7 +74,7 @@ sealed class Follow<IN : TargetRef, OUT : TargetRef>(override var requester: Req
|
|||||||
paginate.result.forEach {
|
paginate.result.forEach {
|
||||||
emit(it)
|
emit(it)
|
||||||
}
|
}
|
||||||
nextPage = paginate.currentPage+1
|
nextPage = paginate.currentPage + 1
|
||||||
} while (!paginate.isLastPage())
|
} while (!paginate.isLastPage())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,8 @@ class FollowArticle(requester: Requester) : Follow<ArticleRef, ArticleEntity>(re
|
|||||||
): Paginated<FollowSimple<ArticleRef, CitizenRef>> {
|
): Paginated<FollowSimple<ArticleRef, CitizenRef>> {
|
||||||
return requester
|
return requester
|
||||||
.getFunction("find_follows_article_by_target")
|
.getFunction("find_follows_article_by_target")
|
||||||
.select(page, limit,
|
.select(
|
||||||
|
page, limit,
|
||||||
"target_id" to target.id
|
"target_id" to target.id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ class ArticleSteps : En, KoinTest {
|
|||||||
|
|
||||||
Given("I have article") { extraData: DataTable ->
|
Given("I have article") { extraData: DataTable ->
|
||||||
extraData.asMap<String, String>(String::class.java, String::class.java).let { params ->
|
extraData.asMap<String, String>(String::class.java, String::class.java).let { params ->
|
||||||
val username = params["createdBy"]?.toLowerCase()?.replace(' ', '-') ?: error("You must provide the 'createdBy' parameter")
|
val username = params["createdBy"]?.toLowerCase()?.replace(' ', '-')
|
||||||
|
?: error("You must provide the 'createdBy' parameter")
|
||||||
val citizen = get<CitizenRepository>().findByUsername(username) ?: error("Citizen not exist")
|
val citizen = get<CitizenRepository>().findByUsername(username) ?: error("Citizen not exist")
|
||||||
val id = params["id"]?.toUUID() ?: UUID.randomUUID()
|
val id = params["id"]?.toUUID() ?: UUID.randomUUID()
|
||||||
val article = ArticleEntity(
|
val article = ArticleEntity(
|
||||||
@@ -59,7 +60,6 @@ class ArticleSteps : En, KoinTest {
|
|||||||
)
|
)
|
||||||
get<ArticleRepository>().upsert(article)
|
get<ArticleRepository>().upsert(article)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Given("I have article with id {string} created by {string}") { id: String, username: String ->
|
Given("I have article with id {string} created by {string}") { id: String, username: String ->
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ import fr.dcproject.repository.Citizen as CitizenRepository
|
|||||||
import fr.dcproject.repository.OpinionArticle as OpinionRepository
|
import fr.dcproject.repository.OpinionArticle as OpinionRepository
|
||||||
import fr.dcproject.repository.OpinionChoice as OpinionChoiceRepository
|
import fr.dcproject.repository.OpinionChoice as OpinionChoiceRepository
|
||||||
|
|
||||||
|
|
||||||
class OpinionSteps : En, KoinTest {
|
class OpinionSteps : En, KoinTest {
|
||||||
init {
|
init {
|
||||||
Given("I have the opinion {string} on article {string} created by {string}:") { opinionChoice: String, article: String, citizen: String, extraInfo: DataTable ->
|
Given("I have the opinion {string} on article {string} created by {string}:") { opinionChoice: String, article: String, citizen: String, extraInfo: DataTable ->
|
||||||
extraInfo.asMap<String, String>(String::class.java, String::class.java).let {
|
extraInfo.asMap<String, String>(String::class.java, String::class.java).let {
|
||||||
val opinion = OpinionArticle(
|
val opinion = OpinionArticle(
|
||||||
choice = get<OpinionChoiceRepository>().findOpinionsChoiceByName(opinionChoice) ?: error("Opinion Choice not exist"),
|
choice = get<OpinionChoiceRepository>().findOpinionsChoiceByName(opinionChoice)
|
||||||
|
?: error("Opinion Choice not exist"),
|
||||||
target = get<ArticleRepository>().findById(article.toUUID()) ?: error("Article not exist"),
|
target = get<ArticleRepository>().findById(article.toUUID()) ?: error("Article not exist"),
|
||||||
createdBy = get<CitizenRepository>().findById(citizen.toUUID()) ?: error("Citizen not exist")
|
createdBy = get<CitizenRepository>().findById(citizen.toUUID()) ?: error("Citizen not exist")
|
||||||
)
|
)
|
||||||
@@ -25,12 +25,17 @@ class OpinionSteps : En, KoinTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Given("I have an opinion") { extraInfo: DataTable ->
|
Given("I have an opinion") { extraInfo: DataTable ->
|
||||||
extraInfo.asMap<String, String>(String::class.java, String::class.java)?.let { params ->
|
extraInfo.asMap<String, String>(String::class.java, String::class.java)?.let { params ->
|
||||||
val username = params["createdBy"]?.toLowerCase()?.replace(' ', '-') ?: error("You must provide the 'createdBy' parameter")
|
val username = params["createdBy"]?.toLowerCase()?.replace(' ', '-')
|
||||||
|
?: error("You must provide the 'createdBy' parameter")
|
||||||
val opinion = OpinionArticle(
|
val opinion = OpinionArticle(
|
||||||
choice = params["opinion"]?.let { get<OpinionChoiceRepository>().findOpinionsChoiceByName(it) ?: error("Opinion Choice not exist")} ?: error("You must provide the 'opinion' parameter"),
|
choice = params["opinion"]?.let {
|
||||||
target = params["article"]?.let { get<ArticleRepository>().findById(it.toUUID()) ?: error("Article not exist")} ?: error("You must provide the 'article' parameter"),
|
get<OpinionChoiceRepository>().findOpinionsChoiceByName(it) ?: error("Opinion Choice not exist")
|
||||||
|
} ?: error("You must provide the 'opinion' parameter"),
|
||||||
|
target = params["article"]?.let {
|
||||||
|
get<ArticleRepository>().findById(it.toUUID()) ?: error("Article not exist")
|
||||||
|
} ?: error("You must provide the 'article' parameter"),
|
||||||
createdBy = get<CitizenRepository>().findByUsername(username) ?: error("Citizen not exist")
|
createdBy = get<CitizenRepository>().findByUsername(username) ?: error("Citizen not exist")
|
||||||
)
|
)
|
||||||
get<OpinionRepository>().opinion(opinion)
|
get<OpinionRepository>().opinion(opinion)
|
||||||
|
|||||||
Reference in New Issue
Block a user