Skip to content

Commit

Permalink
#19 ISD-567 logs element parents
Browse files Browse the repository at this point in the history
  • Loading branch information
pappist committed Apr 9, 2024
1 parent da7f92e commit 6e65b86
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
16 changes: 14 additions & 2 deletions src/main/kotlin/data/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data class Revision(
val branch_id: String = "",
val resource_id: String = "",
val workspace_id: String = "",
val elements: List<Any?> = emptyList()
val elements: List<String> = emptyList()
)

data class Element(
Expand All @@ -54,9 +54,20 @@ data class Elements(
val branch_id: String = "",
val resource_id: String = "",
val workspace_id: String = "",
val elements: List<Any?> = emptyList()
val elements: Map<String, String> = mapOf()
)

data class ElementContainer(
val name: String = "undefined",
val type: String = "",
val serverID: String = "",
val mdID: String = ""
) {
override fun toString(): String {
return "[MDObjID: ${mdID}, name: $name, type: $type, serverID: $serverID]"
}
}

const val REPO = "repo"
const val WORKSPACE = "workspace"
const val WORKSPACE_ID = "workspace_id"
Expand All @@ -73,6 +84,7 @@ const val ELEMENTS = "elements"
const val ELEMENT_IDS = "element_ids"
const val ELEMENT = "element"
const val ELEMENT_ID = "element_id"
const val CONTAINERS = "containers"

const val GET_WORKSPACES = "getWorkspaces"
const val GET_RESOURCES = "getResources"
Expand Down
8 changes: 3 additions & 5 deletions src/main/kotlin/verticles/MainVerticle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class MainVerticle(
if (revisionId == inputRevision) {
if (requestSingleElements) {
revision.elements.forEach { element ->
val elemId = element as String
val elemId = element
vertx.eventBus().send(
TWCVERT_ADDRESS, JsonObject.mapFrom(
Message(
Expand Down Expand Up @@ -353,7 +353,7 @@ class MainVerticle(
)
}
} else {
val elementIds = revision.elements
val elementIds = revision.elements.map { Pair(it, "") }.toMap()
vertx.eventBus().send(
TWCVERT_ADDRESS, JsonObject.mapFrom(
Message(
Expand Down Expand Up @@ -433,9 +433,7 @@ class MainVerticle(
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")
}
val elementIds = elements.elements
vertx.eventBus().send(
TWCVERT_ADDRESS, JsonObject.mapFrom(
Message(
Expand Down
37 changes: 27 additions & 10 deletions src/main/kotlin/verticles/RESTVerticle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ class RESTVerticle(
val resourceId = obj.getString(RESOURCE_ID)
val branchId = obj.getString(BRANCH_ID)
val revisionId = obj.getInteger(REVISION_ID)
val elementIds = obj.getJsonArray(ELEMENT_IDS).map { it.toString().trim('"') }
val elementIds = (obj.getJsonObject(ELEMENT_IDS) as Iterable<MutableMap.MutableEntry<String, Any>>)
.associate { Pair(it.key, it.value) }
.mapKeys { e -> e.key.trim('"') }
.mapValues { e -> e.value.toString() }
val elementSize = elementIds.size.toLong()
queryPrepared(elementSize)
val requestData = elementIds.keys.joinToString(",") { it }

client.post(
port, serverPath,
Expand All @@ -113,19 +117,32 @@ class RESTVerticle(
.putHeader("Cookie", "${twcMap[USER]}")
.putHeader("Cookie", "${twcMap[SESSION]}")
.timeout(timeout)
.sendBuffer(Buffer.buffer(elementIds.joinToString(","))) { ar ->
.sendBuffer(Buffer.buffer(requestData)) { ar ->
if (ar.succeeded()) {
if (ar.result().statusCode() == 200) {

val data = ar.result().bodyAsJsonObject()

queryCompleted(elementSize)
val containedElements = elementIds.flatMap { elementId ->
val element = data.getJsonObject(elementId).getJsonArray("data")
element.getJsonObject(0).getJsonArray("ldp:contains")
val containedElements = elementIds.keys.flatMap { elementId ->
val element = data.getJsonObject(elementId)
val elementData = element.getJsonArray("data")
val elementStatus = element.getInteger("status")
val childElements = elementData.getJsonObject(0).getJsonArray("ldp:contains").map {
JsonObject.mapFrom(it).getString("@id")
}
if(elementStatus != 200 ) {
println("Unexpected status code on fetching element details. ID: $elementId, parent: ${elementIds[elementId]}")
}
val parentName = elementData.getJsonObject(1).getString("kerml:name")
val parentType = elementData.getJsonObject(1).getString("@type")
val parentSegment = "$parentName (type: $parentType)"
childElements.map { childId -> Pair(childId, "${elementIds.getOrDefault(elementId, "")} / $parentSegment") }
}

if (containedElements.isNotEmpty()) {
if (chunkSize > 1) {
println("First element in chunk: ${containedElements.first().first} is a child of ${containedElements.first().second}")
containedElements.withIndex().groupBy {
it.index / chunkSize
}.values.map { it.map {
Expand All @@ -135,7 +152,7 @@ class RESTVerticle(
branchId,
resourceId,
workspaceId,
chunkList
chunkList.toMap()
)
vertx.eventBus().send(
TWCMAIN_ADDRESS,
Expand All @@ -154,7 +171,7 @@ class RESTVerticle(
branchId,
resourceId,
workspaceId,
containedElements
containedElements.toMap()
)
vertx.eventBus().send(
TWCMAIN_ADDRESS,
Expand All @@ -170,12 +187,12 @@ class RESTVerticle(
elementContentHandler.handleContent(data, serverPath, workspaceId, resourceId, branchId, revisionId)
} else {
println("Error on requesting elements: ${ar.result().statusCode()} : ${ar.result().statusMessage()}")
printElementIds(elementIds)
printElementIds(elementIds.keys.toList())
myError()
}
} else {
println("Query Root Element failed: ${ar.cause().message}")
printElementIds(elementIds)
printElementIds(elementIds.keys.toList())
myError()
}

Expand Down Expand Up @@ -292,7 +309,7 @@ class RESTVerticle(
//println(data)
val revision = Revision(
revId, branchId, resourceId, workspaceId,
data.getJsonObject(0).getJsonArray("rootObjectIDs").list
data.getJsonObject(0).getJsonArray("rootObjectIDs").list.map { it.toString() }
)
//println(revision)
vertx.eventBus().send(
Expand Down

0 comments on commit 6e65b86

Please sign in to comment.