Move all file in fr.dcproject.

This commit is contained in:
2021-02-11 01:37:29 +01:00
parent c85401aa86
commit 066b01e86f
148 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
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 {
single {
val config: Configuration = get()
// Elasticsearch Client
val esClient = RestClient.builder(
HttpHost.create(config.elasticsearch)
).build().apply {
createEsIndexForViews()
}
ArticleViewManager<ArticleForView>(esClient)
}
}

View File

@@ -0,0 +1,18 @@
package fr.dcproject.component.views
import fr.dcproject.component.citizen.CitizenI
import fr.dcproject.component.views.entity.ViewAggregation
import org.elasticsearch.client.Response
import org.joda.time.DateTime
interface ViewManager <T> {
/**
* Add view to one entity
*/
fun addView(ip: String, entity: T, citizen: CitizenI? = null, dateTime: DateTime = DateTime.now()): Response?
/**
* Get Views aggregations
*/
fun getViewsCount(entity: T): ViewAggregation
}

View File

@@ -0,0 +1,58 @@
package fr.dcproject.component.views
import fr.dcproject.common.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)
}
}
}

View File

@@ -0,0 +1,10 @@
package fr.dcproject.component.views.dto
import fr.dcproject.component.views.entity.ViewAggregation
class ViewAggregation(
val total: Int,
val unique: Int
) {
constructor(views: ViewAggregation) : this(views.total, views.unique)
}

View File

@@ -0,0 +1,9 @@
package fr.dcproject.component.views.dto
interface Viewable {
var views: ViewAggregation
class Imp(views: fr.dcproject.component.views.entity.ViewAggregation) : Viewable {
override var views: ViewAggregation = ViewAggregation(views.total, views.unique)
}
}

View File

@@ -0,0 +1,13 @@
package fr.dcproject.component.views.entity
import fr.postgresjson.entity.EntityI
import fr.postgresjson.entity.EntityUpdatedAt
import fr.postgresjson.entity.EntityUpdatedAtImp
class ViewAggregation(
val total: Int,
val unique: Int
) : EntityI,
EntityUpdatedAt by EntityUpdatedAtImp() {
constructor() : this(0, 0)
}