Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pedot Nicola
semint-kprime
Commits
c0c1db64
Commit
c0c1db64
authored
May 04, 2021
by
npedot
Browse files
new gid global id, adds gid to database and changset
parent
d2388b07
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/unibz.cs.semint.kprime/domain/Gid.kt
0 → 100644
View file @
c0c1db64
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
src/main/kotlin/unibz.cs.semint.kprime/domain/ddl/Database.kt
View file @
c0c1db64
...
...
@@ -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
...
...
src/main/kotlin/unibz.cs.semint.kprime/domain/dml/ChangeSet.kt
View file @
c0c1db64
...
...
@@ -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
}
...
...
src/test/kotlin/unibz.cs.semint.kprime/domain/GidTest.kt
0 → 100644
View file @
c0c1db64
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
src/test/kotlin/unibz.cs.semint.kprime/usecase/serialize/YAMLSerializerDatabaseTest.kt
View file @
c0c1db64
...
...
@@ -27,6 +27,7 @@ class YAMLSerializerDatabaseTest {
objectMapper
.
writeValue
(
outWriter
,
database
)
assertEquals
(
"""
---
gid: null
name: "dbname"
id: "iddb"
author: null
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment