#15 Count total view

Create Viewable interface
Set Article as Viewable
Create ES client
Now view article increment view count
Create index on start application

add an extention in ApplicationCall, to get citizen or return null
This commit is contained in:
2020-03-11 12:55:39 +01:00
parent f677cac779
commit 90e7e0254d
17 changed files with 325 additions and 13 deletions

View File

@@ -0,0 +1,29 @@
package fr.dcproject.utils
import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.PathNotFoundException
import org.apache.http.util.EntityUtils
import org.elasticsearch.client.Response
import org.slf4j.LoggerFactory
fun Response.contentToString(): String {
return EntityUtils.toString(this.entity)
}
fun Response.getField(jsonPath: String): Int? {
return try {
JsonPath.read(this.contentToString(), jsonPath)
} catch (e: PathNotFoundException) {
null
}
}
fun String.getJsonField(jsonPath: String): Int? {
return try {
JsonPath.read(this, jsonPath)
} catch (e: PathNotFoundException) {
LoggerFactory.getLogger("fr.dcproject.utils.getJsonField")
.warn("No value for Json path ${JsonPath.compile(jsonPath).path}")
null
}
}