From 465543c6db0960703866f987d95f27ffe4f96288 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Thu, 27 Aug 2020 14:41:15 -0700 Subject: [PATCH 01/15] Implement ListModels API --- .../azure-digitaltwins-core/API design.md | 42 ++++------ .../core/DigitalTwinsAsyncClient.java | 56 +++++++++++++ .../core/util/ListModelOptions.java | 79 +++++++++++++++++++ 3 files changed, 151 insertions(+), 26 deletions(-) create mode 100644 sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/util/ListModelOptions.java diff --git a/sdk/digitaltwins/azure-digitaltwins-core/API design.md b/sdk/digitaltwins/azure-digitaltwins-core/API design.md index 1ae87eee05c02..3d5169d614d4e 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/API design.md +++ b/sdk/digitaltwins/azure-digitaltwins-core/API design.md @@ -1178,18 +1178,10 @@ Async APIs /** * Creates one or many models. * @param models The list of models to create. Each string corresponds to exactly one model. - * @return The list of created models + * @return A {@link PagedFlux} of created models. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public Mono> createModels(List models) { } - - /** - * Creates one or many models. - * @param models The list of models to create. Each string corresponds to exactly one model. - * @return A REST response containing the list of created models. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public Mono>> createModelsWithResponse(List models) { } + public PagedFlux createModels(Iterable models) { } /** * Gets a model, including the model metadata and the model definition. @@ -1206,16 +1198,22 @@ Async APIs */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getModelWithResponse(String modelId) { } - + + // TODO: all 3 optional parameters need to wrapped in a listOptions class and the input of this method will be a single wrapper object. /** * Gets the list of models by iterating through a collection. - * @param dependenciesFor The model Ids to have dependencies retrieved. - * @param includeModelDefinition Whether to include the model definition in the result. If false, only the model metadata will be returned. - * @param options The options to follow when listing the models. For example, the page size hint can be specified. * @return A {@link PagedFlux} of ModelData. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux listModels(List dependenciesFor, boolean includeModelDefinition, DigitalTwinModelsListOptions options) { } + public PagedFlux listModels() { } + + /** + * Gets the list of models by iterating through a collection. + * @param listModelOptions The options to follow when listing the models. For example, the page size hint can be specified. + * @return A {@link PagedFlux} of ModelData. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listModels(ListModelOptions listModelOptions) { } /** * Deletes a model. @@ -1254,18 +1252,10 @@ Sync APIs /** * Creates one or many models. * @param models The list of models to create. Each string corresponds to exactly one model. - * @return The list of created models - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public List createModels(List models) { } - - /** - * Creates one or many models. - * @param models The list of models to create. Each string corresponds to exactly one model. - * @return A REST response containing the list of created models. + * @return A {@link PagedIterable} of created ModelData. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public Response> createModelsWithResponse(List models, Context context) { } + public PagedIterable createModels(Iterable models, Context context) { } /** * Gets a model, including the model metadata and the model definition. @@ -1291,7 +1281,7 @@ Sync APIs * @return A {@link PagedIterable} of ModelData. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable listModels(List dependenciesFor, boolean includeModelDefinition, DigitalTwinModelsListOptions options, Context context) { } + public PagedIterable listModels(Iterable dependenciesFor, boolean includeModelDefinition, DigitalTwinModelsListOptions options, Context context) { } /** * Deletes a model. 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 6b24eeda5dfc9..431fab3d1339e 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 @@ -13,14 +13,18 @@ import com.azure.core.util.serializer.JacksonAdapter; import com.azure.digitaltwins.core.implementation.AzureDigitalTwinsAPIImpl; import com.azure.digitaltwins.core.implementation.AzureDigitalTwinsAPIImplBuilder; +import com.azure.digitaltwins.core.implementation.models.DigitalTwinModelsListOptions; +import com.azure.digitaltwins.core.models.ModelData; import com.azure.digitaltwins.core.util.DigitalTwinsResponse; import com.azure.digitaltwins.core.util.DigitalTwinsResponseHeaders; import com.azure.digitaltwins.core.implementation.serializer.DigitalTwinsStringSerializer; +import com.azure.digitaltwins.core.util.ListModelOptions; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import reactor.core.publisher.Mono; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.function.Function; @@ -228,4 +232,56 @@ Mono> listRelationshipsNextSinglePageAsync(String nextLink }); } + /** + * Gets the list of models by iterating through a collection. + * @param listModelOptions The options for the list operation. + * @return A {@link PagedFlux} of ModelData. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listModels(ListModelOptions listModelOptions) { + Supplier>> firstPage = () -> protocolLayer.getDigitalTwinModels().listSinglePageAsync( + (List) listModelOptions.getDependenciesFor(), + listModelOptions.getIncludeModelDefinition(), + new DigitalTwinModelsListOptions().setMaxItemCount(listModelOptions.getMaxItemCount())) + .map( + objectPagedResponse -> { + List modelList = objectPagedResponse.getValue().stream() + .filter(Objects::nonNull) + .collect(Collectors.toList()); + return new PagedResponseBase<>( + objectPagedResponse.getRequest(), + objectPagedResponse.getStatusCode(), + objectPagedResponse.getHeaders(), + modelList, + objectPagedResponse.getContinuationToken(), + ((PagedResponseBase) objectPagedResponse).getDeserializedHeaders()); + } + ); + + Function>> nextPage = nextLink -> protocolLayer.getDigitalTwinModels().listNextSinglePageAsync(nextLink) + .map(objectPagedResponse -> { + List modelList = objectPagedResponse.getValue().stream() + .filter(Objects::nonNull) + .collect(Collectors.toList()); + return new PagedResponseBase<>( + objectPagedResponse.getRequest(), + objectPagedResponse.getStatusCode(), + objectPagedResponse.getHeaders(), + modelList, + objectPagedResponse.getContinuationToken(), + ((PagedResponseBase)objectPagedResponse).getDeserializedHeaders()); + }); + + return new PagedFlux<>(firstPage, nextPage); + } + + /** + * Gets the list of models by iterating through a collection. + * @return A {@link PagedFlux} of ModelData. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listModels() { + return listModels(new ListModelOptions()); + } + } diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/util/ListModelOptions.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/util/ListModelOptions.java new file mode 100644 index 0000000000000..6acf0ac7db4a6 --- /dev/null +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/util/ListModelOptions.java @@ -0,0 +1,79 @@ +package com.azure.digitaltwins.core.util; + +import com.azure.core.annotation.Fluent; + +@Fluent +public final class ListModelOptions { + + /* + * The maximum number of items to retrieve per request. The server may + * choose to return less than the requested max. + */ + private Integer maxItemCount; + + /** + * Get the maxItemCount property. + * + * @return the maxItemCount value. + */ + public Integer getMaxItemCount() { + return this.maxItemCount; + } + + /** + * Set the maxItemCount property. + * + * @param maxItemCount the maxItemCount value to set. + * @return the ListModelOptions object itself. + */ + public ListModelOptions setMaxItemCount(Integer maxItemCount) { + this.maxItemCount = maxItemCount; + return this; + } + + /* + * Whether to include the model definition in the result. If false, only the model metadata will be returned. + */ + private Boolean includeModelDefinition; + + /** + * Get the includeModelDefinition property. + * + * @return the includeModelDefinition value. + */ + public Boolean getIncludeModelDefinition() { return this.includeModelDefinition; } + + /** + * Set the includeModelDefinition property. + * + * @param includeModelDefinition the includeModelDefinition value to set. + * @return the ListModelOptions object itself. + */ + public ListModelOptions setIncludeModelDefinition(Boolean includeModelDefinition) { + this.includeModelDefinition = includeModelDefinition; + return this; + } + + /* + * The model Ids to have dependencies retrieved. + */ + private Iterable dependenciesFor; + + /** + * Get the dependenciesFor property. + * + * @return the dependenciesFor value. + */ + public Iterable getDependenciesFor() { return this.dependenciesFor; } + + /** + * Set the dependenciesFor property. + * + * @param dependenciesFor the dependenciesFor value to set. + * @return the ListModelOptions object itself. + */ + public ListModelOptions setDependenciesFor(Iterable dependenciesFor) { + this.dependenciesFor = dependenciesFor; + return this; + } +} From cd664bca8c439b5212b7fb9fee50692bff407e4b Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Thu, 27 Aug 2020 14:42:34 -0700 Subject: [PATCH 02/15] Update API design.md --- sdk/digitaltwins/azure-digitaltwins-core/API design.md | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/API design.md b/sdk/digitaltwins/azure-digitaltwins-core/API design.md index 3d5169d614d4e..c84d9dc02ae38 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/API design.md +++ b/sdk/digitaltwins/azure-digitaltwins-core/API design.md @@ -1199,7 +1199,6 @@ Async APIs @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getModelWithResponse(String modelId) { } - // TODO: all 3 optional parameters need to wrapped in a listOptions class and the input of this method will be a single wrapper object. /** * Gets the list of models by iterating through a collection. * @return A {@link PagedFlux} of ModelData. From 73ff14cf546c344aedc289620ff51ef2b925a575 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Thu, 27 Aug 2020 15:42:19 -0700 Subject: [PATCH 03/15] Update DigitalTwinsAsyncClient.java --- .../core/DigitalTwinsAsyncClient.java | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 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 431fab3d1339e..f8c1521b70838 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 @@ -232,6 +232,23 @@ Mono> listRelationshipsNextSinglePageAsync(String nextLink }); } + + //================================================================================================================================================== + // Models APIs + //================================================================================================================================================== + +/* *//** + * Creates one or many models. + * @param models The list of models to create. Each string corresponds to exactly one model. + * @return A {@link PagedFlux} of created models. + *//* + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux createModels(List models) + { + protocolLayer.getDigitalTwinModels().addWithResponseAsync(() + .map() + }*/ + /** * Gets the list of models by iterating through a collection. * @param listModelOptions The options for the list operation. @@ -242,35 +259,9 @@ public PagedFlux listModels(ListModelOptions listModelOptions) { Supplier>> firstPage = () -> protocolLayer.getDigitalTwinModels().listSinglePageAsync( (List) listModelOptions.getDependenciesFor(), listModelOptions.getIncludeModelDefinition(), - new DigitalTwinModelsListOptions().setMaxItemCount(listModelOptions.getMaxItemCount())) - .map( - objectPagedResponse -> { - List modelList = objectPagedResponse.getValue().stream() - .filter(Objects::nonNull) - .collect(Collectors.toList()); - return new PagedResponseBase<>( - objectPagedResponse.getRequest(), - objectPagedResponse.getStatusCode(), - objectPagedResponse.getHeaders(), - modelList, - objectPagedResponse.getContinuationToken(), - ((PagedResponseBase) objectPagedResponse).getDeserializedHeaders()); - } - ); + new DigitalTwinModelsListOptions().setMaxItemCount(listModelOptions.getMaxItemCount())); - Function>> nextPage = nextLink -> protocolLayer.getDigitalTwinModels().listNextSinglePageAsync(nextLink) - .map(objectPagedResponse -> { - List modelList = objectPagedResponse.getValue().stream() - .filter(Objects::nonNull) - .collect(Collectors.toList()); - return new PagedResponseBase<>( - objectPagedResponse.getRequest(), - objectPagedResponse.getStatusCode(), - objectPagedResponse.getHeaders(), - modelList, - objectPagedResponse.getContinuationToken(), - ((PagedResponseBase)objectPagedResponse).getDeserializedHeaders()); - }); + Function>> nextPage = nextLink -> protocolLayer.getDigitalTwinModels().listNextSinglePageAsync(nextLink); return new PagedFlux<>(firstPage, nextPage); } @@ -283,5 +274,4 @@ public PagedFlux listModels(ListModelOptions listModelOptions) { public PagedFlux listModels() { return listModels(new ListModelOptions()); } - } From 5468f61e5df61a235f56b6ba0eb2d582328f3d5c Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Thu, 27 Aug 2020 16:10:38 -0700 Subject: [PATCH 04/15] Add createModels API --- .../core/DigitalTwinsAsyncClient.java | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 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 f8c1521b70838..3d752a5f42057 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 @@ -237,17 +237,38 @@ Mono> listRelationshipsNextSinglePageAsync(String nextLink // Models APIs //================================================================================================================================================== -/* *//** + /** * Creates one or many models. * @param models The list of models to create. Each string corresponds to exactly one model. * @return A {@link PagedFlux} of created models. - *//* + */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux createModels(List models) - { - protocolLayer.getDigitalTwinModels().addWithResponseAsync(() - .map() - }*/ + public PagedFlux createModels(List models) { + List modelsPayload = new ArrayList<>(); + for (String model: models) { + try { + modelsPayload.add(mapper.readValue(model, Object.class)); + } + catch (JsonProcessingException e) { + logger.error("Could not parse the model payload [%s]: %s", model, e); + return null; + } + } + + Supplier>> firstPage = () -> protocolLayer.getDigitalTwinModels().addWithResponseAsync(modelsPayload) + .map( + listResponse -> new PagedResponseBase<>( + listResponse.getRequest(), + listResponse.getStatusCode(), + listResponse.getHeaders(), + listResponse.getValue(), + null, + ((ResponseBase)listResponse).getDeserializedHeaders())); + + Function>> nextPage = nextLink -> null; + + return new PagedFlux<>(firstPage, nextPage); + } /** * Gets the list of models by iterating through a collection. From 7835323364123b3c4c39a3e7ef5444cd71fbf6f3 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Thu, 27 Aug 2020 16:19:22 -0700 Subject: [PATCH 05/15] Minor fix to the next link --- .../com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3d752a5f42057..1581141429298 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 @@ -265,7 +265,7 @@ public PagedFlux createModels(List models) { null, ((ResponseBase)listResponse).getDeserializedHeaders())); - Function>> nextPage = nextLink -> null; + Function>> nextPage = nextLink -> Mono.empty(); return new PagedFlux<>(firstPage, nextPage); } From 68a49c1dc7987b034adcc1c4a9a1d4f48b6c694a Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Thu, 27 Aug 2020 17:01:18 -0700 Subject: [PATCH 06/15] Implement Async getModel apis --- .../core/DigitalTwinsAsyncClient.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 1581141429298..a2464efd1b418 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 @@ -52,6 +52,7 @@ public final class DigitalTwinsAsyncClient { private static final ObjectMapper mapper = new ObjectMapper(); private final DigitalTwinsServiceVersion serviceVersion; private final AzureDigitalTwinsAPIImpl protocolLayer; + private static final Boolean includeModelDefinition = true; DigitalTwinsAsyncClient(HttpPipeline pipeline, DigitalTwinsServiceVersion serviceVersion, String host) { final SimpleModule stringModule = new SimpleModule("String Serializer"); @@ -236,7 +237,6 @@ Mono> listRelationshipsNextSinglePageAsync(String nextLink //================================================================================================================================================== // Models APIs //================================================================================================================================================== - /** * Creates one or many models. * @param models The list of models to create. Each string corresponds to exactly one model. @@ -270,6 +270,29 @@ public PagedFlux createModels(List models) { return new PagedFlux<>(firstPage, nextPage); } + /** + * Gets a model, including the model metadata and the model definition. + * @param modelId The Id of the model. + * @return The application/json model + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getModel(String modelId) { + return protocolLayer.getDigitalTwinModels().getByIdWithResponseAsync(modelId, includeModelDefinition) + .flatMap(modelDataResponse -> Mono.just(mapper.convertValue(modelDataResponse.getValue(), ModelData.class))); + } + + /** + * Gets a model, including the model metadata and the model definition. + * @param modelId The Id of the model. + * @return The application/json model + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getModelWithResponse(String modelId) { + return protocolLayer + .getDigitalTwinModels() + .getByIdWithResponseAsync(modelId, includeModelDefinition); + } + /** * Gets the list of models by iterating through a collection. * @param listModelOptions The options for the list operation. From a5abc00fea8f016b8b4e4e1d839f194313e84391 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Thu, 27 Aug 2020 17:41:19 -0700 Subject: [PATCH 07/15] Rebase master, implement context --- .../core/DigitalTwinsAsyncClient.java | 63 +++++++++++++++---- 1 file changed, 50 insertions(+), 13 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 a2464efd1b418..1a3187473f8ab 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 @@ -237,6 +237,7 @@ Mono> listRelationshipsNextSinglePageAsync(String nextLink //================================================================================================================================================== // Models APIs //================================================================================================================================================== + /** * Creates one or many models. * @param models The list of models to create. Each string corresponds to exactly one model. @@ -244,6 +245,19 @@ Mono> listRelationshipsNextSinglePageAsync(String nextLink */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux createModels(List models) { + return new PagedFlux<>( + () -> withContext(context -> createModelsSinglePageAsync(models, context)), + nextLink -> withContext(context -> Mono.empty())); + } + + PagedFlux createModels(List models, Context context){ + return new PagedFlux<>( + () -> createModelsSinglePageAsync(models, context), + nextLink -> Mono.empty()); + } + + Mono> createModelsSinglePageAsync(List models, Context context) + { List modelsPayload = new ArrayList<>(); for (String model: models) { try { @@ -255,7 +269,7 @@ public PagedFlux createModels(List models) { } } - Supplier>> firstPage = () -> protocolLayer.getDigitalTwinModels().addWithResponseAsync(modelsPayload) + return protocolLayer.getDigitalTwinModels().addWithResponseAsync(modelsPayload, context) .map( listResponse -> new PagedResponseBase<>( listResponse.getRequest(), @@ -264,10 +278,6 @@ public PagedFlux createModels(List models) { listResponse.getValue(), null, ((ResponseBase)listResponse).getDeserializedHeaders())); - - Function>> nextPage = nextLink -> Mono.empty(); - - return new PagedFlux<>(firstPage, nextPage); } /** @@ -277,7 +287,11 @@ public PagedFlux createModels(List models) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getModel(String modelId) { - return protocolLayer.getDigitalTwinModels().getByIdWithResponseAsync(modelId, includeModelDefinition) + return withContext(context -> getModel(modelId, context)); + } + + Mono getModel(String modelId, Context context){ + return protocolLayer.getDigitalTwinModels().getByIdWithResponseAsync(modelId, includeModelDefinition, context) .flatMap(modelDataResponse -> Mono.just(mapper.convertValue(modelDataResponse.getValue(), ModelData.class))); } @@ -288,9 +302,13 @@ public Mono getModel(String modelId) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getModelWithResponse(String modelId) { + return withContext(context -> getModelWithResponse(modelId, context)); + } + + Mono> getModelWithResponse(String modelId, Context context){ return protocolLayer .getDigitalTwinModels() - .getByIdWithResponseAsync(modelId, includeModelDefinition); + .getByIdWithResponseAsync(modelId, includeModelDefinition, context); } /** @@ -300,14 +318,27 @@ public Mono> getModelWithResponse(String modelId) { */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listModels(ListModelOptions listModelOptions) { - Supplier>> firstPage = () -> protocolLayer.getDigitalTwinModels().listSinglePageAsync( - (List) listModelOptions.getDependenciesFor(), - listModelOptions.getIncludeModelDefinition(), - new DigitalTwinModelsListOptions().setMaxItemCount(listModelOptions.getMaxItemCount())); + return new PagedFlux<>( + () -> withContext(context -> listModelsSinglePageAsync(listModelOptions, context)), + nextLink -> withContext(context -> listModelsNextSinglePageAsync(nextLink, context))); + } + + PagedFlux listModels(ListModelOptions listModelOptions, Context context){ + return new PagedFlux<>( + () -> listModelsSinglePageAsync(listModelOptions, context), + nextLink -> listModelsNextSinglePageAsync(nextLink, context)); + } - Function>> nextPage = nextLink -> protocolLayer.getDigitalTwinModels().listNextSinglePageAsync(nextLink); + Mono> listModelsSinglePageAsync(ListModelOptions listModelOptions, Context context){ + return protocolLayer.getDigitalTwinModels().listSinglePageAsync( + (List) listModelOptions.getDependenciesFor(), + listModelOptions.getIncludeModelDefinition(), + new DigitalTwinModelsListOptions().setMaxItemCount(listModelOptions.getMaxItemCount()), + context); + } - return new PagedFlux<>(firstPage, nextPage); + Mono> listModelsNextSinglePageAsync(String nextLink, Context context){ + return protocolLayer.getDigitalTwinModels().listNextSinglePageAsync(nextLink, context); } /** @@ -318,4 +349,10 @@ public PagedFlux listModels(ListModelOptions listModelOptions) { public PagedFlux listModels() { return listModels(new ListModelOptions()); } + + PagedFlux listModels(Context context){ + return new PagedFlux<>( + () -> listModelsSinglePageAsync(new ListModelOptions(), context), + nextLink -> listModelsNextSinglePageAsync(nextLink, context)); + } } From cf7d079daf0592cda83b1530c10b02e58503c2cd Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Thu, 27 Aug 2020 17:48:23 -0700 Subject: [PATCH 08/15] Update DigitalTwinsAsyncClient.java --- .../com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java | 5 +++-- 1 file changed, 3 insertions(+), 2 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 1a3187473f8ab..b1b5a2b80adfe 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 @@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.ArrayList; @@ -237,7 +238,7 @@ Mono> listRelationshipsNextSinglePageAsync(String nextLink //================================================================================================================================================== // Models APIs //================================================================================================================================================== - + /** * Creates one or many models. * @param models The list of models to create. Each string corresponds to exactly one model. @@ -265,7 +266,7 @@ Mono> createModelsSinglePageAsync(List models, } catch (JsonProcessingException e) { logger.error("Could not parse the model payload [%s]: %s", model, e); - return null; + return Mono.error(e); } } From 6954b7b7c58a096c1bbc58440444e72dd8db0abb Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Fri, 28 Aug 2020 09:29:05 -0700 Subject: [PATCH 09/15] Address comments. --- .../core/DigitalTwinsAsyncClient.java | 20 ++++++++----------- .../core/util/ListModelOptions.java | 8 +++++--- 2 files changed, 13 insertions(+), 15 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 b1b5a2b80adfe..cc5542d8e95ad 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 @@ -242,7 +242,7 @@ Mono> listRelationshipsNextSinglePageAsync(String nextLink /** * Creates one or many models. * @param models The list of models to create. Each string corresponds to exactly one model. - * @return A {@link PagedFlux} of created models. + * @return A {@link PagedFlux} of created models and the http response. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux createModels(List models) { @@ -284,22 +284,18 @@ Mono> createModelsSinglePageAsync(List models, /** * Gets a model, including the model metadata and the model definition. * @param modelId The Id of the model. - * @return The application/json model + * @return The ModelData */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getModel(String modelId) { - return withContext(context -> getModel(modelId, context)); - } - - Mono getModel(String modelId, Context context){ - return protocolLayer.getDigitalTwinModels().getByIdWithResponseAsync(modelId, includeModelDefinition, context) - .flatMap(modelDataResponse -> Mono.just(mapper.convertValue(modelDataResponse.getValue(), ModelData.class))); + return withContext(context -> getModelWithResponse(modelId, context)) + .flatMap(response -> Mono.just(response.getValue())); } /** * Gets a model, including the model metadata and the model definition. * @param modelId The Id of the model. - * @return The application/json model + * @return The ModelData and the http response. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getModelWithResponse(String modelId) { @@ -315,7 +311,7 @@ Mono> getModelWithResponse(String modelId, Context context){ /** * Gets the list of models by iterating through a collection. * @param listModelOptions The options for the list operation. - * @return A {@link PagedFlux} of ModelData. + * @return A {@link PagedFlux} of ModelData and the http response.. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listModels(ListModelOptions listModelOptions) { @@ -332,7 +328,7 @@ PagedFlux listModels(ListModelOptions listModelOptions, Context conte Mono> listModelsSinglePageAsync(ListModelOptions listModelOptions, Context context){ return protocolLayer.getDigitalTwinModels().listSinglePageAsync( - (List) listModelOptions.getDependenciesFor(), + listModelOptions.getDependenciesFor(), listModelOptions.getIncludeModelDefinition(), new DigitalTwinModelsListOptions().setMaxItemCount(listModelOptions.getMaxItemCount()), context); @@ -344,7 +340,7 @@ Mono> listModelsNextSinglePageAsync(String nextLink, Co /** * Gets the list of models by iterating through a collection. - * @return A {@link PagedFlux} of ModelData. + * @return A {@link PagedFlux} of ModelData and the http response.. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listModels() { diff --git a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/util/ListModelOptions.java b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/util/ListModelOptions.java index 6acf0ac7db4a6..e63131a3e4330 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/util/ListModelOptions.java +++ b/sdk/digitaltwins/azure-digitaltwins-core/src/main/java/com/azure/digitaltwins/core/util/ListModelOptions.java @@ -2,6 +2,8 @@ import com.azure.core.annotation.Fluent; +import java.util.List; + @Fluent public final class ListModelOptions { @@ -57,14 +59,14 @@ public ListModelOptions setIncludeModelDefinition(Boolean includeModelDefinition /* * The model Ids to have dependencies retrieved. */ - private Iterable dependenciesFor; + private List dependenciesFor; /** * Get the dependenciesFor property. * * @return the dependenciesFor value. */ - public Iterable getDependenciesFor() { return this.dependenciesFor; } + public List getDependenciesFor() { return this.dependenciesFor; } /** * Set the dependenciesFor property. @@ -72,7 +74,7 @@ public ListModelOptions setIncludeModelDefinition(Boolean includeModelDefinition * @param dependenciesFor the dependenciesFor value to set. * @return the ListModelOptions object itself. */ - public ListModelOptions setDependenciesFor(Iterable dependenciesFor) { + public ListModelOptions setDependenciesFor(List dependenciesFor) { this.dependenciesFor = dependenciesFor; return this; } From 9f0dd6798540a26962775677ce7686b9c8549e96 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Fri, 28 Aug 2020 09:34:34 -0700 Subject: [PATCH 10/15] Update comments. --- .../azure-digitaltwins-core/API design.md | 12 ++++++------ .../digitaltwins/core/DigitalTwinsAsyncClient.java | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/API design.md b/sdk/digitaltwins/azure-digitaltwins-core/API design.md index c84d9dc02ae38..f889f46a478e8 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/API design.md +++ b/sdk/digitaltwins/azure-digitaltwins-core/API design.md @@ -1178,15 +1178,15 @@ Async APIs /** * Creates one or many models. * @param models The list of models to create. Each string corresponds to exactly one model. - * @return A {@link PagedFlux} of created models. + * @return A {@link PagedFlux} of created models and the http response. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux createModels(Iterable models) { } + public PagedFlux createModels(List models) { } /** * Gets a model, including the model metadata and the model definition. * @param modelId The Id of the model. - * @return The application/json model + * @return The ModelData */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getModel(String modelId) { } @@ -1194,14 +1194,14 @@ Async APIs /** * Gets a model, including the model metadata and the model definition asynchronously. * @param modelId The Id of the model. - * @return A REST response containing the model. + * @return The ModelData and the http response */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getModelWithResponse(String modelId) { } /** * Gets the list of models by iterating through a collection. - * @return A {@link PagedFlux} of ModelData. + * @return A {@link PagedFlux} of ModelData and the http response. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listModels() { } @@ -1209,7 +1209,7 @@ Async APIs /** * Gets the list of models by iterating through a collection. * @param listModelOptions The options to follow when listing the models. For example, the page size hint can be specified. - * @return A {@link PagedFlux} of ModelData. + * @return A {@link PagedFlux} of ModelData and the http response. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listModels(ListModelOptions listModelOptions) { } 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 cc5542d8e95ad..edf54072f5435 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 @@ -295,7 +295,7 @@ public Mono getModel(String modelId) { /** * Gets a model, including the model metadata and the model definition. * @param modelId The Id of the model. - * @return The ModelData and the http response. + * @return The ModelData and the http response */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getModelWithResponse(String modelId) { @@ -310,8 +310,8 @@ Mono> getModelWithResponse(String modelId, Context context){ /** * Gets the list of models by iterating through a collection. - * @param listModelOptions The options for the list operation. - * @return A {@link PagedFlux} of ModelData and the http response.. + * @param listModelOptions The options to follow when listing the models. For example, the page size hint can be specified. + * @return A {@link PagedFlux} of ModelData and the http response. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listModels(ListModelOptions listModelOptions) { @@ -340,7 +340,7 @@ Mono> listModelsNextSinglePageAsync(String nextLink, Co /** * Gets the list of models by iterating through a collection. - * @return A {@link PagedFlux} of ModelData and the http response.. + * @return A {@link PagedFlux} of ModelData and the http response. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listModels() { From 6efdd3acc26c5b46c3894aec029730eb05457aea Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Fri, 28 Aug 2020 13:04:38 -0700 Subject: [PATCH 11/15] Implement deleteModels --- .../core/DigitalTwinsAsyncClient.java | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 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 edf54072f5435..52116519b5fa0 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 @@ -320,6 +320,21 @@ public PagedFlux listModels(ListModelOptions listModelOptions) { nextLink -> withContext(context -> listModelsNextSinglePageAsync(nextLink, context))); } + /** + * Gets the list of models by iterating through a collection. + * @return A {@link PagedFlux} of ModelData and the http response. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listModels() { + return listModels(new ListModelOptions()); + } + + PagedFlux listModels(Context context){ + return new PagedFlux<>( + () -> listModelsSinglePageAsync(new ListModelOptions(), context), + nextLink -> listModelsNextSinglePageAsync(nextLink, context)); + } + PagedFlux listModels(ListModelOptions listModelOptions, Context context){ return new PagedFlux<>( () -> listModelsSinglePageAsync(listModelOptions, context), @@ -339,17 +354,27 @@ Mono> listModelsNextSinglePageAsync(String nextLink, Co } /** - * Gets the list of models by iterating through a collection. - * @return A {@link PagedFlux} of ModelData and the http response. + * Deletes a model. + * @param modelId The id for the model. The id is globally unique and case sensitive. */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux listModels() { - return listModels(new ListModelOptions()); + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono deleteModel(String modelId) { + return withContext(context -> deleteModelWithResponse(modelId, context)) + .flatMap(response -> Mono.just(response.getValue())); } - PagedFlux listModels(Context context){ - return new PagedFlux<>( - () -> listModelsSinglePageAsync(new ListModelOptions(), context), - nextLink -> listModelsNextSinglePageAsync(nextLink, context)); + /** + * Deletes a model. + * @param modelId The id for the model. The id is globally unique and case sensitive. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> deleteModelWithResponse(String modelId) { + return withContext(context -> deleteModelWithResponse(modelId, context)); + } + + Mono> deleteModelWithResponse(String modelId, Context context){ + return protocolLayer.getDigitalTwinModels().deleteWithResponseAsync(modelId, context); } + + //TODO: Decommission Model APIs (waiting for Abhipsa's change to come in) } From f8134cd35fa978dd34754717e2ae5695ffb4cf05 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Fri, 28 Aug 2020 13:08:06 -0700 Subject: [PATCH 12/15] fix comments. --- .../com/azure/digitaltwins/core/DigitalTwinsAsyncClient.java | 2 ++ 1 file changed, 2 insertions(+) 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 52116519b5fa0..a0829d76c068f 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 @@ -356,6 +356,7 @@ Mono> listModelsNextSinglePageAsync(String nextLink, Co /** * Deletes a model. * @param modelId The id for the model. The id is globally unique and case sensitive. + * @return An empty Mono */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteModel(String modelId) { @@ -366,6 +367,7 @@ public Mono deleteModel(String modelId) { /** * Deletes a model. * @param modelId The id for the model. The id is globally unique and case sensitive. + * @return The http response. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteModelWithResponse(String modelId) { From c0736884fcf1ebbd73b61579eb0791f4eff49604 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Fri, 28 Aug 2020 14:02:37 -0700 Subject: [PATCH 13/15] Implement Sync APIs --- .../digitaltwins/core/DigitalTwinsClient.java | 88 ++++++++++++++++++- 1 file changed, 86 insertions(+), 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 496cd1844e761..ce734b0694b76 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 @@ -7,10 +7,18 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; import com.azure.core.http.HttpPipeline; -import com.azure.core.http.rest.PagedIterable; -import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.*; import com.azure.core.util.Context; +import com.azure.digitaltwins.core.implementation.models.DigitalTwinModelsListOptions; +import com.azure.digitaltwins.core.models.ModelData; +import com.azure.digitaltwins.core.util.ListModelOptions; import com.fasterxml.jackson.core.JsonProcessingException; +import reactor.core.publisher.Mono; + +import java.util.ArrayList; +import java.util.List; + +import static com.azure.core.util.FluxUtil.withContext; /** * This class provides a client for interacting synchronously with an Azure Digital Twins instance. @@ -80,4 +88,80 @@ public Response createRelationshipWithResponse(String digitalTwinId, Str public PagedIterable listRelationships(String digitalTwinId, String relationshipName, Context context) { return new PagedIterable<>(digitalTwinsAsyncClient.listRelationships(digitalTwinId, relationshipName, context)); } + + //================================================================================================================================================== + // Models APIs + //================================================================================================================================================== + + /** + * Creates one or many models. + * @param models The list of models to create. Each string corresponds to exactly one model. + * @return A {@link PagedIterable} of created models and the http response. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable createModels(List models) { + return new PagedIterable<>(digitalTwinsAsyncClient.createModels(models)); + } + + /** + * Gets a model, including the model metadata and the model definition. + * @param modelId The Id of the model. + * @return The ModelData + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public ModelData getModel(String modelId) { + return digitalTwinsAsyncClient.getModel(modelId).block(); + } + + /** + * Gets a model, including the model metadata and the model definition. + * @param modelId The Id of the model. + * @return The ModelData and the http response + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getModelWithResponse(String modelId) { + return digitalTwinsAsyncClient.getModelWithResponse(modelId).block(); + } + + /** + * Gets the list of models by iterating through a collection. + * @param listModelOptions The options to follow when listing the models. For example, the page size hint can be specified. + * @return A {@link PagedIterable} of ModelData and the http response. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listModels(ListModelOptions listModelOptions) { + return new PagedIterable<>( + digitalTwinsAsyncClient.listModels(listModelOptions)); + } + + /** + * Gets the list of models by iterating through a collection. + * @return A {@link PagedFlux} of ModelData and the http response. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listModels() { + return listModels(new ListModelOptions()); + } + + /** + * 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(); + } + + /** + * Deletes a model. + * @param modelId The id for the model. The id is globally unique and case sensitive. + * @return The http response. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteModelWithResponse(String modelId) { + return digitalTwinsAsyncClient.deleteModelWithResponse(modelId).block(); + } + + //TODO: Decommission Model APIs (waiting for Abhipsa's change to come in) } From 36b8d0b78706ed663c4ac7683c54c341226136d8 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Fri, 28 Aug 2020 14:11:07 -0700 Subject: [PATCH 14/15] Implement contexts for sync client. --- .../digitaltwins/core/DigitalTwinsClient.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 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 ce734b0694b76..7d02ddd063bd8 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 @@ -96,11 +96,12 @@ public PagedIterable listRelationships(String digitalTwinId, String rela /** * Creates one or many models. * @param models The list of models to create. Each string corresponds to exactly one model. + * @param context Additional context that is passed through the Http pipeline during the service call. * @return A {@link PagedIterable} of created models and the http response. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable createModels(List models) { - return new PagedIterable<>(digitalTwinsAsyncClient.createModels(models)); + public PagedIterable createModels(List models, Context context) { + return new PagedIterable<>(digitalTwinsAsyncClient.createModels(models, context)); } /** @@ -116,22 +117,24 @@ public ModelData getModel(String modelId) { /** * Gets a model, including the model metadata and the model definition. * @param modelId The Id of the model. + * @param context Additional context that is passed through the Http pipeline during the service call. * @return The ModelData and the http response */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response getModelWithResponse(String modelId) { - return digitalTwinsAsyncClient.getModelWithResponse(modelId).block(); + public Response getModelWithResponse(String modelId, Context context) { + return digitalTwinsAsyncClient.getModelWithResponse(modelId, context).block(); } /** * Gets the list of models by iterating through a collection. * @param listModelOptions The options to follow when listing the models. For example, the page size hint can be specified. + * @param context Additional context that is passed through the Http pipeline during the service call. * @return A {@link PagedIterable} of ModelData and the http response. */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable listModels(ListModelOptions listModelOptions) { + public PagedIterable listModels(ListModelOptions listModelOptions, Context context) { return new PagedIterable<>( - digitalTwinsAsyncClient.listModels(listModelOptions)); + digitalTwinsAsyncClient.listModels(listModelOptions, context)); } /** @@ -140,7 +143,7 @@ public PagedIterable listModels(ListModelOptions listModelOptions) { */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listModels() { - return listModels(new ListModelOptions()); + return new PagedIterable<>(digitalTwinsAsyncClient.listModels()); } /** @@ -156,11 +159,12 @@ public Void deleteModel(String modelId) { /** * Deletes a model. * @param modelId The id for the model. The id is globally unique and case sensitive. + * @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 deleteModelWithResponse(String modelId) { - return digitalTwinsAsyncClient.deleteModelWithResponse(modelId).block(); + 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) From acb56b2cbe0719c1d5d7f2031b072394f50c14b5 Mon Sep 17 00:00:00 2001 From: Azad Abbasi Date: Fri, 28 Aug 2020 14:40:48 -0700 Subject: [PATCH 15/15] Update comments. Remove API design doc for methods that have been implemented. --- .../azure-digitaltwins-core/API design.md | 101 +----------------- .../core/DigitalTwinsAsyncClient.java | 4 +- .../digitaltwins/core/DigitalTwinsClient.java | 4 +- 3 files changed, 5 insertions(+), 104 deletions(-) diff --git a/sdk/digitaltwins/azure-digitaltwins-core/API design.md b/sdk/digitaltwins/azure-digitaltwins-core/API design.md index f889f46a478e8..1e9b645702ea4 100644 --- a/sdk/digitaltwins/azure-digitaltwins-core/API design.md +++ b/sdk/digitaltwins/azure-digitaltwins-core/API design.md @@ -1175,60 +1175,7 @@ When updating a model, the payload for a multi-operation json patch follows the Async APIs ```java - /** - * Creates one or many models. - * @param models The list of models to create. Each string corresponds to exactly one model. - * @return A {@link PagedFlux} of created models and the http response. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux createModels(List models) { } - - /** - * Gets a model, including the model metadata and the model definition. - * @param modelId The Id of the model. - * @return The ModelData - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getModel(String modelId) { } - - /** - * Gets a model, including the model metadata and the model definition asynchronously. - * @param modelId The Id of the model. - * @return The ModelData and the http response - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getModelWithResponse(String modelId) { } - - /** - * Gets the list of models by iterating through a collection. - * @return A {@link PagedFlux} of ModelData and the http response. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux listModels() { } - /** - * Gets the list of models by iterating through a collection. - * @param listModelOptions The options to follow when listing the models. For example, the page size hint can be specified. - * @return A {@link PagedFlux} of ModelData and the http response. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux listModels(ListModelOptions listModelOptions) { } - - /** - * Deletes a model. - * @param modelId The id for the model. The id is globally unique and case sensitive. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono deleteModel(String modelId) { } - - /** - * Deletes a model. - * @param modelId The id for the model. The id is globally unique and case sensitive. - * @return The http response. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono deleteModelWithResponse(String modelId) { } - /** * Decommissions a model. * @param modelId The Id of the model to decommission. @@ -1249,53 +1196,6 @@ Async APIs Sync APIs ```java /** - * Creates one or many models. - * @param models The list of models to create. Each string corresponds to exactly one model. - * @return A {@link PagedIterable} of created ModelData. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable createModels(Iterable models, Context context) { } - - /** - * Gets a model, including the model metadata and the model definition. - * @param modelId The Id of the model. - * @return The application/json model - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public ModelData getModel(String modelId) { } - - /** - * Gets a model, including the model metadata and the model definition. - * @param modelId The Id of the model. - * @return A REST response containing the model. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response getModelWithResponse(String modelId, Context context) { } - - /** - * Gets the list of models by iterating through a collection. - * @param dependenciesFor The model Ids to have dependencies retrieved. - * @param includeModelDefinition Whether to include the model definition in the result. If false, only the model metadata will be returned. - * @param options The options to follow when listing the models. For example, the page size hint can be specified. - * @return A {@link PagedIterable} of ModelData. - */ - @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable listModels(Iterable dependenciesFor, boolean includeModelDefinition, DigitalTwinModelsListOptions options, Context context) { } - - /** - * Deletes a model. - * @param modelId The id for the model. The id is globally unique and case sensitive. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono deleteModel(String modelId) { } - - /** - * Deletes a model. - * @param modelId The id for the model. The id is globally unique and case sensitive. - * @return The http response. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response deleteModelWithResponse(String modelId, Context context) { } /** * Decommissions a model. @@ -1307,6 +1207,7 @@ Sync APIs /** * 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) 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 a0829d76c068f..13b9120310c58 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 @@ -355,7 +355,7 @@ Mono> listModelsNextSinglePageAsync(String nextLink, Co /** * Deletes a model. - * @param modelId The id for the model. The id is globally unique and case sensitive. + * @param modelId The Id for the model. The Id is globally unique and case sensitive. * @return An empty Mono */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -366,7 +366,7 @@ public Mono deleteModel(String modelId) { /** * Deletes a model. - * @param modelId The id for the model. The id is globally unique and case sensitive. + * @param modelId The Id for the model. The Id is globally unique and case sensitive. * @return The http response. */ @ServiceMethod(returns = ReturnType.SINGLE) 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 7d02ddd063bd8..9aff8f0b84073 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 @@ -148,7 +148,7 @@ public PagedIterable listModels() { /** * Deletes a model. - * @param modelId The id for the model. The id is globally unique and case sensitive. + * @param modelId The Id for the model. The Id is globally unique and case sensitive. * @return Void */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -158,7 +158,7 @@ public Void deleteModel(String modelId) { /** * Deletes a model. - * @param modelId The id for the model. The id is globally unique and case sensitive. + * @param modelId The Id for the model. The Id is globally unique and case sensitive. * @param context Additional context that is passed through the Http pipeline during the service call. * @return The http response. */