Skip to content

Commit 669540c

Browse files
feat: implement delete and find of room digital twin
1 parent 26ee7cd commit 669540c

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/main/kotlin/infrastructure/digitaltwins/DigitalTwinManager.kt

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,38 @@ class DigitalTwinManager : RoomDigitalTwinManager {
4848
}
4949

5050
override fun deleteRoomDigitalTwin(roomId: RoomID): Boolean {
51-
TODO("Not yet implemented")
52-
}
51+
fun deleteIncomingRelationships() {
52+
this.dtClient.listIncomingRelationships(roomId.value).forEach {
53+
this.dtClient.deleteRelationship(it.sourceId, it.relationshipId)
54+
}
55+
}
5356

54-
override fun findBy(roomId: RoomID): Room? {
55-
TODO("Not yet implemented")
57+
fun deleteOutgoingRelationships() {
58+
this.dtClient.listRelationships(roomId.value, BasicRelationship::class.java).forEach {
59+
this.dtClient.deleteRelationship(it.sourceId, it.id)
60+
}
61+
}
62+
63+
return try {
64+
deleteIncomingRelationships()
65+
deleteOutgoingRelationships()
66+
println(roomId.value)
67+
dtClient.deleteDigitalTwin(roomId.value)
68+
true
69+
} catch (e: ErrorResponseException) {
70+
println(e) // log the exception.
71+
false
72+
}
5673
}
5774

75+
override fun findBy(roomId: RoomID): Room? =
76+
try {
77+
this.dtClient.getDigitalTwin(roomId.value, BasicDigitalTwin::class.java).toRoom()
78+
} catch (e: ErrorResponseException) {
79+
println(e) // log the exception.
80+
null
81+
}
82+
5883
companion object {
5984
private const val dtAppIdVariable = "AZURE_CLIENT_ID"
6085
private const val dtTenantVariable = "AZURE_TENANT_ID"

0 commit comments

Comments
 (0)