Skip to content

Commit

Permalink
chore: create azure dt client
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-acampora committed Feb 26, 2023
1 parent 157ca05 commit c412650
Showing 1 changed file with 48 additions and 13 deletions.
61 changes: 48 additions & 13 deletions src/main/kotlin/infrastructure/digitaltwins/AzureDTClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,64 @@
package infrastructure.digitaltwins

import application.controller.manager.HealthProfessionalDigitalTwinsManager
import application.controller.manager.UserDigitalTwinsManager
import com.azure.digitaltwins.core.BasicDigitalTwin
import com.azure.digitaltwins.core.BasicRelationship
import com.azure.digitaltwins.core.DigitalTwinsClientBuilder
import com.azure.digitaltwins.core.implementation.models.ErrorResponseException
import com.azure.identity.DefaultAzureCredentialBuilder
import entity.healthprofessional.HealthProfessionalData.HealthProfessional
import entity.user.User
import infrastructure.digitaltwins.adtpresenter.HealthProfessionalAdt.toDigitalTwin

/**
* The Azure Digital Twins Client.
* It contains the implementation of Digital Twins operations.
*/
class AzureDTClient : UserDigitalTwinsManager, HealthProfessionalDigitalTwinsManager {
class AzureDTClient : HealthProfessionalDigitalTwinsManager {

override fun createUser(user: User) {
TODO("Not yet implemented")
init {
checkNotNull(System.getenv("AZURE_CLIENT_ID")) {
"Azure Client App Id required!"
}
checkNotNull(System.getenv("AZURE_TENANT_ID")) {
"Azure Tenant Id required!"
}
checkNotNull(System.getenv("AZURE_CLIENT_SECRET")) {
"Azure Client Secret required!"
}
checkNotNull(System.getenv("AZURE_DT_ENDPOINT")) {
"Azure Digital Twin Endpoint required!"
}
}

override fun createHealthProfessional(healthProfessional: HealthProfessional) {
TODO("Not yet implemented")
}
private val client = DigitalTwinsClientBuilder()
.credential(DefaultAzureCredentialBuilder().build())
.endpoint(System.getenv("AZURE_DT_ENDPOINT"))
.buildClient()

override fun deleteUser(userId: String) {
TODO("Not yet implemented")
override fun createHealthProfessional(healthProfessional: HealthProfessional): Boolean {
with(healthProfessional.toDigitalTwin()) {
try {
client.createOrReplaceDigitalTwin(this.id, this, BasicDigitalTwin::class.java)
return true
} catch (e: ErrorResponseException) {
println(e)
return false
}
}
}

override fun deleteHealthProfessional(healthProfessionalId: String) {
TODO("Not yet implemented")
}
override fun deleteHealthProfessional(healthProfessionalId: String): Boolean =
try {
client.listIncomingRelationships(healthProfessionalId).forEach {
client.deleteRelationship(it.sourceId, it.relationshipId)
}
client.listRelationships(healthProfessionalId, BasicRelationship::class.java).forEach {
client.deleteRelationship(it.sourceId, it.id)
}
client.deleteDigitalTwin(healthProfessionalId)
true
} catch (e: ErrorResponseException) {
println(e)
false
}
}

0 comments on commit c412650

Please sign in to comment.