more stuff

This commit is contained in:
gowthaman.b
2023-11-11 11:38:58 +05:30
parent 1e3d9aa1f1
commit dc0a59fcf2
11 changed files with 335 additions and 109 deletions

View File

@@ -46,6 +46,7 @@ object Session {
}
fun currentUser() = currentUser.get().userName
fun currentTenant() = currentUser.get().tenant
fun Database.findByEntityAndId(entity: String, id: String): DataModel {
return find(DataModel::class.java)

View File

@@ -16,11 +16,7 @@ import io.ebean.annotation.WhenModified
import io.ebean.annotation.WhoCreated
import io.ebean.annotation.WhoModified
import java.time.LocalDateTime
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.MappedSuperclass
import javax.persistence.Version
import javax.persistence.*
data class Comments(val text: String = "", val by: String = "", val at: LocalDateTime = LocalDateTime.now())
@@ -62,6 +58,95 @@ abstract class BaseModel : Model() {
var comments: MutableList<Comments> = arrayListOf()
}
@Entity
open class TenantModel : BaseModel() {
var name: String = ""
var domain: String = ""
var mobile: List<String> = emptyList()
var emails: List<String> = emptyList()
@DbJsonB
var preferences: MutableMap<String, Any> = hashMapOf()
}
enum class AuditType {
CREATE, UPDATE, DELETE, VIEW
}
open class AuditLog : BaseModel() {
var auditType: AuditType = AuditType.CREATE
var entity: String = ""
var uniqueIdentifier: String = ""
@DbJsonB
@Index(definition = "create index audit_log_values_idx on audit_log using GIN (data) ", platforms = [Platform.POSTGRES])
var data: Map<String, Any> = hashMapOf()
@DbJsonB
@Index(definition = "create index audit_log_changes_idx on audit_log using GIN (changes) ", platforms = [Platform.POSTGRES])
var changes: Map<String, Any> = hashMapOf()
}
@Entity
open class EntityModel : BaseModel() {
@Index(unique = true)
@JsonDeserialize(using = SafeStringDeserializer::class)
var name: String = ""
//a kts script that will return true/false along with errors before saving
var preSaveScript: String = ""
//a kts script that will do something ... returns void
var postSaveScript: String = ""
//this will create extra actions/roles in keycloak
//the default actions are create, update, view, delete
@DbArray
var actions: List<String> = emptyList()
//allow only these fields, if this is empty, then all fields are allowed
@DbArray
var allowedFields: List<String> = emptyList()
//when an entity is saved/updated audit logs will be populated, when this is empty, all fields are logged
@DbArray
var auditLogFields: List<String> = emptyList()
@DbJsonB
var preferences: MutableMap<String, Any> = hashMapOf()
//if '0' then its auto saved, no approval steps are required, for further steps,
//a user needs to have ROLE_ENTITY_APPROVE_LEVEL1, ROLE_ENTITY_APPROVE_LEVEL2 roles
var approvalLevels: Int = 0
}
enum class JobFrequencyType {
SPECIFIC, EVERY, CRON
}
enum class JobType {
SCRIPT, DB
}
@Entity
open class JobModel : BaseModel() {
@Index(unique = true)
var jobName: String = ""
@Enumerated(EnumType.STRING)
var jobType: JobType = JobType.SCRIPT
var jobPath: String = ""
@DbArray
var tenants: List<String> = emptyList()
@Enumerated(EnumType.STRING)
var jobFrequencyType = JobFrequencyType.EVERY
var frequency: String = "1h"
}
@Entity
@Index(unique = true, name = "entity_unique_id", columnNames = ["entity_name", "unique_identifier", "tenant_id"])
open class DataModel : BaseModel() {