|
15 | 15 | import com.azure.identity.DefaultAzureCredentialBuilder;
|
16 | 16 | import com.google.gson.Gson;
|
17 | 17 | import com.google.gson.JsonObject;
|
| 18 | +import entity.actuator.ActuatorID; |
| 19 | +import entity.actuator.ActuatorType; |
18 | 20 | import entity.medicaltechnology.MedicalTechnology;
|
19 | 21 | import entity.medicaltechnology.MedicalTechnologyID;
|
20 | 22 | import entity.room.RoomID;
|
| 23 | +import infrastructure.digitaltwins.adtpresentation.ActuatorAdtPresentation; |
21 | 24 | import infrastructure.digitaltwins.adtpresentation.MedicalTechnologyAdtPresentation;
|
| 25 | +import usecase.repository.ActuatorRepository; |
22 | 26 | import usecase.repository.MedicalTechnologyRepository;
|
23 | 27 |
|
24 | 28 | import java.util.Objects;
|
|
29 | 33 | /**
|
30 | 34 | * Digital Twin Manager that implements the repositories of the application.
|
31 | 35 | */
|
32 |
| -public class DigitalTwinManager implements MedicalTechnologyRepository { |
| 36 | +public class DigitalTwinManager implements MedicalTechnologyRepository, ActuatorRepository { |
33 | 37 | private static final String DT_APP_ID_VARIABLE = "AZURE_CLIENT_ID";
|
34 | 38 | private static final String DT_TENANT_VARIABLE = "AZURE_TENANT_ID";
|
35 | 39 | private static final String DT_APP_SECRET_VARIABLE = "AZURE_CLIENT_SECRET";
|
@@ -82,6 +86,25 @@ public final Optional<MedicalTechnology> findBy(final MedicalTechnologyID medica
|
82 | 86 | });
|
83 | 87 | }
|
84 | 88 |
|
| 89 | + @Override |
| 90 | + public final Optional<ActuatorID> findActuatorInRoom(final ActuatorType actuatorType, final RoomID roomID) { |
| 91 | + return this.applySafeDigitalTwinOperation(Optional.empty(), client -> |
| 92 | + client.query("SELECT TOP(1) CT.$dtId" |
| 93 | + + " FROM DIGITALTWINS T " |
| 94 | + + "JOIN CT RELATED T." |
| 95 | + + ActuatorAdtPresentation.HAS_ACTUATOR_RELATIONSHIP |
| 96 | + + " WHERE T.$dtId = '" |
| 97 | + + roomID.getId() |
| 98 | + + "' AND CT.type = '" |
| 99 | + + ActuatorAdtPresentation.toActuatorDigitalTwinType(actuatorType) |
| 100 | + + "'", |
| 101 | + String.class).stream() |
| 102 | + .findFirst() |
| 103 | + .map(firstResult -> |
| 104 | + new ActuatorID(new Gson().fromJson(firstResult, JsonObject.class).get("$dtId").getAsString()) |
| 105 | + )); |
| 106 | + } |
| 107 | + |
85 | 108 | private <R> R applySafeDigitalTwinOperation(final R defaultResult, final Function<DigitalTwinsClient, R> operation) {
|
86 | 109 | try {
|
87 | 110 | return operation.apply(this.dtClient);
|
|
0 commit comments