diff --git a/sdk/digitaltwins/azure-digitaltwins-core/API design.md b/sdk/digitaltwins/azure-digitaltwins-core/API design.md index cb386611f147d..5f024005ca117 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/API design.md +++ b/sdk/digitaltwins/azure-digitaltwins-core/API design.md @@ -802,43 +802,11 @@ 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) { } ``` 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) { } ``` 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..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 @@ -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::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::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::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..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,11 +347,10 @@ 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) { - return digitalTwinsAsyncClient.deleteModel(modelId).block(); + public void deleteModel(String modelId) { + deleteModelWithResponse(modelId, Context.NONE); } /** @@ -365,6 +364,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. + */ + public void decommissionModel(String modelId) { + decommissionModelWithResponse(modelId, Context.NONE); + } + /** + * 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) { + return digitalTwinsAsyncClient.decommissionModelWithResponse(modelId, context).block(); + } } 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()