move some part of KoinModule in components
This commit is contained in:
8
src/main/kotlin/component/article/KoinModule.kt
Normal file
8
src/main/kotlin/component/article/KoinModule.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package fr.dcproject.component.article
|
||||
|
||||
import org.koin.dsl.module
|
||||
|
||||
val articleKoinModule = module {
|
||||
single { ArticleRepository(get()) }
|
||||
single { ArticleAccessControl(get()) }
|
||||
}
|
||||
11
src/main/kotlin/component/auth/KoinModule.kt
Normal file
11
src/main/kotlin/component/auth/KoinModule.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package fr.dcproject.component.auth
|
||||
|
||||
import fr.dcproject.application.Configuration
|
||||
import fr.dcproject.messages.Mailer
|
||||
import org.koin.dsl.module
|
||||
|
||||
val authKoinModule = module {
|
||||
single { UserRepository(get()) }
|
||||
// Used to send a connexion link by email
|
||||
single { PasswordlessAuth(get<Mailer>(), Configuration.domain, get()) }
|
||||
}
|
||||
8
src/main/kotlin/component/citizen/KoinModule.kt
Normal file
8
src/main/kotlin/component/citizen/KoinModule.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package fr.dcproject.component.citizen
|
||||
|
||||
import org.koin.dsl.module
|
||||
|
||||
val citizenKoinModule = module {
|
||||
single { CitizenRepository(get()) }
|
||||
single { CitizenAccessControl() }
|
||||
}
|
||||
14
src/main/kotlin/component/comment/KoinModule.kt
Normal file
14
src/main/kotlin/component/comment/KoinModule.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
package fr.dcproject.component.comment
|
||||
|
||||
import fr.dcproject.component.comment.article.CommentArticleRepository
|
||||
import fr.dcproject.component.comment.constitution.CommentConstitutionRepository
|
||||
import fr.dcproject.component.comment.generic.CommentAccessControl
|
||||
import fr.dcproject.component.comment.generic.CommentRepository
|
||||
import org.koin.dsl.module
|
||||
|
||||
val commentKoinModule = module {
|
||||
single { CommentRepository(get()) }
|
||||
single { CommentArticleRepository(get()) }
|
||||
single { CommentConstitutionRepository(get()) }
|
||||
single { CommentAccessControl() }
|
||||
}
|
||||
8
src/main/kotlin/component/constitution/KoinModule.kt
Normal file
8
src/main/kotlin/component/constitution/KoinModule.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package fr.dcproject.component.constitution
|
||||
|
||||
import org.koin.dsl.module
|
||||
|
||||
val constitutionKoinModule = module {
|
||||
single { ConstitutionRepository(get()) }
|
||||
single { ConstitutionAccessControl() }
|
||||
}
|
||||
9
src/main/kotlin/component/follow/KoinModule.kt
Normal file
9
src/main/kotlin/component/follow/KoinModule.kt
Normal file
@@ -0,0 +1,9 @@
|
||||
package fr.dcproject.component.follow
|
||||
|
||||
import org.koin.dsl.module
|
||||
|
||||
val followKoinModule = module {
|
||||
single { FollowArticleRepository(get()) }
|
||||
single { FollowConstitutionRepository(get()) }
|
||||
single { FollowAccessControl() }
|
||||
}
|
||||
11
src/main/kotlin/component/opinion/KoinModule.kt
Normal file
11
src/main/kotlin/component/opinion/KoinModule.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package fr.dcproject.component.opinion
|
||||
|
||||
import org.koin.dsl.module
|
||||
|
||||
val opinionKoinModule = module {
|
||||
single { OpinionChoiceRepository(get()) }
|
||||
single { OpinionRepositoryArticle(get()) }
|
||||
|
||||
single { OpinionAccessControl() }
|
||||
single { OpinionChoiceAccessControl() }
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package fr.dcproject.component.views
|
||||
|
||||
import org.elasticsearch.client.Request
|
||||
import org.elasticsearch.client.RestClient
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
object ConfigViews {
|
||||
private fun waitElasticsearchIsUp(client: RestClient) {
|
||||
val logger: Logger = LoggerFactory.getLogger("fr.dcproject.elasticsearch")
|
||||
val request = Request("GET", "/_cluster/health")
|
||||
repeat(5 * 60 / 2) { // 5 minutes
|
||||
runCatching {
|
||||
client.performRequest(request).statusLine.statusCode
|
||||
}.onSuccess {
|
||||
if (it == 200) {
|
||||
logger.debug("Elasticsearch is Ready! Continue...")
|
||||
return
|
||||
} else {
|
||||
logger.debug("sleep 2s and retry...")
|
||||
Thread.sleep(2000)
|
||||
}
|
||||
}.onFailure {
|
||||
logger.debug("${it.message}, sleep 2s and retry...")
|
||||
Thread.sleep(2000)
|
||||
}
|
||||
}
|
||||
error("Elasticsearch is not ready")
|
||||
}
|
||||
|
||||
fun createEsIndexForViews(client: RestClient) {
|
||||
waitElasticsearchIsUp(client)
|
||||
|
||||
/* Create index if not exist */
|
||||
client.run {
|
||||
if (performRequest(Request("HEAD", "/views?include_type_name=false")).statusLine.statusCode == 404) {
|
||||
Request(
|
||||
"PUT",
|
||||
"/views?include_type_name=false"
|
||||
).apply {
|
||||
//language=JSON
|
||||
setJsonEntity(
|
||||
"""
|
||||
{
|
||||
"settings": {
|
||||
"number_of_shards": 5
|
||||
},
|
||||
"mappings": {
|
||||
"properties": {
|
||||
"logged": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"type": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"user_ref": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"id": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"version_id": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"ip": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"citizen_id": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"view_at": {
|
||||
"type": "date"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}.let {
|
||||
performRequest(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/main/kotlin/component/views/KoinModule.kt
Normal file
19
src/main/kotlin/component/views/KoinModule.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package fr.dcproject.component.views
|
||||
|
||||
import fr.dcproject.application.Configuration
|
||||
import fr.dcproject.component.article.ArticleForView
|
||||
import fr.dcproject.component.article.ArticleViewManager
|
||||
import org.apache.http.HttpHost
|
||||
import org.elasticsearch.client.RestClient
|
||||
import org.koin.dsl.module
|
||||
|
||||
val viewKoinModule = module {
|
||||
// Elasticsearch Client
|
||||
val esClient = RestClient.builder(
|
||||
HttpHost.create(Configuration.elasticsearch)
|
||||
).build().apply {
|
||||
createEsIndexForViews()
|
||||
}
|
||||
|
||||
single { ArticleViewManager<ArticleForView>(esClient) }
|
||||
}
|
||||
58
src/main/kotlin/component/views/createEsIndexForViews.kt
Normal file
58
src/main/kotlin/component/views/createEsIndexForViews.kt
Normal file
@@ -0,0 +1,58 @@
|
||||
package fr.dcproject.component.views
|
||||
|
||||
import fr.dcproject.utils.waitElasticsearchIsUp
|
||||
import org.elasticsearch.client.Request
|
||||
import org.elasticsearch.client.RestClient
|
||||
|
||||
fun RestClient.createEsIndexForViews() {
|
||||
waitElasticsearchIsUp()
|
||||
|
||||
/* Create index if not exist */
|
||||
if (performRequest(Request("HEAD", "/views?include_type_name=false")).statusLine.statusCode == 404) {
|
||||
Request(
|
||||
"PUT",
|
||||
"/views?include_type_name=false"
|
||||
).apply {
|
||||
//language=JSON
|
||||
setJsonEntity(
|
||||
"""
|
||||
{
|
||||
"settings": {
|
||||
"number_of_shards": 5
|
||||
},
|
||||
"mappings": {
|
||||
"properties": {
|
||||
"logged": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"type": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"user_ref": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"id": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"version_id": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"ip": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"citizen_id": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"view_at": {
|
||||
"type": "date"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}.let {
|
||||
performRequest(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/main/kotlin/component/vote/KoinModule.kt
Normal file
12
src/main/kotlin/component/vote/KoinModule.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package fr.dcproject.component.vote
|
||||
|
||||
import org.koin.dsl.module
|
||||
|
||||
val voteKoinModule = module {
|
||||
single { VoteRepository(get()) }
|
||||
single { VoteArticleRepository(get()) }
|
||||
single { VoteConstitutionRepository(get()) }
|
||||
single { VoteCommentRepository(get()) }
|
||||
|
||||
single { VoteAccessControl() }
|
||||
}
|
||||
8
src/main/kotlin/component/workgroup/KoinModule.kt
Normal file
8
src/main/kotlin/component/workgroup/KoinModule.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package fr.dcproject.component.workgroup
|
||||
|
||||
import org.koin.dsl.module
|
||||
|
||||
val workgroupKoinModule = module {
|
||||
single { WorkgroupRepository(get()) }
|
||||
single { WorkgroupAccessControl() }
|
||||
}
|
||||
Reference in New Issue
Block a user