Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume JsonPatchDocument from azure.core and remove UpdateOperationUtility #16883

Merged
merged 20 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sdk/digitaltwins/azure-digitaltwins-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<artifactId>azure-core-http-netty</artifactId>
<version>1.6.3</version> <!-- {x-version-update;com.azure:azure-core-http-netty;dependency} -->
</dependency>
<dependency>
azabbasi marked this conversation as resolved.
Show resolved Hide resolved
<groupId>com.azure</groupId>
<artifactId>azure-core-serializer-json-jackson</artifactId>
<version>1.1.0</version> <!-- {x-version-update;com.azure:azure-core-serializer-json-jackson;dependency} -->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.rest.*;
import com.azure.core.util.Context;
import com.azure.core.models.JsonPatchDocument;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.JsonSerializer;
Expand Down Expand Up @@ -249,11 +250,11 @@ <T> Mono<DigitalTwinsResponse<T>> getDigitalTwinWithResponse(String digitalTwinI
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param jsonPatch The JSON patch to apply to the specified digital twin.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
* @return An empty Mono
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> updateDigitalTwin(String digitalTwinId, List<Object> jsonPatch)
public Mono<Void> updateDigitalTwin(String digitalTwinId, JsonPatchDocument jsonPatch)
{
return updateDigitalTwinWithResponse(digitalTwinId, jsonPatch, null)
.flatMap(voidResponse -> Mono.empty());
Expand All @@ -270,17 +271,17 @@ public Mono<Void> updateDigitalTwin(String digitalTwinId, List<Object> jsonPatch
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param jsonPatch The JSON patch to apply to the specified digital twin.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @return A {@link DigitalTwinsResponse}
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<DigitalTwinsResponse<Void>> updateDigitalTwinWithResponse(String digitalTwinId, List<Object> jsonPatch, UpdateDigitalTwinOptions options)
public Mono<DigitalTwinsResponse<Void>> updateDigitalTwinWithResponse(String digitalTwinId, JsonPatchDocument jsonPatch, UpdateDigitalTwinOptions options)
{
return withContext(context -> updateDigitalTwinWithResponse(digitalTwinId, jsonPatch, options, context));
}

Mono<DigitalTwinsResponse<Void>> updateDigitalTwinWithResponse(String digitalTwinId, List<Object> jsonPatch, UpdateDigitalTwinOptions options, Context context) {
Mono<DigitalTwinsResponse<Void>> updateDigitalTwinWithResponse(String digitalTwinId, JsonPatchDocument jsonPatch, UpdateDigitalTwinOptions options, Context context) {
return protocolLayer
.getDigitalTwins()
.updateWithResponseAsync(digitalTwinId, jsonPatch, OptionsConverter.toProtocolLayerOptions(options), context)
Expand Down Expand Up @@ -481,11 +482,11 @@ <T> Mono<DigitalTwinsResponse<T>> getRelationshipWithResponse(String digitalTwin
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to be updated.
* @param jsonPatch The JSON patch to apply to the specified digital twin's relationship.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
* @return An empty Mono.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> updateRelationship(String digitalTwinId, String relationshipId, List<Object> jsonPatch) {
public Mono<Void> updateRelationship(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch) {
return updateRelationshipWithResponse(digitalTwinId, relationshipId, jsonPatch, null)
.flatMap(voidResponse -> Mono.empty());
}
Expand All @@ -500,16 +501,16 @@ public Mono<Void> updateRelationship(String digitalTwinId, String relationshipId
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to be updated.
* @param jsonPatch The JSON patch to apply to the specified digital twin's relationship.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @return A {@link DigitalTwinsResponse} containing no parsed payload object.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<DigitalTwinsResponse<Void>> updateRelationshipWithResponse(String digitalTwinId, String relationshipId, List<Object> jsonPatch, UpdateRelationshipOptions options) {
public Mono<DigitalTwinsResponse<Void>> updateRelationshipWithResponse(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch, UpdateRelationshipOptions options) {
return withContext(context -> updateRelationshipWithResponse(digitalTwinId, relationshipId, jsonPatch, options, context));
}

Mono<DigitalTwinsResponse<Void>> updateRelationshipWithResponse(String digitalTwinId, String relationshipId, List<Object> jsonPatch, UpdateRelationshipOptions options, Context context) {
Mono<DigitalTwinsResponse<Void>> updateRelationshipWithResponse(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch, UpdateRelationshipOptions options, Context context) {
return protocolLayer
.getDigitalTwins()
.updateRelationshipWithResponseAsync(digitalTwinId, relationshipId, jsonPatch, OptionsConverter.toProtocolLayerOptions(options), context)
Expand Down Expand Up @@ -978,9 +979,8 @@ public Mono<Response<Void>> decommissionModelWithResponse(String modelId) {
}

Mono<Response<Void>> decommissionModelWithResponse(String modelId, Context context) {
List<Object> updateOperation = new UpdateOperationUtility()
.appendReplaceOperation("/decommissioned", true)
.getUpdateOperations();
JsonPatchDocument updateOperation = new JsonPatchDocument()
.appendReplace("/decommissioned", true);

return protocolLayer.getDigitalTwinModels().updateWithResponseAsync(modelId, updateOperation, null, context);
}
Expand Down Expand Up @@ -1051,11 +1051,11 @@ <T> Mono<DigitalTwinsResponse<T>> getComponentWithResponse(String digitalTwinId,
* @param digitalTwinId The Id of the digital twin that has the component to patch.
* @param componentName The name of the component on the digital twin.
* @param jsonPatch The JSON patch to apply to the specified digital twin's relationship.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
* @return An empty Mono.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> updateComponent(String digitalTwinId, String componentName, List<Object> jsonPatch) {
public Mono<Void> updateComponent(String digitalTwinId, String componentName, JsonPatchDocument jsonPatch) {
return updateComponentWithResponse(digitalTwinId, componentName, jsonPatch, null)
.flatMap(voidResponse -> Mono.empty());
}
Expand All @@ -1070,16 +1070,16 @@ public Mono<Void> updateComponent(String digitalTwinId, String componentName, Li
* @param digitalTwinId The Id of the digital twin that has the component to patch.
* @param componentName The name of the component on the digital twin.
* @param jsonPatch The JSON patch to apply to the specified digital twin's relationship.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @return A {@link DigitalTwinsResponse} containing an empty Mono.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<DigitalTwinsResponse<Void>> updateComponentWithResponse(String digitalTwinId, String componentName, List<Object> jsonPatch, UpdateComponentOptions options) {
public Mono<DigitalTwinsResponse<Void>> updateComponentWithResponse(String digitalTwinId, String componentName, JsonPatchDocument jsonPatch, UpdateComponentOptions options) {
return withContext(context -> updateComponentWithResponse(digitalTwinId, componentName, jsonPatch, options, context));
}

Mono<DigitalTwinsResponse<Void>> updateComponentWithResponse(String digitalTwinId, String componentName, List<Object> jsonPatch, UpdateComponentOptions options, Context context) {
Mono<DigitalTwinsResponse<Void>> updateComponentWithResponse(String digitalTwinId, String componentName, JsonPatchDocument jsonPatch, UpdateComponentOptions options, Context context) {
return protocolLayer.getDigitalTwins().updateComponentWithResponseAsync(digitalTwinId, componentName, jsonPatch, OptionsConverter.toProtocolLayerOptions(options), context)
.flatMap(response -> {
DigitalTwinsResponseHeaders twinHeaders = mapper.convertValue(response.getDeserializedHeaders(), DigitalTwinsResponseHeaders.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.core.models.JsonPatchDocument;
import com.azure.digitaltwins.core.models.*;

import java.util.List;
Expand Down Expand Up @@ -168,10 +169,10 @@ public <T> DigitalTwinsResponse<T> getDigitalTwinWithResponse(String digitalTwin
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param jsonPatch The JSON patch to apply to the specified digital twin.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void updateDigitalTwin(String digitalTwinId, List<Object> jsonPatch)
public void updateDigitalTwin(String digitalTwinId, JsonPatchDocument jsonPatch)
{
updateDigitalTwinWithResponse(digitalTwinId, jsonPatch, null, Context.NONE);
}
Expand All @@ -187,13 +188,13 @@ public void updateDigitalTwin(String digitalTwinId, List<Object> jsonPatch)
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param jsonPatch The JSON patch to apply to the specified digital twin.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return A {@link DigitalTwinsResponse}
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public DigitalTwinsResponse<Void> updateDigitalTwinWithResponse(String digitalTwinId, List<Object> jsonPatch, UpdateDigitalTwinOptions options, Context context)
public DigitalTwinsResponse<Void> updateDigitalTwinWithResponse(String digitalTwinId, JsonPatchDocument jsonPatch, UpdateDigitalTwinOptions options, Context context)
{
return digitalTwinsAsyncClient.updateDigitalTwinWithResponse(digitalTwinId, jsonPatch, options, context).block();
}
Expand Down Expand Up @@ -348,10 +349,10 @@ public <T> DigitalTwinsResponse<T> getRelationshipWithResponse(String digitalTwi
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to be updated.
* @param jsonPatch The JSON patch to apply to the specified digital twin's relationship.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void updateRelationship(String digitalTwinId, String relationshipId, List<Object> jsonPatch) {
public void updateRelationship(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch) {
updateRelationshipWithResponse(digitalTwinId, relationshipId, jsonPatch, null, Context.NONE);
}

Expand All @@ -365,13 +366,13 @@ public void updateRelationship(String digitalTwinId, String relationshipId, List
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to be updated.
* @param jsonPatch The JSON patch to apply to the specified digital twin's relationship.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return A {@link DigitalTwinsResponse} containing no parsed payload object.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public DigitalTwinsResponse<Void> updateRelationshipWithResponse(String digitalTwinId, String relationshipId, List<Object> jsonPatch, UpdateRelationshipOptions options, Context context) {
public DigitalTwinsResponse<Void> updateRelationshipWithResponse(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch, UpdateRelationshipOptions options, Context context) {
return digitalTwinsAsyncClient.updateRelationshipWithResponse(digitalTwinId, relationshipId, jsonPatch, options, context).block();
}

Expand Down Expand Up @@ -701,10 +702,10 @@ public <T> DigitalTwinsResponse<T> getComponentWithResponse(String digitalTwinId
* @param digitalTwinId The Id of the digital twin that has the component to patch.
* @param componentName The name of the component on the digital twin.
* @param jsonPatch The JSON patch to apply to the specified digital twin's relationship.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void updateComponent(String digitalTwinId, String componentName, List<Object> jsonPatch) {
public void updateComponent(String digitalTwinId, String componentName, JsonPatchDocument jsonPatch) {
updateComponentWithResponse(digitalTwinId, componentName, jsonPatch, null, Context.NONE);
}

Expand All @@ -718,13 +719,13 @@ public void updateComponent(String digitalTwinId, String componentName, List<Obj
* @param digitalTwinId The Id of the digital twin that has the component to patch.
* @param componentName The name of the component on the digital twin.
* @param jsonPatch The JSON patch to apply to the specified digital twin's relationship.
* This argument can be created using {@link UpdateOperationUtility}.
* This argument can be created using {@link JsonPatchDocument}.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return A {@link DigitalTwinsResponse} containing no parsed payload object.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public DigitalTwinsResponse<Void> updateComponentWithResponse(String digitalTwinId, String componentName, List<Object> jsonPatch, UpdateComponentOptions options, Context context) {
public DigitalTwinsResponse<Void> updateComponentWithResponse(String digitalTwinId, String componentName, JsonPatchDocument jsonPatch, UpdateComponentOptions options, Context context) {
return digitalTwinsAsyncClient.updateComponentWithResponse(digitalTwinId, componentName, jsonPatch, options, context).block();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.models.JsonPatchDocument;
import com.azure.core.util.Context;
import com.azure.core.util.serializer.CollectionFormat;
import com.azure.core.util.serializer.JacksonAdapter;
Expand Down Expand Up @@ -109,7 +110,7 @@ Mono<Response<Void>> update(
@HeaderParam("tracestate") String tracestate,
@PathParam("id") String id,
@QueryParam("api-version") String apiVersion,
@BodyParam("application/json-patch+json") List<Object> updateModel,
@BodyParam("application/json-patch+json") JsonPatchDocument updateModel,
azabbasi marked this conversation as resolved.
Show resolved Hide resolved
Context context);

@Delete("/models/{id}")
Expand Down Expand Up @@ -306,7 +307,7 @@ public Mono<Response<DigitalTwinsModelData>> getByIdWithResponseAsync(
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> updateWithResponseAsync(
String id,
List<Object> updateModel,
JsonPatchDocument updateModel,
DigitalTwinModelsUpdateOptions digitalTwinModelsUpdateOptions,
Context context) {
if (this.client.getHost() == null) {
Expand Down
Loading