From 5046cc75ee1bf913e9e72c28915d7ba8b2540167 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Mon, 31 Aug 2020 16:51:00 -0700 Subject: [PATCH 1/7] Implement the last 2 Model APIs --- .../core/DigitalTwinsAsyncClient.java | 36 ++++++++++++++++--- .../digitaltwins/core/DigitalTwinsClient.java | 18 +++++++++- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java index 45139226e5ba6..d8ac1b2d92676 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java @@ -20,6 +20,7 @@ import com.azure.digitaltwins.core.util.DigitalTwinsResponse; import com.azure.digitaltwins.core.util.DigitalTwinsResponseHeaders; import com.azure.digitaltwins.core.util.ListModelOptions; +import com.azure.digitaltwins.core.util.UpdateOperationUtility; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; @@ -593,8 +594,8 @@ Mono> createModelsSinglePageAsync(List models, */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getModel(String modelId) { - return withContext(context -> getModelWithResponse(modelId, context)) - .flatMap(response -> Mono.just(response.getValue())); + return getModelWithResponse(modelId) + .map(response -> response.getValue()); } /** @@ -665,8 +666,8 @@ Mono> listModelsNextSinglePageAsync(String nextLink, Co */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteModel(String modelId) { - return withContext(context -> deleteModelWithResponse(modelId, context)) - .flatMap(response -> Mono.just(response.getValue())); + return deleteModelWithResponse(modelId) + .map(response -> response.getValue()); } /** @@ -683,11 +684,36 @@ Mono> deleteModelWithResponse(String modelId, Context context){ return protocolLayer.getDigitalTwinModels().deleteWithResponseAsync(modelId, context); } - //TODO: Decommission Model APIs (waiting for Abhipsa's change to come in) PagedFlux listRelationships(String digitalTwinId, String relationshipName, Context context) { return new PagedFlux<>( () -> listRelationshipsFirstPage(digitalTwinId, relationshipName, context), nextLink -> listRelationshipsNextPage(nextLink, context)); } + /** + * Decommissions a model. + * @param modelId The Id of the model to decommission. + * @return an empty Mono + */ + public Mono decommissionModel(String modelId) { + return decommissionModelWithResponse(modelId) + .map(response -> response.getValue()); + } + + /** + * Decommissions a model. + * @param modelId The Id of the model to decommission. + * @return The http response. + */ + public Mono> decommissionModelWithResponse(String modelId) { + return withContext(context -> decommissionModelWithResponse(modelId, context)); + } + + Mono> decommissionModelWithResponse(String modelId, Context context) { + List updateOperation = new UpdateOperationUtility() + .appendReplaceOperation("/decommissioned", true) + .getUpdateOperations(); + + return protocolLayer.getDigitalTwinModels().updateWithResponseAsync(modelId, updateOperation, context); + } } diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java index 671484f6e5f88..c2fb9cd74eb5f 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java @@ -15,6 +15,7 @@ import com.azure.digitaltwins.core.models.ModelData; import com.azure.digitaltwins.core.util.DigitalTwinsResponse; import com.azure.digitaltwins.core.util.ListModelOptions; +import reactor.core.publisher.Mono; import java.util.List; @@ -365,6 +366,21 @@ public Response deleteModelWithResponse(String modelId, Context context) { return digitalTwinsAsyncClient.deleteModelWithResponse(modelId, context).block(); } - //TODO: Decommission Model APIs (waiting for Abhipsa's change to come in) + /** + * Decommissions a model. + * @param modelId The Id of the model to decommission. + * @return Void + */ + public Void decommissionModel(String modelId) { + return digitalTwinsAsyncClient.decommissionModel(modelId).block(); + } + /** + * Decommissions a model. + * @param modelId The Id of the model to decommission. + * @return The http response. + */ + public Response decommissionModelWithResponse(String modelId, Context context) { + return digitalTwinsAsyncClient.decommissionModelWithResponse(modelId, context).block(); + } } From b4d4727ae6eed39278561d8c538ac4fba9dc13d9 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Mon, 31 Aug 2020 16:51:19 -0700 Subject: [PATCH 2/7] Update API design.md --- .../azure-digitaltwins-core/API design.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/API design.md b/sdk/digitaltwins/azure-digitaltwins-core/API design.md index cb386611f147d..6b2b43827cd5f 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/API design.md +++ b/sdk/digitaltwins/azure-digitaltwins-core/API design.md @@ -802,21 +802,6 @@ When updating a model, the payload for a multi-operation json patch follows the Async APIs ```java - - /** - * Decommissions a model. - * @param modelId The Id of the model to decommission. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono decommissionModel(String modelId) { } - - /** - * Decommissions a model. - * @param modelId The Id of the model to decommission. - * @return The http response. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono decommissionModelWithResponse(String modelId) { } ``` From ab5dba61ffa6fffad1cf011e22f94993bfe59831 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Mon, 31 Aug 2020 16:54:48 -0700 Subject: [PATCH 3/7] Update API design.md --- .../azure-digitaltwins-core/API design.md | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/API design.md b/sdk/digitaltwins/azure-digitaltwins-core/API design.md index 6b2b43827cd5f..5f024005ca117 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/API design.md +++ b/sdk/digitaltwins/azure-digitaltwins-core/API design.md @@ -807,23 +807,6 @@ Async APIs Sync APIs ```java - /** - - /** - * Decommissions a model. - * @param modelId The Id of the model to decommission. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Void decommissionModel(String modelId) { } - - /** - * Decommissions a model. - * @param modelId The Id of the model to decommission. - * @param context Additional context that is passed through the Http pipeline during the service call. - * @return The http response. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response decommissionModelWithResponse(String modelId, Context context) { } ``` From affd379b84e553d226ce45b53c569aca0bccb4a3 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Mon, 31 Aug 2020 16:59:13 -0700 Subject: [PATCH 4/7] use method reference when applicable. --- .../azure/digitaltwins/core/DigitalTwinsAsyncClient.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java index d8ac1b2d92676..8f54858ee3233 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java @@ -595,7 +595,7 @@ Mono> createModelsSinglePageAsync(List models, @ServiceMethod(returns = ReturnType.SINGLE) public Mono getModel(String modelId) { return getModelWithResponse(modelId) - .map(response -> response.getValue()); + .map(Response::getValue); } /** @@ -667,7 +667,7 @@ Mono> listModelsNextSinglePageAsync(String nextLink, Co @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteModel(String modelId) { return deleteModelWithResponse(modelId) - .map(response -> response.getValue()); + .map(Response::getValue); } /** @@ -697,7 +697,7 @@ PagedFlux listRelationships(String digitalTwinId, String relationshipNam */ public Mono decommissionModel(String modelId) { return decommissionModelWithResponse(modelId) - .map(response -> response.getValue()); + .map(Response::getValue); } /** From 7f4ae9710fabb56b0b9fb0183b98df8e26557815 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Mon, 31 Aug 2020 17:01:18 -0700 Subject: [PATCH 5/7] cleanup imports --- .../com/azure/digitaltwins/core/DigitalTwinsClient.java | 1 - .../com/azure/digitaltwins/core/DigitalTwinsTestBase.java | 6 ------ 2 files changed, 7 deletions(-) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java index c2fb9cd74eb5f..5c5b54294ac3c 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java @@ -15,7 +15,6 @@ import com.azure.digitaltwins.core.models.ModelData; import com.azure.digitaltwins.core.util.DigitalTwinsResponse; import com.azure.digitaltwins.core.util.ListModelOptions; -import reactor.core.publisher.Mono; import java.util.List; diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/DigitalTwinsTestBase.java b/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/DigitalTwinsTestBase.java index 4f9396d5be0e7..258df31566766 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/DigitalTwinsTestBase.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/test/java/com/azure/digitaltwins/core/DigitalTwinsTestBase.java @@ -3,18 +3,12 @@ import com.azure.core.credential.AccessToken; import com.azure.core.credential.TokenCredential; import com.azure.core.credential.TokenRequestContext; -import com.azure.core.http.policy.HttpLogDetailLevel; -import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.test.TestBase; -import com.azure.core.test.TestMode; import com.azure.core.util.Configuration; -import com.azure.core.util.logging.ClientLogger; import com.azure.identity.ClientSecretCredentialBuilder; import reactor.core.publisher.Mono; -import java.util.Locale; - public class DigitalTwinsTestBase extends TestBase { protected static final String TENANT_ID = Configuration.getGlobalConfiguration() From c4286605cf8d80d55d136b73ee0323cada3c6a12 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Mon, 31 Aug 2020 17:11:11 -0700 Subject: [PATCH 6/7] Update DigitalTwinsClient.java --- .../com/azure/digitaltwins/core/DigitalTwinsClient.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java index 5c5b54294ac3c..79208aadc9df2 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java @@ -350,8 +350,8 @@ public PagedIterable listModels() { * @return Void */ @ServiceMethod(returns = ReturnType.SINGLE) - public Void deleteModel(String modelId) { - return digitalTwinsAsyncClient.deleteModel(modelId).block(); + public void deleteModel(String modelId) { + deleteModelWithResponse(modelId, Context.NONE); } /** @@ -370,8 +370,8 @@ public Response deleteModelWithResponse(String modelId, Context context) { * @param modelId The Id of the model to decommission. * @return Void */ - public Void decommissionModel(String modelId) { - return digitalTwinsAsyncClient.decommissionModel(modelId).block(); + public void decommissionModel(String modelId) { + decommissionModelWithResponse(modelId, Context.NONE); } /** From 16c1414e935ac10f7bf21fbe03d8654d115e1eb0 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Mon, 31 Aug 2020 17:21:28 -0700 Subject: [PATCH 7/7] Update DigitalTwinsClient.java --- .../java/com/azure/digitaltwins/core/DigitalTwinsClient.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java index 79208aadc9df2..8cfb8965635c8 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/DigitalTwinsClient.java @@ -347,7 +347,6 @@ public PagedIterable listModels() { /** * Deletes a model. * @param modelId The Id for the model. The Id is globally unique and case sensitive. - * @return Void */ @ServiceMethod(returns = ReturnType.SINGLE) public void deleteModel(String modelId) { @@ -368,7 +367,6 @@ public Response deleteModelWithResponse(String modelId, Context context) { /** * Decommissions a model. * @param modelId The Id of the model to decommission. - * @return Void */ public void decommissionModel(String modelId) { decommissionModelWithResponse(modelId, Context.NONE); @@ -377,6 +375,7 @@ public void decommissionModel(String modelId) { /** * Decommissions a model. * @param modelId The Id of the model to decommission. + * @param context Additional context that is passed through the Http pipeline during the service call. * @return The http response. */ public Response decommissionModelWithResponse(String modelId, Context context) {