From 300bff1db9ceb6e41026caeaec166ef9cb8f9718 Mon Sep 17 00:00:00 2001 From: Abel Hegedus Date: Mon, 25 Nov 2019 17:15:46 +0100 Subject: [PATCH] move files to renamed directory --- README.md | 8 +- .../build.gradle | 4 +- .../settings.gradle | 2 +- .../vhci/modelaccess/twc/rest => }/Crawler.kt | 38 +- .../vhci/modelaccess/twc/rest/data/Data.kt | 76 --- .../twc/rest/verticles/MainVerticle.kt | 349 ------------- .../src/main/kotlin/data/Data.kt | 74 +++ .../src/main/kotlin/verticles/MainVerticle.kt | 481 ++++++++++++++++++ .../twc/rest => }/verticles/RESTVerticle.kt | 243 +++++---- 9 files changed, 741 insertions(+), 534 deletions(-) rename com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/{com/incquerylabs/vhci/modelaccess/twc/rest => }/Crawler.kt (91%) delete mode 100644 com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/data/Data.kt delete mode 100644 com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/verticles/MainVerticle.kt create mode 100644 com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/data/Data.kt create mode 100644 com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/verticles/MainVerticle.kt rename com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/{com/incquerylabs/vhci/modelaccess/twc/rest => }/verticles/RESTVerticle.kt (68%) diff --git a/README.md b/README.md index 882e01f..929504e 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ ## Run the crawler -1. Download `vhci.modelaccess.twc.rest--all.jar` from [GitHub releases](https://github.com/IncQueryLabs/repo-crawler/releases) -1. `java -jar vhci.modelaccess.twc.rest--all.jar ` with arguments (see below) +1. Download `twc.repo-crawler--all.jar` from [GitHub releases](https://github.com/IncQueryLabs/repo-crawler/releases) +1. `java -jar twc.repo-crawler--all.jar ` with arguments (see below) ## Example arguments @@ -26,7 +26,7 @@ Running the jar without arguments prints out the usage instructions. 1. Install `IntelliJ IDEA` with kotlin plugin. 1. Open IntelliJ IDEA and open project. `File -> Open.. -> ` (Select `Gradle` if needed.) 1. `Build -> Build Project` -1. `Run -> Run... -> com.incquerylabs.vhci.modelaccess.twc.rest.Crawler.kt` (set arguments in Configuration) +1. `Run -> Run... -> com.incquerylabs.twc.repo.crawler.Crawler.kt` (set arguments in Configuration) ### Gradle @@ -35,4 +35,4 @@ Running the jar without arguments prints out the usage instructions. ### Shadow Jar 1. `./gradlew shadowJar` -1. `java -jar build/libs/vhci.modelaccess.twc.rest--all.jar ` with arguments (see above) +1. `java -jar build/libs/twc.repo-crawler--all.jar ` with arguments (see above) diff --git a/com.incquerylabs.vhci.modelaccess.twc.rest/build.gradle b/com.incquerylabs.vhci.modelaccess.twc.rest/build.gradle index 9803e4c..38818dc 100644 --- a/com.incquerylabs.vhci.modelaccess.twc.rest/build.gradle +++ b/com.incquerylabs.vhci.modelaccess.twc.rest/build.gradle @@ -24,11 +24,11 @@ compileTestKotlin { } application { - mainClassName = 'com.incquerylabs.vhci.modelaccess.twc.rest.CrawlerKt' + mainClassName = 'com.incquerylabs.twc.repo.crawler.CrawlerKt' } vertx { - launcher = 'com.incquerylabs.vhci.modelaccess.twc.rest.CrawlerKt' + launcher = 'com.incquerylabs.twc.repo.crawler.CrawlerKt' } wrapper { diff --git a/com.incquerylabs.vhci.modelaccess.twc.rest/settings.gradle b/com.incquerylabs.vhci.modelaccess.twc.rest/settings.gradle index 1378425..f254c6f 100644 --- a/com.incquerylabs.vhci.modelaccess.twc.rest/settings.gradle +++ b/com.incquerylabs.vhci.modelaccess.twc.rest/settings.gradle @@ -1,2 +1,2 @@ -rootProject.name = 'vhci.modelaccess.twc.rest' +rootProject.name = 'twc.repo-crawler' diff --git a/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/Crawler.kt b/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/Crawler.kt similarity index 91% rename from com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/Crawler.kt rename to com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/Crawler.kt index 5798258..e78a0a1 100644 --- a/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/Crawler.kt +++ b/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/Crawler.kt @@ -1,15 +1,14 @@ -package com.incquerylabs.vhci.modelaccess.twc.rest +package com.incquerylabs.twc.repo.crawler -import com.incquerylabs.vhci.modelaccess.twc.rest.data.* -import io.vertx.core.Vertx -import io.vertx.core.json.Json -import io.vertx.core.json.JsonObject -import com.incquerylabs.vhci.modelaccess.twc.rest.verticles.MainVerticle -import com.incquerylabs.vhci.modelaccess.twc.rest.verticles.RESTVerticle +import com.incquerylabs.twc.repo.crawler.data.* +import com.incquerylabs.twc.repo.crawler.verticles.MainVerticle +import com.incquerylabs.twc.repo.crawler.verticles.RESTVerticle import io.vertx.core.DeploymentOptions -import io.vertx.core.cli.Argument +import io.vertx.core.Vertx import io.vertx.core.cli.CLI import io.vertx.core.cli.Option +import io.vertx.core.json.Json +import io.vertx.core.json.JsonObject import java.io.File @@ -137,19 +136,19 @@ fun main(args: Array) { } if (workspaceId != null) { println("Workspace ID set to $workspaceId") - twcMap[DataConstants.WORKSPACE_ID] = workspaceId + twcMap[WORKSPACE_ID] = workspaceId } if (resourceId != null) { println("Resource ID set to $resourceId") - twcMap[DataConstants.RESOURCE_ID] = resourceId + twcMap[RESOURCE_ID] = resourceId } if (branchId != null) { println("Branch ID set to $branchId") - twcMap[DataConstants.BRANCH_ID] = branchId + twcMap[BRANCH_ID] = branchId } if (revision != null) { println("Revision set to $revision") - twcMap[DataConstants.REVISION] = revision.toInt() + twcMap[REVISION] = revision.toInt() } @@ -158,7 +157,13 @@ fun main(args: Array) { File("server.config").createNewFile() } - File("server.config").writeText(Json.encode(Server(serverOpt, portOpt.toInt(), isSslEnabled))) + File("server.config").writeText(Json.encode( + Server( + serverOpt, + portOpt.toInt(), + isSslEnabled + ) + )) twcMap["server_path"] = serverOpt twcMap["server_port"] = portOpt.toInt() twcMap["server_ssl"] = isSslEnabled @@ -207,7 +212,12 @@ fun main(args: Array) { "Basic ${java.util.Base64.getEncoder().encodeToString("${usr}:${pswd}".toByteArray())}" twcMap["username"] = usr - vertx.deployVerticle(MainVerticle(usr, pswd)) { deploy -> + vertx.deployVerticle( + MainVerticle( + usr, + pswd + ) + ) { deploy -> if (deploy.failed()) { error("Deploy failed: ${deploy.cause().message}\n${deploy.cause().printStackTrace()}") } diff --git a/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/data/Data.kt b/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/data/Data.kt deleted file mode 100644 index 42d0f38..0000000 --- a/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/data/Data.kt +++ /dev/null @@ -1,76 +0,0 @@ -package com.incquerylabs.vhci.modelaccess.twc.rest.data - -data class Message(val event: String = "", val obj: Any = "") -data class User(val username: String, val password: String) -data class Server(val path: String, val port: Int, val ssl: Boolean) -data class Repo(val id: String = "", val workspaces: List = emptyList()) -data class Workspace(val id: String = "", val resources: List = emptyList()) -data class Resource(val id: String = "", val workspace_id: String = "", val branches: List = emptyList()) -data class Branch( - val id: String = "", - val resource_id: String = "", - val workspace_id: String = "", - val revisions: List = emptyList() -) - -data class Revision( - val id: Int = -1, - val branch_id: String = "", - val resource_id: String = "", - val workspace_id: String = "", - val elements: List = emptyList() -) - -data class Element( - val id: String = "", - val revision_id: Int = -1, - val branch_id: String = "", - val resource_id: String = "", - val workspace_id: String = "", - val elements: List = emptyList() -) - -data class Elements( - val revision_id: Int = -1, - val branch_id: String = "", - val resource_id: String = "", - val workspace_id: String = "", - val elements: List = emptyList() -) - -object DataConstants { - const val REPO = "repo" - const val WORKSPACE = "workspace" - const val WORKSPACE_ID = "workspace_id" - const val RESOURCE = "resource" - const val RESOURCE_ID = "resource_id" - const val BRANCH = "branch" - const val BRANCH_ID = "branch_id" - const val REVISION = "revision" - const val REVISION_ID = "revision_id" - const val ELEMENTS = "elements" - const val ELEMENT_IDS = "element_ids" - const val ELEMENT = "element" - const val ELEMENT_ID = "element_id" - - const val GET_WORKSPACES = "getWorkspaces" - const val GET_RESOURCES = "getResources" - const val GET_BRANCHES = "getBranches" - const val GET_REVISIONS = "getRevisions" - const val GET_ROOT_ELEMENT_IDS = "getRootElementIds" - const val GET_ELEMENT = "getElement" - const val GET_ELEMENTS = "getElements" - - const val TWCMAP = "twcMap" - const val TWCVERT_ADDRESS = "twc.rest.twcvert" - const val TWCMAIN_ADDRESS = "twc.rest.main" - const val QUERIES = "queries" - const val EXIT = "exit" - const val ERROR = "error" - const val LOGIN = "login" - const val LOGGED_IN = "logged_in" - const val LOGOUT = "logout" - - const val USER = "user_cookie" - const val SESSION = "session_cookie" -} diff --git a/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/verticles/MainVerticle.kt b/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/verticles/MainVerticle.kt deleted file mode 100644 index 6a12e13..0000000 --- a/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/verticles/MainVerticle.kt +++ /dev/null @@ -1,349 +0,0 @@ -package com.incquerylabs.vhci.modelaccess.twc.rest.verticles - -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Branch -import com.incquerylabs.vhci.modelaccess.twc.rest.data.DataConstants -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Element -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Elements -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Message -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Repo -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Resource -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Revision -import com.incquerylabs.vhci.modelaccess.twc.rest.data.User -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Workspace -import io.vertx.core.AbstractVerticle -import io.vertx.core.json.JsonObject - -class MainVerticle(val usr: String, val pswd: String) : AbstractVerticle() { - var sum = 0 - var number = 0 - var s = 0 - var queries = 0 - - override fun start() { - val twcMap = vertx.sharedData().getLocalMap(DataConstants.TWCMAP) - val requestSingleElements = twcMap["requestSingleElement"] as Boolean - - val eb = vertx.eventBus() - vertx.setPeriodic(1000) { - vertx.sharedData().getCounter(DataConstants.QUERIES) { res -> - if (res.succeeded()) { - val counter = res.result() - counter.get { res -> - queries = res.result().toInt() - - vertx.sharedData().getCounter("sum") { res -> - if (res.succeeded()) { - val counter = res.result() - counter.get { get -> - if (get.succeeded()) { - sum = get.result().toInt() - - vertx.sharedData().getCounter("number") { res -> - if (res.succeeded()) { - val counter = res.result() - counter.get { get -> - if (get.succeeded()) { - number = get.result().toInt() - println("Total: ${queries}/${sum}/${++s} query/response/sec | Now: $number elem | AvgSpeed: ${sum / (s)} elem/sec") - counter.compareAndSet(number.toLong(), 0, {}) - - if (queries != 0 && sum != 0 && queries == sum) { - eb.send( - DataConstants.TWCVERT_ADDRESS, - JsonObject.mapFrom( - Message( - DataConstants.LOGOUT, - JsonObject() - ) - ) - ) - } - } - } - } else { - error("Counter: queries not available.") - } - } - } - } - } else { - error("Counter: queries not available.") - } - } - - - } - } else { - // Something went wrong! - } - } - - } - eb.send(DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom(Message(DataConstants.LOGIN, User("$usr", "$pswd")))) - eb.consumer(DataConstants.TWCMAIN_ADDRESS) { message -> - - val messageData = (message.body() as JsonObject).mapTo(Message::class.java) - - when (messageData.event) { - DataConstants.LOGGED_IN -> { - println("Login complete (user: ${twcMap[DataConstants.USER]}, session: ${twcMap[DataConstants.SESSION]})") - - val workspaceId = twcMap[DataConstants.WORKSPACE_ID] - val resourceId = twcMap[DataConstants.RESOURCE_ID] - val branchId = twcMap[DataConstants.BRANCH_ID] - val revision = twcMap[DataConstants.REVISION] - when { - workspaceId == null -> eb.send( - DataConstants.TWCVERT_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.GET_WORKSPACES, JsonObject())) - ) - resourceId == null -> eb.send( - DataConstants.TWCVERT_ADDRESS, - JsonObject.mapFrom( - Message( - DataConstants.GET_RESOURCES, - JsonObject().put(DataConstants.WORKSPACE_ID, workspaceId) - ) - ) - ) - branchId == null -> eb.send( - DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom( - Message( - DataConstants.GET_BRANCHES, - JsonObject() - .put(DataConstants.WORKSPACE_ID, workspaceId) - .put(DataConstants.RESOURCE_ID, resourceId) - ) - ) - ) - revision == null -> eb.send( - DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom( - Message( - DataConstants.GET_REVISIONS, - JsonObject() - .put(DataConstants.WORKSPACE_ID, workspaceId) - .put(DataConstants.RESOURCE_ID, resourceId) - .put(DataConstants.BRANCH_ID, branchId) - ) - ) - ) - else -> vertx.eventBus().send( - DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom( - Message( - DataConstants.GET_ROOT_ELEMENT_IDS, - JsonObject() - .put(DataConstants.WORKSPACE_ID, workspaceId) - .put(DataConstants.RESOURCE_ID, resourceId) - .put(DataConstants.BRANCH_ID, branchId) - .put(DataConstants.REVISION_ID, revision) - ) - ) - ) - } - - } - DataConstants.REPO -> { - // println("Received Repository") - val repo = JsonObject(messageData.obj as Map).mapTo(Repo::class.java) - repo.workspaces.forEach { ws -> - val id = JsonObject(ws as Map).getString("@id") - eb.send( - DataConstants.TWCVERT_ADDRESS, - JsonObject.mapFrom( - Message( - DataConstants.GET_RESOURCES, - JsonObject().put(DataConstants.WORKSPACE_ID, id) - ) - ) - ) - } - } - DataConstants.WORKSPACE -> { - // println("Received Workspace") - val workspace = JsonObject(messageData.obj as Map).mapTo(Workspace::class.java) - val workspaceId = workspace.id - - workspace.resources.forEach { res -> - val resourceId = JsonObject(res as Map).getString("@id") - eb.send( - DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom( - Message( - DataConstants.GET_BRANCHES, - JsonObject() - .put(DataConstants.WORKSPACE_ID, workspaceId) - .put(DataConstants.RESOURCE_ID, resourceId) - ) - ) - ) - } - } - DataConstants.RESOURCE -> { - // println("Received Resource") - val resource = JsonObject(messageData.obj as Map).mapTo(Resource::class.java) - val resourceId = resource.id - val workspaceId = resource.workspace_id - resource.branches.forEach { branch -> - val branchId = JsonObject(branch as Map).getString("@id") - eb.send( - DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom( - Message( - DataConstants.GET_REVISIONS, - JsonObject() - .put(DataConstants.WORKSPACE_ID, workspaceId) - .put(DataConstants.RESOURCE_ID, resourceId) - .put(DataConstants.BRANCH_ID, branchId) - ) - ) - ) - } - - } - DataConstants.BRANCH -> { - // println("Received Branch") - val branch = JsonObject(messageData.obj as Map).mapTo(Branch::class.java) - val branchId = branch.id - val resourceId = branch.resource_id - val workspaceId = branch.workspace_id - val inputRevision = twcMap[DataConstants.REVISION] - if (inputRevision == null) { - twcMap[DataConstants.REVISION] = branch.revisions.maxBy { it as Int } - } - - branch.revisions.forEach { rev -> - val revId = (rev as Int) - vertx.eventBus().send( - DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom( - Message( - DataConstants.GET_ROOT_ELEMENT_IDS, - JsonObject() - .put(DataConstants.WORKSPACE_ID, workspaceId) - .put(DataConstants.RESOURCE_ID, resourceId) - .put(DataConstants.BRANCH_ID, branchId) - .put(DataConstants.REVISION_ID, revId) - ) - ) - ) - } - - } - DataConstants.REVISION -> { - // println("Received Revision") - val revision = JsonObject(messageData.obj as Map).mapTo(Revision::class.java) - val revisionId = revision.id - val branchId = revision.branch_id - val resourceId = revision.resource_id - val workspaceId = revision.workspace_id - val inputRevision = twcMap[DataConstants.REVISION] - if (revisionId == inputRevision) { - if (requestSingleElements) { - revision.elements.forEach { element -> - val elemId = element as String - vertx.eventBus().send( - DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom( - Message( - DataConstants.GET_ELEMENT, - JsonObject() - .put(DataConstants.WORKSPACE_ID, workspaceId) - .put(DataConstants.RESOURCE_ID, resourceId) - .put(DataConstants.BRANCH_ID, branchId) - .put(DataConstants.REVISION_ID, revisionId) - .put(DataConstants.ELEMENT_ID, elemId) - ) - ) - ) - } - } else { - val elementIds = revision.elements - vertx.eventBus().send( - DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom( - Message( - DataConstants.GET_ELEMENTS, - JsonObject() - .put(DataConstants.WORKSPACE_ID, workspaceId) - .put(DataConstants.RESOURCE_ID, resourceId) - .put(DataConstants.BRANCH_ID, branchId) - .put(DataConstants.REVISION_ID, revisionId) - .put(DataConstants.ELEMENT_IDS, elementIds) - ) - ) - ) - } - } - - } - DataConstants.ELEMENT -> { - // println("Received Element") - val element = JsonObject(messageData.obj as Map).mapTo(Element::class.java) - val revisionId = element.revision_id - val branchId = element.branch_id - val resourceId = element.resource_id - val workspaceId = element.workspace_id - element.elements.forEach { element -> - val elementId = JsonObject(element as Map).getString("@id") - - vertx.eventBus().send( - DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom( - Message( - DataConstants.GET_ELEMENT, - JsonObject() - .put(DataConstants.WORKSPACE_ID, workspaceId) - .put(DataConstants.RESOURCE_ID, resourceId) - .put(DataConstants.BRANCH_ID, branchId) - .put(DataConstants.REVISION_ID, revisionId) - .put(DataConstants.ELEMENT_ID, elementId) - ) - ) - ) - } - } - DataConstants.ELEMENTS -> { - // println("Received Elements") - val elements = JsonObject(messageData.obj as Map).mapTo(Elements::class.java) - val revisionId = elements.revision_id - val branchId = elements.branch_id - val resourceId = elements.resource_id - val workspaceId = elements.workspace_id - val elementIds = elements.elements.map { element -> - JsonObject.mapFrom(element).getString("@id") - } - vertx.eventBus().send( - DataConstants.TWCVERT_ADDRESS, JsonObject.mapFrom( - Message( - DataConstants.GET_ELEMENTS, - JsonObject() - .put(DataConstants.WORKSPACE_ID, workspaceId) - .put(DataConstants.RESOURCE_ID, resourceId) - .put(DataConstants.BRANCH_ID, branchId) - .put(DataConstants.REVISION_ID, revisionId) - .put(DataConstants.ELEMENT_IDS, elementIds) - ) - ) - ) - } - DataConstants.ERROR -> { - println("\nExit") - if (twcMap["cookies"] != null) { - eb.send( - DataConstants.TWCVERT_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.LOGOUT, JsonObject())) - ) - } - vertx.close() - } - DataConstants.EXIT -> { - println("\nExit") - if (twcMap["cookies"] != null) { - eb.send( - DataConstants.TWCVERT_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.LOGOUT, JsonObject())) - ) - } - vertx.close() - } - - else -> error("Unknown Command: ${messageData.event}") - } - - } - } -} \ No newline at end of file diff --git a/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/data/Data.kt b/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/data/Data.kt new file mode 100644 index 0000000..171a8c3 --- /dev/null +++ b/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/data/Data.kt @@ -0,0 +1,74 @@ +package com.incquerylabs.twc.repo.crawler.data + +data class Message(val event: String = "", val obj: Any = "") +data class User(val username: String, val password: String) +data class Server(val path: String, val port: Int, val ssl: Boolean) +data class Repo(val id: String = "", val workspaces: List = emptyList()) +data class Workspace(val id: String = "", val resources: List = emptyList()) +data class Resource(val id: String = "", val workspace_id: String = "", val branches: List = emptyList()) +data class Branch( + val id: String = "", + val resource_id: String = "", + val workspace_id: String = "", + val revisions: List = emptyList() +) + +data class Revision( + val id: Int = -1, + val branch_id: String = "", + val resource_id: String = "", + val workspace_id: String = "", + val elements: List = emptyList() +) + +data class Element( + val id: String = "", + val revision_id: Int = -1, + val branch_id: String = "", + val resource_id: String = "", + val workspace_id: String = "", + val elements: List = emptyList() +) + +data class Elements( + val revision_id: Int = -1, + val branch_id: String = "", + val resource_id: String = "", + val workspace_id: String = "", + val elements: List = emptyList() +) + +const val REPO = "repo" +const val WORKSPACE = "workspace" +const val WORKSPACE_ID = "workspace_id" +const val RESOURCE = "resource" +const val RESOURCE_ID = "resource_id" +const val BRANCH = "branch" +const val BRANCH_ID = "branch_id" +const val REVISION = "revision" +const val REVISION_ID = "revision_id" +const val ELEMENTS = "elements" +const val ELEMENT_IDS = "element_ids" +const val ELEMENT = "element" +const val ELEMENT_ID = "element_id" + +const val GET_WORKSPACES = "getWorkspaces" +const val GET_RESOURCES = "getResources" +const val GET_BRANCHES = "getBranches" +const val GET_REVISIONS = "getRevisions" +const val GET_ROOT_ELEMENT_IDS = "getRootElementIds" +const val GET_ELEMENT = "getElement" +const val GET_ELEMENTS = "getElements" + +const val TWCMAP = "twcMap" +const val TWCVERT_ADDRESS = "twc.rest.twcvert" +const val TWCMAIN_ADDRESS = "twc.rest.main" +const val QUERIES = "queries" +const val EXIT = "exit" +const val ERROR = "error" +const val LOGIN = "login" +const val LOGGED_IN = "logged_in" +const val LOGOUT = "logout" + +const val USER = "user_cookie" +const val SESSION = "session_cookie" diff --git a/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/verticles/MainVerticle.kt b/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/verticles/MainVerticle.kt new file mode 100644 index 0000000..cf43b3b --- /dev/null +++ b/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/verticles/MainVerticle.kt @@ -0,0 +1,481 @@ +package com.incquerylabs.twc.repo.crawler.verticles + +import com.incquerylabs.twc.repo.crawler.data.* +import io.vertx.core.AbstractVerticle +import io.vertx.core.json.JsonObject + +class MainVerticle(val usr: String, val pswd: String) : AbstractVerticle() { + var sum = 0 + var number = 0 + var s = 0 + var queries = 0 + + override fun start() { + val twcMap = vertx.sharedData().getLocalMap(TWCMAP) + val requestSingleElements = twcMap["requestSingleElement"] as Boolean + + val eb = vertx.eventBus() + vertx.setPeriodic(1000) { + vertx.sharedData().getCounter(QUERIES) { res -> + if (res.succeeded()) { + val counter = res.result() + counter.get { res -> + queries = res.result().toInt() + + vertx.sharedData().getCounter("sum") { res -> + if (res.succeeded()) { + val counter = res.result() + counter.get { get -> + if (get.succeeded()) { + sum = get.result().toInt() + + vertx.sharedData().getCounter("number") { res -> + if (res.succeeded()) { + val counter = res.result() + counter.get { get -> + if (get.succeeded()) { + number = get.result().toInt() + println("Total: ${queries}/${sum}/${++s} query/response/sec | Now: $number elem | AvgSpeed: ${sum / (s)} elem/sec") + counter.compareAndSet(number.toLong(), 0, {}) + + if (queries != 0 && sum != 0 && queries == sum) { + eb.send( + TWCVERT_ADDRESS, + JsonObject.mapFrom( + Message( + LOGOUT, + JsonObject() + ) + ) + ) + } + } + } + } else { + error("Counter: queries not available.") + } + } + } + } + } else { + error("Counter: queries not available.") + } + } + + + } + } else { + // Something went wrong! + } + } + + } + eb.send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + LOGIN, + User("$usr", "$pswd") + ) + )) + eb.consumer(TWCMAIN_ADDRESS) { message -> + + val messageData = (message.body() as JsonObject).mapTo(Message::class.java) + + when (messageData.event) { + LOGGED_IN -> { + println("Login complete (user: ${twcMap[USER]}, session: ${twcMap[SESSION]})") + + val workspaceId = twcMap[WORKSPACE_ID] + val resourceId = twcMap[RESOURCE_ID] + val branchId = twcMap[BRANCH_ID] + val revision = twcMap[REVISION] + when { + workspaceId == null -> eb.send( + TWCVERT_ADDRESS, + JsonObject.mapFrom( + Message( + GET_WORKSPACES, + JsonObject() + ) + ) + ) + resourceId == null -> eb.send( + TWCVERT_ADDRESS, + JsonObject.mapFrom( + Message( + GET_RESOURCES, + JsonObject().put( + WORKSPACE_ID, + workspaceId + ) + ) + ) + ) + branchId == null -> eb.send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + GET_BRANCHES, + JsonObject() + .put( + WORKSPACE_ID, + workspaceId + ) + .put( + RESOURCE_ID, + resourceId + ) + ) + ) + ) + revision == null -> eb.send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + GET_REVISIONS, + JsonObject() + .put( + WORKSPACE_ID, + workspaceId + ) + .put( + RESOURCE_ID, + resourceId + ) + .put( + BRANCH_ID, + branchId + ) + ) + ) + ) + else -> vertx.eventBus().send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + GET_ROOT_ELEMENT_IDS, + JsonObject() + .put( + WORKSPACE_ID, + workspaceId + ) + .put( + RESOURCE_ID, + resourceId + ) + .put( + BRANCH_ID, + branchId + ) + .put( + REVISION_ID, + revision + ) + ) + ) + ) + } + + } + REPO -> { + // println("Received Repository") + val repo = JsonObject(messageData.obj as Map).mapTo(Repo::class.java) + repo.workspaces.forEach { ws -> + val id = JsonObject(ws as Map).getString("@id") + eb.send( + TWCVERT_ADDRESS, + JsonObject.mapFrom( + Message( + GET_RESOURCES, + JsonObject().put( + WORKSPACE_ID, + id + ) + ) + ) + ) + } + } + WORKSPACE -> { + // println("Received Workspace") + val workspace = JsonObject(messageData.obj as Map).mapTo(Workspace::class.java) + val workspaceId = workspace.id + + workspace.resources.forEach { res -> + val resourceId = JsonObject(res as Map).getString("@id") + eb.send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + GET_BRANCHES, + JsonObject() + .put( + WORKSPACE_ID, + workspaceId + ) + .put( + RESOURCE_ID, + resourceId + ) + ) + ) + ) + } + } + RESOURCE -> { + // println("Received Resource") + val resource = JsonObject(messageData.obj as Map).mapTo(Resource::class.java) + val resourceId = resource.id + val workspaceId = resource.workspace_id + resource.branches.forEach { branch -> + val branchId = JsonObject(branch as Map).getString("@id") + eb.send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + GET_REVISIONS, + JsonObject() + .put( + WORKSPACE_ID, + workspaceId + ) + .put( + RESOURCE_ID, + resourceId + ) + .put( + BRANCH_ID, + branchId + ) + ) + ) + ) + } + + } + BRANCH -> { + // println("Received Branch") + val branch = JsonObject(messageData.obj as Map).mapTo(Branch::class.java) + val branchId = branch.id + val resourceId = branch.resource_id + val workspaceId = branch.workspace_id + val inputRevision = twcMap[REVISION] + if (inputRevision == null) { + twcMap[REVISION] = branch.revisions.maxBy { it as Int } + } + + branch.revisions.forEach { rev -> + val revId = (rev as Int) + vertx.eventBus().send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + GET_ROOT_ELEMENT_IDS, + JsonObject() + .put( + WORKSPACE_ID, + workspaceId + ) + .put( + RESOURCE_ID, + resourceId + ) + .put( + BRANCH_ID, + branchId + ) + .put( + REVISION_ID, + revId + ) + ) + ) + ) + } + + } + REVISION -> { + // println("Received Revision") + val revision = JsonObject(messageData.obj as Map).mapTo(Revision::class.java) + val revisionId = revision.id + val branchId = revision.branch_id + val resourceId = revision.resource_id + val workspaceId = revision.workspace_id + val inputRevision = twcMap[REVISION] + if (revisionId == inputRevision) { + if (requestSingleElements) { + revision.elements.forEach { element -> + val elemId = element as String + vertx.eventBus().send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + GET_ELEMENT, + JsonObject() + .put( + WORKSPACE_ID, + workspaceId + ) + .put( + RESOURCE_ID, + resourceId + ) + .put( + BRANCH_ID, + branchId + ) + .put( + REVISION_ID, + revisionId + ) + .put( + ELEMENT_ID, + elemId + ) + ) + ) + ) + } + } else { + val elementIds = revision.elements + vertx.eventBus().send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + GET_ELEMENTS, + JsonObject() + .put( + WORKSPACE_ID, + workspaceId + ) + .put( + RESOURCE_ID, + resourceId + ) + .put( + BRANCH_ID, + branchId + ) + .put( + REVISION_ID, + revisionId + ) + .put( + ELEMENT_IDS, + elementIds + ) + ) + ) + ) + } + } + + } + ELEMENT -> { + // println("Received Element") + val element = JsonObject(messageData.obj as Map).mapTo(Element::class.java) + val revisionId = element.revision_id + val branchId = element.branch_id + val resourceId = element.resource_id + val workspaceId = element.workspace_id + element.elements.forEach { element -> + val elementId = JsonObject(element as Map).getString("@id") + + vertx.eventBus().send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + GET_ELEMENT, + JsonObject() + .put( + WORKSPACE_ID, + workspaceId + ) + .put( + RESOURCE_ID, + resourceId + ) + .put( + BRANCH_ID, + branchId + ) + .put( + REVISION_ID, + revisionId + ) + .put( + ELEMENT_ID, + elementId + ) + ) + ) + ) + } + } + ELEMENTS -> { + // println("Received Elements") + val elements = JsonObject(messageData.obj as Map).mapTo(Elements::class.java) + val revisionId = elements.revision_id + val branchId = elements.branch_id + val resourceId = elements.resource_id + val workspaceId = elements.workspace_id + val elementIds = elements.elements.map { element -> + JsonObject.mapFrom(element).getString("@id") + } + vertx.eventBus().send( + TWCVERT_ADDRESS, JsonObject.mapFrom( + Message( + GET_ELEMENTS, + JsonObject() + .put( + WORKSPACE_ID, + workspaceId + ) + .put( + RESOURCE_ID, + resourceId + ) + .put( + BRANCH_ID, + branchId + ) + .put( + REVISION_ID, + revisionId + ) + .put( + ELEMENT_IDS, + elementIds + ) + ) + ) + ) + } + ERROR -> { + println("\nExit") + if (twcMap["cookies"] != null) { + eb.send( + TWCVERT_ADDRESS, + JsonObject.mapFrom( + Message( + LOGOUT, + JsonObject() + ) + ) + ) + } + vertx.close() + } + EXIT -> { + println("\nExit") + if (twcMap["cookies"] != null) { + eb.send( + TWCVERT_ADDRESS, + JsonObject.mapFrom( + Message( + LOGOUT, + JsonObject() + ) + ) + ) + } + vertx.close() + } + + else -> error("Unknown Command: ${messageData.event}") + } + + } + } +} \ No newline at end of file diff --git a/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/verticles/RESTVerticle.kt b/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/verticles/RESTVerticle.kt similarity index 68% rename from com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/verticles/RESTVerticle.kt rename to com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/verticles/RESTVerticle.kt index 7be5fa6..e3b2cbf 100644 --- a/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/com/incquerylabs/vhci/modelaccess/twc/rest/verticles/RESTVerticle.kt +++ b/com.incquerylabs.vhci.modelaccess.twc.rest/src/main/kotlin/verticles/RESTVerticle.kt @@ -1,17 +1,8 @@ -package com.incquerylabs.vhci.modelaccess.twc.rest.verticles - -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Branch -import com.incquerylabs.vhci.modelaccess.twc.rest.data.DataConstants -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Element -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Elements -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Message -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Repo -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Resource -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Revision -import com.incquerylabs.vhci.modelaccess.twc.rest.data.Workspace +package com.incquerylabs.twc.repo.crawler.verticles + +import com.incquerylabs.twc.repo.crawler.data.* import io.vertx.core.AbstractVerticle import io.vertx.core.buffer.Buffer -import io.vertx.core.json.JsonArray import io.vertx.core.json.JsonObject import io.vertx.core.shareddata.LocalMap import io.vertx.ext.web.client.WebClient @@ -26,7 +17,7 @@ class RESTVerticle() : AbstractVerticle() { var chunkSize = -1 override fun start() { - val twcMap = vertx.sharedData().getLocalMap(DataConstants.TWCMAP) + val twcMap = vertx.sharedData().getLocalMap(TWCMAP) val client = WebClient.create(vertx, WebClientOptions().setSsl(twcMap["server_ssl"] as Boolean)) serverPath = twcMap["server_path"].toString() @@ -35,63 +26,63 @@ class RESTVerticle() : AbstractVerticle() { val debug = twcMap["debug"] as Boolean - vertx.eventBus().consumer(DataConstants.TWCVERT_ADDRESS) { message -> + vertx.eventBus().consumer(TWCVERT_ADDRESS) { message -> val json = message.body() as JsonObject val obj = json.getJsonObject("obj") when (json.getString("event")) { - DataConstants.LOGIN -> { + LOGIN -> { println("Try to login. Username: ${json.getJsonObject("obj").getString("username")}") //println(obj) login(client, twcMap) } - DataConstants.LOGOUT -> { + LOGOUT -> { println("Log out") logout(client, twcMap) } - DataConstants.GET_WORKSPACES -> { + GET_WORKSPACES -> { if (debug) { println("Query Workspaces") println(obj) } getWorkspaces(client, twcMap) } - DataConstants.GET_RESOURCES -> { + GET_RESOURCES -> { if (debug) { println("Query Resources") println(obj) } getResources(client, twcMap, obj) } - DataConstants.GET_BRANCHES -> { + GET_BRANCHES -> { if (debug) { println("Query Branches") println(obj) } getBranches(client, twcMap, obj) } - DataConstants.GET_REVISIONS -> { + GET_REVISIONS -> { if (debug) { println("Query Revisions") println(obj) } getRevisions(client, twcMap, obj) } - DataConstants.GET_ROOT_ELEMENT_IDS -> { + GET_ROOT_ELEMENT_IDS -> { if (debug) { println("Search Root Element Ids") println(obj) } getRootElementIds(client, twcMap, obj) } - DataConstants.GET_ELEMENT -> { + GET_ELEMENT -> { if (debug) { println("Query Element") println(obj) } getElement(client, twcMap, obj) } - DataConstants.GET_ELEMENTS -> { + GET_ELEMENTS -> { if (debug) { println("Query Elements") println(obj) @@ -107,11 +98,11 @@ class RESTVerticle() : AbstractVerticle() { } private fun getElements(client: WebClient, twcMap: LocalMap, obj: JsonObject) { - val workspaceId = obj.getString(DataConstants.WORKSPACE_ID) - val resourceId = obj.getString(DataConstants.RESOURCE_ID) - val branchId = obj.getString(DataConstants.BRANCH_ID) - val revisionId = obj.getInteger(DataConstants.REVISION_ID) - val elementIds = obj.getJsonArray(DataConstants.ELEMENT_IDS) + val workspaceId = obj.getString(WORKSPACE_ID) + val resourceId = obj.getString(RESOURCE_ID) + val branchId = obj.getString(BRANCH_ID) + val revisionId = obj.getInteger(REVISION_ID) + val elementIds = obj.getJsonArray(ELEMENT_IDS) val elementSize = elementIds.size().toLong() queryPrepared(elementSize) @@ -120,8 +111,8 @@ class RESTVerticle() : AbstractVerticle() { "/osmc/workspaces/$workspaceId/resources/$resourceId/branches/$branchId/revisions/$revisionId/elements" ) .putHeader("content-type", "text/plain") - .putHeader("Cookie", "${twcMap[DataConstants.USER]}") - .putHeader("Cookie", "${twcMap[DataConstants.SESSION]}") + .putHeader("Cookie", "${twcMap[USER]}") + .putHeader("Cookie", "${twcMap[SESSION]}") .sendBuffer(Buffer.buffer(elementIds.joinToString(","))) { ar -> if (ar.succeeded()) { if (ar.result().statusCode() == 200) { @@ -138,18 +129,40 @@ class RESTVerticle() : AbstractVerticle() { containedElements.withIndex().groupBy { it.index / chunkSize }.values.map { it.map { it.value } }.forEach { chunkList -> - val elementM = Elements(revisionId, branchId, resourceId, workspaceId, chunkList) + val elementM = Elements( + revisionId, + branchId, + resourceId, + workspaceId, + chunkList + ) vertx.eventBus().send( - DataConstants.TWCMAIN_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.ELEMENTS, elementM)) + TWCMAIN_ADDRESS, + JsonObject.mapFrom( + Message( + ELEMENTS, + elementM + ) + ) ) } } else { val elementM = - Elements(revisionId, branchId, resourceId, workspaceId, containedElements) + Elements( + revisionId, + branchId, + resourceId, + workspaceId, + containedElements + ) vertx.eventBus().send( - DataConstants.TWCMAIN_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.ELEMENTS, elementM)) + TWCMAIN_ADDRESS, + JsonObject.mapFrom( + Message( + ELEMENTS, + elementM + ) + ) ) } } @@ -167,7 +180,7 @@ class RESTVerticle() : AbstractVerticle() { } private fun queryPrepared(elementSize: Long) { - vertx.sharedData().getCounter(DataConstants.QUERIES) { res -> + vertx.sharedData().getCounter(QUERIES) { res -> if (res.succeeded()) { val counter = res.result() counter.addAndGet(elementSize) {} @@ -202,18 +215,18 @@ class RESTVerticle() : AbstractVerticle() { private fun getRootElement(client: WebClient, twcMap: LocalMap, obj: JsonObject) { queryPrepared(1) - val workspaceId = obj.getString(DataConstants.WORKSPACE_ID) - val resourceId = obj.getString(DataConstants.RESOURCE_ID) - val branchId = obj.getString(DataConstants.BRANCH_ID) - val revisionId = obj.getInteger(DataConstants.REVISION_ID) - val elementId = obj.getString(DataConstants.ELEMENT_ID) + val workspaceId = obj.getString(WORKSPACE_ID) + val resourceId = obj.getString(RESOURCE_ID) + val branchId = obj.getString(BRANCH_ID) + val revisionId = obj.getInteger(REVISION_ID) + val elementId = obj.getString(ELEMENT_ID) client.get( port, serverPath, "/osmc/workspaces/$workspaceId/resources/$resourceId/branches/$branchId/elements/$elementId" ) .putHeader("content-type", "application/ld+json") - .putHeader("Cookie", "${twcMap[DataConstants.USER]}") - .putHeader("Cookie", "${twcMap[DataConstants.SESSION]}") + .putHeader("Cookie", "${twcMap[USER]}") + .putHeader("Cookie", "${twcMap[SESSION]}") .sendJson(JsonObject()) { ar -> if (ar.succeeded()) { if (ar.result().statusCode() == 200) { @@ -228,8 +241,13 @@ class RESTVerticle() : AbstractVerticle() { ) vertx.eventBus().send( - DataConstants.TWCMAIN_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.ELEMENT, element)) + TWCMAIN_ADDRESS, + JsonObject.mapFrom( + Message( + ELEMENT, + element + ) + ) ) } else { @@ -245,17 +263,17 @@ class RESTVerticle() : AbstractVerticle() { } private fun getRootElementIds(client: WebClient, twcMap: LocalMap, obj: JsonObject) { - val workspaceId = obj.getString(DataConstants.WORKSPACE_ID) - val resourceId = obj.getString(DataConstants.RESOURCE_ID) - val branchId = obj.getString(DataConstants.BRANCH_ID) - val revId = obj.getInteger(DataConstants.REVISION_ID) + val workspaceId = obj.getString(WORKSPACE_ID) + val resourceId = obj.getString(RESOURCE_ID) + val branchId = obj.getString(BRANCH_ID) + val revId = obj.getInteger(REVISION_ID) client.get( port, serverPath, "/osmc/workspaces/${workspaceId}/resources/${resourceId}/branches/${branchId}/revisions/${revId}" ) .putHeader("content-type", "application/ld+json") - .putHeader("Cookie", "${twcMap[DataConstants.USER]}") - .putHeader("Cookie", "${twcMap[DataConstants.SESSION]}") + .putHeader("Cookie", "${twcMap[USER]}") + .putHeader("Cookie", "${twcMap[SESSION]}") .send { ar -> if (ar.succeeded()) { if (ar.result().statusCode() == 200) { @@ -268,8 +286,13 @@ class RESTVerticle() : AbstractVerticle() { ) //println(revision) vertx.eventBus().send( - DataConstants.TWCMAIN_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.REVISION, revision)) + TWCMAIN_ADDRESS, + JsonObject.mapFrom( + Message( + REVISION, + revision + ) + ) ) } else { @@ -285,16 +308,16 @@ class RESTVerticle() : AbstractVerticle() { } private fun getRevisions(client: WebClient, twcMap: LocalMap, obj: JsonObject) { - val workspaceId = obj.getString(DataConstants.WORKSPACE_ID) - val resourceId = obj.getString(DataConstants.RESOURCE_ID) - val branchId = obj.getString(DataConstants.BRANCH_ID) + val workspaceId = obj.getString(WORKSPACE_ID) + val resourceId = obj.getString(RESOURCE_ID) + val branchId = obj.getString(BRANCH_ID) client.get( port, serverPath, "/osmc/workspaces/${workspaceId}/resources/${resourceId}/branches/${branchId}/revisions" ) .putHeader("content-type", "application/ld+json") - .putHeader("Cookie", "${twcMap[DataConstants.USER]}") - .putHeader("Cookie", "${twcMap[DataConstants.SESSION]}") + .putHeader("Cookie", "${twcMap[USER]}") + .putHeader("Cookie", "${twcMap[SESSION]}") .send { ar -> if (ar.succeeded()) { if (ar.result().statusCode() == 200) { @@ -308,8 +331,13 @@ class RESTVerticle() : AbstractVerticle() { ) //println(resource) vertx.eventBus().send( - DataConstants.TWCMAIN_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.BRANCH, branch)) + TWCMAIN_ADDRESS, + JsonObject.mapFrom( + Message( + BRANCH, + branch + ) + ) ) } else { @@ -325,22 +353,31 @@ class RESTVerticle() : AbstractVerticle() { } private fun getBranches(client: WebClient, twcMap: LocalMap, obj: JsonObject) { - val workspaceId = obj.getString(DataConstants.WORKSPACE_ID) - val resourceId = obj.getString(DataConstants.RESOURCE_ID) + val workspaceId = obj.getString(WORKSPACE_ID) + val resourceId = obj.getString(RESOURCE_ID) client.get(port, serverPath, "/osmc/workspaces/${workspaceId}/resources/${resourceId}/branches") .putHeader("content-type", "application/ld+json") - .putHeader("Cookie", "${twcMap[DataConstants.USER]}") - .putHeader("Cookie", "${twcMap[DataConstants.SESSION]}") + .putHeader("Cookie", "${twcMap[USER]}") + .putHeader("Cookie", "${twcMap[SESSION]}") .send { ar -> if (ar.succeeded()) { if (ar.result().statusCode() == 200) { val data = ar.result().bodyAsJsonObject() - val resource = Resource(resourceId, workspaceId, data.getJsonArray("ldp:contains").list) + val resource = Resource( + resourceId, + workspaceId, + data.getJsonArray("ldp:contains").list + ) //println(resource) vertx.eventBus().send( - DataConstants.TWCMAIN_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.RESOURCE, resource)) + TWCMAIN_ADDRESS, + JsonObject.mapFrom( + Message( + RESOURCE, + resource + ) + ) ) } else { @@ -356,21 +393,29 @@ class RESTVerticle() : AbstractVerticle() { } private fun getResources(client: WebClient, twcMap: LocalMap, obj: JsonObject) { - val workspaceId = obj.getString(DataConstants.WORKSPACE_ID) + val workspaceId = obj.getString(WORKSPACE_ID) client.get(port, serverPath, "/osmc/workspaces/${workspaceId}/resources") .putHeader("content-type", "application/ld+json") - .putHeader("Cookie", "${twcMap[DataConstants.USER]}") - .putHeader("Cookie", "${twcMap[DataConstants.SESSION]}") + .putHeader("Cookie", "${twcMap[USER]}") + .putHeader("Cookie", "${twcMap[SESSION]}") .send { ar -> if (ar.succeeded()) { if (ar.result().statusCode() == 200) { val data = ar.result().bodyAsJsonArray() - val workspace = Workspace(workspaceId, data.getJsonObject(0).getJsonArray("ldp:contains").list) + val workspace = Workspace( + workspaceId, + data.getJsonObject(0).getJsonArray("ldp:contains").list + ) //println(workspace) vertx.eventBus().send( - DataConstants.TWCMAIN_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.WORKSPACE, workspace)) + TWCMAIN_ADDRESS, + JsonObject.mapFrom( + Message( + WORKSPACE, + workspace + ) + ) ) } else { @@ -395,8 +440,8 @@ class RESTVerticle() : AbstractVerticle() { if (ar.result().statusCode() == 204) { val userCookie = ar.result().cookies()[0].split(';')[0] val sessionCookie = ar.result().cookies()[1].split(';')[0] - twcMap[DataConstants.USER] = userCookie - twcMap[DataConstants.SESSION] = sessionCookie + twcMap[USER] = userCookie + twcMap[SESSION] = sessionCookie val currentTimeMillis = System.currentTimeMillis() val sessionFile = "session_details_$currentTimeMillis" twcMap["sessionFile"] = sessionFile @@ -406,8 +451,13 @@ class RESTVerticle() : AbstractVerticle() { """.trimIndent()) println("Session details written to: $sessionFile") vertx.eventBus().send( - DataConstants.TWCMAIN_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.LOGGED_IN, JsonObject())) + TWCMAIN_ADDRESS, + JsonObject.mapFrom( + Message( + LOGGED_IN, + JsonObject() + ) + ) ) } else { println("${ar.result().statusCode()} : ${ar.result().statusMessage()}") @@ -425,8 +475,8 @@ class RESTVerticle() : AbstractVerticle() { private fun logout(client: WebClient, twcMap: LocalMap) { client.get(port, serverPath, "/osmc/logout") .putHeader("content-type", "application/ld+json") - .putHeader("Cookie", "${twcMap[DataConstants.USER]}") - .putHeader("Cookie", "${twcMap[DataConstants.SESSION]}") + .putHeader("Cookie", "${twcMap[USER]}") + .putHeader("Cookie", "${twcMap[SESSION]}") .send { ar -> if (ar.succeeded()) { if (ar.result().statusCode() == 204) { @@ -435,8 +485,13 @@ class RESTVerticle() : AbstractVerticle() { println("Logout successful, deleting session file $sessionFile") File(sessionFile).deleteOnExit() vertx.eventBus().send( - DataConstants.TWCMAIN_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.EXIT, JsonObject())) + TWCMAIN_ADDRESS, + JsonObject.mapFrom( + Message( + EXIT, + JsonObject() + ) + ) ) } else { println("${ar.result().statusCode()} : ${ar.result().statusMessage()}") @@ -454,8 +509,8 @@ class RESTVerticle() : AbstractVerticle() { private fun getWorkspaces(client: WebClient, twcMap: LocalMap) { client.get(port, serverPath, "/osmc/workspaces") .putHeader("content-type", "application/ld+json") - .putHeader("Cookie", "${twcMap[DataConstants.USER]}") - .putHeader("Cookie", "${twcMap[DataConstants.SESSION]}") + .putHeader("Cookie", "${twcMap[USER]}") + .putHeader("Cookie", "${twcMap[SESSION]}") .timeout(2000) .send { ar -> if (ar.succeeded()) { @@ -465,11 +520,17 @@ class RESTVerticle() : AbstractVerticle() { val repoID = data.getString("@id") val workspaces = data.getJsonArray("ldp:contains") - val repo = Repo(repoID, workspaces.list) + val repo = + Repo(repoID, workspaces.list) vertx.eventBus().send( - DataConstants.TWCMAIN_ADDRESS, - JsonObject.mapFrom(Message(DataConstants.REPO, JsonObject.mapFrom(repo))) + TWCMAIN_ADDRESS, + JsonObject.mapFrom( + Message( + REPO, + JsonObject.mapFrom(repo) + ) + ) ) } else { println("${ar.result().statusCode()} : ${ar.result().statusMessage()}") @@ -485,7 +546,13 @@ class RESTVerticle() : AbstractVerticle() { private fun myError() { vertx.eventBus() - .send(DataConstants.TWCMAIN_ADDRESS, JsonObject.mapFrom(Message(DataConstants.ERROR, JsonObject()))) + .send( + TWCMAIN_ADDRESS, JsonObject.mapFrom( + Message( + ERROR, + JsonObject() + ) + )) } } \ No newline at end of file