Client code examples

Applicable to all following examples

val clientService = ClientService()

Setup master key (initial run)

val masterKey = "123456".toByteArray()

clientService.createMasterKey(masterKey)

Session setup

val masterKey = "123456".toByteArray()

clientService.unlockWithMasterKey(masterKey)
clientService.setupSessionService()

Create a session

val newSession = clientService.sessionService.createSession("sess01")

clientService.sessionService.selectSession(newSession.sessionId)

clientService.setup()

Create EDV

val providerUrl = "http://localhost:7000"

val result = clientService.edvService.createEdv(providerUrl)

println("Created EDV ${res.edvId} at $providerUrl")

Create document

clientService.documentService.create("documentId123", "the content".toByteArray())

Update document

clientService.documentService.update("documentId123", "new content".toByteArray())

Load document

val result = clientService.documentService.load(edvId, documentId).toString()  // or .toBytes()

Delete document

clientService.documentService.delete("documentId123")

Search document

val results = clientService.documentService.search(edvId, "keyword")
results.forEach { println(it) }

Get all documents in EDV

val results = clientService.indexService.getDocuments(edvId)
results.forEach { println(it) }

Retrieve tree of EDV

val results = clientService.indexService.getTree()
results.forEach { println(it) }

Enable notification channel

clientService.edvService.notificationsConnect(edvId) { event ->
    println("Received notification from EDV $edvId: " +
    "Document ${event.documentId} was ${event.operation.name}" +
    " by ${event.invoker}.")
}

Diconnect notification channels

clientService.edvService.notificationsDisconnect()

Export session

val jwe = sessionService.export(sessionService.sessionId)
println("Session export (it's encrypted with the masterkey): $jwe")

Last updated