Commit c0c1db64 authored by npedot's avatar npedot
Browse files

new gid global id, adds gid to database and changset

parent d2388b07
package unibz.cs.semint.kprime.domain
import java.util.*
// https://docs.oracle.com/javase/7/docs/api/java/util/UUID.html#randomUUID()
fun nextGid(): Gid = UUID.randomUUID().toString()
// hexDigit 0-9,a-z,A-Z,'-'
fun Gid.isValidGid(): Boolean {
if (this.isEmpty()) return false
if (this.length < 10) return false
if (!this.matches(Regex("[0-9a-zA-Z\\-]+"))) return false
return true
}
typealias Gid = String
\ No newline at end of file
......@@ -4,7 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import unibz.cs.semint.kprime.domain.Gid
import unibz.cs.semint.kprime.domain.dql.Query
import unibz.cs.semint.kprime.domain.nextGid
import java.util.*
import javax.xml.bind.annotation.XmlElements
import kotlin.collections.ArrayList
......@@ -12,11 +14,14 @@ import kotlin.collections.ArrayList
@JacksonXmlRootElement(localName = "database")
open class Database () {
@JacksonXmlProperty(isAttribute = true)
var gid: Gid? = null
@JacksonXmlProperty(isAttribute = true)
var name: String =""
@JacksonXmlProperty(isAttribute = true)
var id: String=""
var id: String = ""
@JacksonXmlProperty(isAttribute = true)
var author: String? = null
......
......@@ -4,7 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import unibz.cs.semint.kprime.domain.Gid
import unibz.cs.semint.kprime.domain.ddl.Database
import unibz.cs.semint.kprime.domain.nextGid
fun initChangeSet(alfa:ChangeSet.()->Unit):ChangeSet {
val changeSet = ChangeSet()
......@@ -14,6 +16,8 @@ fun initChangeSet(alfa:ChangeSet.()->Unit):ChangeSet {
@JacksonXmlRootElement(localName = "changeSet")
class ChangeSet() {
@JacksonXmlProperty(isAttribute = true)
var gid: Gid? = null
@JacksonXmlProperty(isAttribute = true)
var id: String = ""
......@@ -66,7 +70,7 @@ class ChangeSet() {
@JacksonXmlElementWrapper(useWrapping=false)
var commands : MutableList<String>? = ArrayList()
infix fun withId(id:String) = apply {
infix fun withId(id:Gid) = apply {
this.id=id
}
......
package unibz.cs.semint.kprime.domain
import org.junit.Test
import java.util.*
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class GidTest {
@Test
fun test_gid() {
assertTrue("1234567890".isValidGid())
assertFalse("".isValidGid())
assertFalse("123456789".isValidGid())
// UUID 9c63265d-f068-46d4-83fb-48d10c6ea8d8
assertTrue(UUID.randomUUID().toString().isValidGid())
assertTrue(nextGid().isValidGid())
assertTrue("9c63265d-f068-46d4-83fb-48d10c6ea8d8".isValidGid())
assertFalse("9c63265d-f068-46d4-83fb+48d10c6ea8d8".isValidGid())
assertFalse("9c63265d%f068-46d4-83fb-48d10c6ea8d8".isValidGid())
}
}
\ No newline at end of file
......@@ -27,6 +27,7 @@ class YAMLSerializerDatabaseTest {
objectMapper.writeValue(outWriter,database)
assertEquals("""
---
gid: null
name: "dbname"
id: "iddb"
author: null
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment