add expense and up kotlin
This commit is contained in:
parent
470893165a
commit
0de3eb7142
@ -1,8 +1,8 @@
|
|||||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.9.23"
|
kotlin("jvm") version "2.0.0"
|
||||||
kotlin("kapt") version "1.9.23"
|
kotlin("kapt") version "2.0.0"
|
||||||
id("idea")
|
id("idea")
|
||||||
id("io.ebean") version "13.23.2"
|
id("io.ebean") version "13.23.2"
|
||||||
id("com.github.johnrengelman.shadow") version "8.1.1"
|
id("com.github.johnrengelman.shadow") version "8.1.1"
|
||||||
@ -33,8 +33,6 @@ dependencies {
|
|||||||
implementation("ch.qos.logback:logback-classic:1.4.12")
|
implementation("ch.qos.logback:logback-classic:1.4.12")
|
||||||
implementation("org.bitbucket.b_c:jose4j:0.9.4")
|
implementation("org.bitbucket.b_c:jose4j:0.9.4")
|
||||||
implementation("redis.clients:jedis:5.0.2")
|
implementation("redis.clients:jedis:5.0.2")
|
||||||
implementation("org.jetbrains.kotlin:kotlin-scripting-jsr223:1.9.23")
|
|
||||||
implementation("org.jetbrains.kotlin:kotlin-script-runtime:1.9.23")
|
|
||||||
implementation("org.bouncycastle:bcprov-jdk18on:1.76")
|
implementation("org.bouncycastle:bcprov-jdk18on:1.76")
|
||||||
implementation("org.bouncycastle:bcpkix-jdk18on:1.76")
|
implementation("org.bouncycastle:bcpkix-jdk18on:1.76")
|
||||||
implementation("org.yaml:snakeyaml:2.2")
|
implementation("org.yaml:snakeyaml:2.2")
|
||||||
|
|||||||
@ -37,7 +37,7 @@ fun main(args: Array<String>) {
|
|||||||
val viewRole = Role.Standard(Action.VIEW)
|
val viewRole = Role.Standard(Action.VIEW)
|
||||||
val createRole = Role.Standard(Action.CREATE)
|
val createRole = Role.Standard(Action.CREATE)
|
||||||
val updateRole = Role.Standard(Action.UPDATE)
|
val updateRole = Role.Standard(Action.UPDATE)
|
||||||
val approveOrRejectRole = Role.Standard(Action.APPROVE)
|
val appAdmin = Role.Explicit("ROLE_ADMIN")
|
||||||
|
|
||||||
//todo, create roles in keycloak based on entity and actions
|
//todo, create roles in keycloak based on entity and actions
|
||||||
|
|
||||||
@ -301,14 +301,15 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/{entity}/{id}", Entities::view, Roles(adminRole, viewRole))
|
post("/{entity}/next", Entities::getNextSeqNo, Roles(adminRole, viewRole, appAdmin))
|
||||||
post("/{entity}/search", Entities::search, Roles(adminRole, viewRole))
|
get("/{entity}/{id}", Entities::view, Roles(adminRole, viewRole, appAdmin))
|
||||||
post("/{entity}", Entities::create, Roles(adminRole, createRole))
|
post("/{entity}/search", Entities::search, Roles(adminRole, viewRole, appAdmin))
|
||||||
|
post("/{entity}", Entities::create, Roles(adminRole, createRole, appAdmin))
|
||||||
|
|
||||||
|
|
||||||
put("/{entity}/{id}", Entities::update, Roles(adminRole, updateRole))
|
put("/{entity}/{id}", Entities::update, Roles(adminRole, updateRole, appAdmin))
|
||||||
patch("/{entity}/{id}", Entities::patch, Roles(adminRole, updateRole))
|
patch("/{entity}/{id}", Entities::patch, Roles(adminRole, updateRole, appAdmin))
|
||||||
delete("/{entity}/{id}", Entities::delete, Roles(adminRole, Role.Standard(Action.DELETE)))
|
delete("/{entity}/{id}", Entities::delete, Roles(adminRole, Role.Standard(Action.DELETE), appAdmin))
|
||||||
}
|
}
|
||||||
}.exception(DuplicateKeyException::class.java, Exceptions.dupKeyExceptionHandler)
|
}.exception(DuplicateKeyException::class.java, Exceptions.dupKeyExceptionHandler)
|
||||||
.exception(DataIntegrityException::class.java, Exceptions.dataIntegrityException)
|
.exception(DataIntegrityException::class.java, Exceptions.dataIntegrityException)
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import com.restapi.domain.Session.findDataModelByEntityAndUniqId
|
|||||||
import com.restapi.integ.Scripting
|
import com.restapi.integ.Scripting
|
||||||
import io.javalin.http.BadRequestResponse
|
import io.javalin.http.BadRequestResponse
|
||||||
import io.javalin.http.Context
|
import io.javalin.http.Context
|
||||||
|
import io.javalin.http.HttpStatus
|
||||||
import io.javalin.http.bodyAsClass
|
import io.javalin.http.bodyAsClass
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
@ -84,6 +85,7 @@ class QueryParamDeSerializer : JsonDeserializer<QueryParam>() {
|
|||||||
|
|
||||||
object Entities {
|
object Entities {
|
||||||
private val logger = LoggerFactory.getLogger("Entities")
|
private val logger = LoggerFactory.getLogger("Entities")
|
||||||
|
private val OK = mapOf("status" to true)
|
||||||
fun delete(ctx: Context) {
|
fun delete(ctx: Context) {
|
||||||
val e = database.findDataModelByEntityAndUniqId(ctx.pathParam("entity"), ctx.pathParam("id"))
|
val e = database.findDataModelByEntityAndUniqId(ctx.pathParam("entity"), ctx.pathParam("id"))
|
||||||
e.deletedBy = Session.currentUser()
|
e.deletedBy = Session.currentUser()
|
||||||
@ -116,6 +118,7 @@ object Entities {
|
|||||||
e.data.putAll(newData)
|
e.data.putAll(newData)
|
||||||
|
|
||||||
e.update()
|
e.update()
|
||||||
|
ctx.json(OK)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun verifyKeys(newData: Map<String, Any>) {
|
private fun verifyKeys(newData: Map<String, Any>) {
|
||||||
@ -152,6 +155,30 @@ object Entities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun getNextSeqNo(ctx: Context) {
|
||||||
|
val entity = ctx.pathParam("entity").uppercase()
|
||||||
|
|
||||||
|
val prefix = "$entity/"
|
||||||
|
val plantId = ctx.queryParam("plantId") ?: throw BadRequestResponse("plantId not sent")
|
||||||
|
val plant = database.find(Plant::class.java)
|
||||||
|
.where()
|
||||||
|
.eq("plantId", plantId)
|
||||||
|
.findOne() ?: throw BadRequestResponse("plant missing for $plantId")
|
||||||
|
|
||||||
|
val inventoryPrefix = plant.prefixes?.get(entity) ?: prefix
|
||||||
|
|
||||||
|
val cnt = (database.find(DataModel::class.java)
|
||||||
|
.where()
|
||||||
|
.eq("entityName", entity.lowercase())
|
||||||
|
.eq("data->>'plantId'", plantId)
|
||||||
|
.findCount() + 1)
|
||||||
|
.toString()
|
||||||
|
.padStart(6, '0')
|
||||||
|
|
||||||
|
val seq = SequenceNumber(inventoryPrefix + cnt)
|
||||||
|
ctx.json(seq).status(HttpStatus.OK)
|
||||||
|
}
|
||||||
|
|
||||||
fun view(it: Context) {
|
fun view(it: Context) {
|
||||||
database.save(
|
database.save(
|
||||||
AuditLog().apply {
|
AuditLog().apply {
|
||||||
@ -264,6 +291,7 @@ object Entities {
|
|||||||
this.data = dataModel.data
|
this.data = dataModel.data
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
ctx.json(OK)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isValidDate(f: String) = try {
|
private fun isValidDate(f: String) = try {
|
||||||
@ -290,7 +318,7 @@ object Entities {
|
|||||||
|
|
||||||
data class SearchParams(
|
data class SearchParams(
|
||||||
val params: Map<String, QueryParam> = mapOf(),
|
val params: Map<String, QueryParam> = mapOf(),
|
||||||
val dateRange: List<LocalDate> = emptyList()
|
val dateRange: List<LocalDate> = listOf(LocalDate.now().minusDays(7), LocalDate.now())
|
||||||
)
|
)
|
||||||
|
|
||||||
data class SequenceNumber(val number: String)
|
data class SequenceNumber(val number: String)
|
||||||
|
|||||||
@ -137,6 +137,11 @@ object Session {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
val objectMapper = jacksonObjectMapper().apply {
|
||||||
|
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
|
configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
|
||||||
|
findAndRegisterModules()
|
||||||
|
}
|
||||||
|
|
||||||
private val sc = DatabaseConfig().apply {
|
private val sc = DatabaseConfig().apply {
|
||||||
loadFromProperties(Properties().apply {
|
loadFromProperties(Properties().apply {
|
||||||
@ -150,13 +155,8 @@ object Session {
|
|||||||
currentUserProvider = CurrentUserProvider { currentUser.get().userName }
|
currentUserProvider = CurrentUserProvider { currentUser.get().userName }
|
||||||
objectMapper = Session.objectMapper
|
objectMapper = Session.objectMapper
|
||||||
}
|
}
|
||||||
|
|
||||||
val database: Database = DatabaseFactory.create(sc)
|
val database: Database = DatabaseFactory.create(sc)
|
||||||
val objectMapper = jacksonObjectMapper().apply {
|
|
||||||
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
|
||||||
configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
|
|
||||||
findAndRegisterModules()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun currentUser() = currentUser.get().userName
|
fun currentUser() = currentUser.get().userName
|
||||||
fun currentTenant() = currentUser.get().tenant
|
fun currentTenant() = currentUser.get().tenant
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user