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

Allow users to pass in their own version of IfNonMatch header #16813

Merged
merged 6 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
8 changes: 8 additions & 0 deletions sdk/digitaltwins/azure-digitaltwins-core/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ java:
custom-types-subpackage: models
required-fields-as-ctor-args: true
```
``` yaml

directive:
- from: swagger-document
azabbasi marked this conversation as resolved.
Show resolved Hide resolved
where: $..[?(@.name=='If-None-Match')]
transform: delete $.enum;

```
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ public Mono<DigitalTwinsAddResponse> addWithResponseAsync(
if (digitalTwinsAddOptions != null) {
digitalTwinsAddOptions.validate();
}
final String ifNoneMatch = "*";
String traceparentInternal = null;
if (digitalTwinsAddOptions != null) {
traceparentInternal = digitalTwinsAddOptions.getTraceparent();
Expand All @@ -363,6 +362,11 @@ public Mono<DigitalTwinsAddResponse> addWithResponseAsync(
tracestateInternal = digitalTwinsAddOptions.getTracestate();
}
String tracestate = tracestateInternal;
String ifNoneMatchInternal = null;
if (digitalTwinsAddOptions != null) {
ifNoneMatchInternal = digitalTwinsAddOptions.getIfNoneMatch();
}
String ifNoneMatch = ifNoneMatchInternal;
return service.add(
this.client.getHost(),
traceparent,
Expand Down Expand Up @@ -574,7 +578,6 @@ public Mono<DigitalTwinsAddRelationshipResponse> addRelationshipWithResponseAsyn
if (digitalTwinsAddRelationshipOptions != null) {
digitalTwinsAddRelationshipOptions.validate();
}
final String ifNoneMatch = "*";
String traceparentInternal = null;
if (digitalTwinsAddRelationshipOptions != null) {
traceparentInternal = digitalTwinsAddRelationshipOptions.getTraceparent();
Expand All @@ -585,6 +588,11 @@ public Mono<DigitalTwinsAddRelationshipResponse> addRelationshipWithResponseAsyn
tracestateInternal = digitalTwinsAddRelationshipOptions.getTracestate();
}
String tracestate = tracestateInternal;
String ifNoneMatchInternal = null;
if (digitalTwinsAddRelationshipOptions != null) {
ifNoneMatchInternal = digitalTwinsAddRelationshipOptions.getIfNoneMatch();
}
String ifNoneMatch = ifNoneMatchInternal;
return service.addRelationship(
this.client.getHost(),
traceparent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ public static DigitalTwinsAddOptions toProtocolLayerOptions(CreateDigitalTwinOpt
return null;
}

return new DigitalTwinsAddOptions().setTraceparent(options.getTraceParent()).setTracestate(options.getTraceState());
return new DigitalTwinsAddOptions()
.setTraceparent(options.getTraceParent())
.setTracestate(options.getTraceState())
.setIfNoneMatch(options.getIfNoneMatch());
}

public static DigitalTwinsAddRelationshipOptions toProtocolLayerOptions(CreateRelationshipOptions options) {
if (options == null) {
return null;
}

return new DigitalTwinsAddRelationshipOptions().setTraceparent(options.getTraceParent()).setTracestate(options.getTraceState());
return new DigitalTwinsAddRelationshipOptions()
.setTraceparent(options.getTraceParent())
.setTracestate(options.getTraceState())
.setIfNoneMatch(options.getIfNoneMatch());
}

public static DigitalTwinModelsAddOptions toProtocolLayerOptions(CreateModelsOptions options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public final class DigitalTwinsAddOptions {
@JsonProperty(value = "tracestate")
private String tracestate;

/*
* Only perform the operation if the entity does not already exist.
*/
@JsonProperty(value = "If-None-Match")
private String ifNoneMatch;

/**
* Get the traceparent property: Identifies the request in a distributed tracing system.
*
Expand Down Expand Up @@ -65,6 +71,26 @@ public DigitalTwinsAddOptions setTracestate(String tracestate) {
return this;
}

/**
* Get the ifNoneMatch property: Only perform the operation if the entity does not already exist.
*
* @return the ifNoneMatch value.
*/
public String getIfNoneMatch() {
return this.ifNoneMatch;
}

/**
* Set the ifNoneMatch property: Only perform the operation if the entity does not already exist.
*
* @param ifNoneMatch the ifNoneMatch value to set.
* @return the DigitalTwinsAddOptions object itself.
*/
public DigitalTwinsAddOptions setIfNoneMatch(String ifNoneMatch) {
this.ifNoneMatch = ifNoneMatch;
return this;
}

/**
* Validates the instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public final class DigitalTwinsAddRelationshipOptions {
@JsonProperty(value = "tracestate")
private String tracestate;

/*
* Only perform the operation if the entity does not already exist.
*/
@JsonProperty(value = "If-None-Match")
private String ifNoneMatch;

/**
* Get the traceparent property: Identifies the request in a distributed tracing system.
*
Expand Down Expand Up @@ -65,6 +71,26 @@ public DigitalTwinsAddRelationshipOptions setTracestate(String tracestate) {
return this;
}

/**
* Get the ifNoneMatch property: Only perform the operation if the entity does not already exist.
*
* @return the ifNoneMatch value.
*/
public String getIfNoneMatch() {
return this.ifNoneMatch;
}

/**
* Set the ifNoneMatch property: Only perform the operation if the entity does not already exist.
*
* @param ifNoneMatch the ifNoneMatch value to set.
* @return the DigitalTwinsAddRelationshipOptions object itself.
*/
public DigitalTwinsAddRelationshipOptions setIfNoneMatch(String ifNoneMatch) {
this.ifNoneMatch = ifNoneMatch;
return this;
}

/**
* Validates the instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public final class CreateDigitalTwinOptions {
@JsonProperty(value = "tracestate")
private String tracestate;

/*
* If-Non-Match header that makes the request method conditional on a recipient cache or origin server either not having any current representation of the target resource.
* @see <a href="https://tools.ietf.org/html/rfc7232">RFC</a> for documentation
* Acceptable values are null or "*".
* If IfNonMatch option is null the service will replace the existing entity with the new entity.
* If IfNonMatch option is "*" the service will reject the request if the entity already exists.
*/
@JsonProperty(value = "If-None-Match")
private String ifNoneMatch;

/**
* Get the traceparent property: Identifies the request in a distributed tracing system.
*
Expand All @@ -37,6 +47,21 @@ public String getTraceParent() {
return this.traceparent;
}

/**
* Get the ifNoneMatch property
*
* If-Non-Match header makes the request method conditional on a recipient cache or origin server either not having any current representation of the target resource.
* @see <a href="https://tools.ietf.org/html/rfc7232">RFC</a> for documentation
* Acceptable values are null or "*".
* If IfNonMatch option is null the service will replace the existing entity with the new entity.
* If IfNonMatch option is "*" the service will reject the request if the entity already exists.
*
* @return the ifNoneMatch value.
*/
public String getIfNoneMatch() {
return this.ifNoneMatch;
}

/**
* Set the traceparent property: Identifies the request in a distributed tracing system.
*
Expand Down Expand Up @@ -69,4 +94,21 @@ public CreateDigitalTwinOptions setTraceState(String tracestate) {
this.tracestate = tracestate;
return this;
}

/**
* Set the ifNoneMatch property.
*
* If-Non-Match header makes the request method conditional on a recipient cache or origin server either not having any current representation of the target resource.
* @see <a href="https://tools.ietf.org/html/rfc7232"> RFC </a>.
* Acceptable values are null or "*".
* If IfNonMatch option is null the service will replace the existing entity with the new entity.
* If IfNonMatch option is "*" the service will reject the request if the entity already exists.
*
* @param ifNoneMatch the ifNoneMatch value to set.
* @return the CreateRelationshipOptions object itself.
*/
public CreateDigitalTwinOptions setIfNoneMatch(String ifNoneMatch) {
this.ifNoneMatch = ifNoneMatch;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public final class CreateRelationshipOptions {
@JsonProperty(value = "tracestate")
private String tracestate;

/*
* If-Non-Match header that makes the request method conditional on a recipient cache or origin server either not having any current representation of the target resource.
* @see <a href="https://tools.ietf.org/html/rfc7232">RFC</a> for documentation
* Acceptable values are null or "*".
* If IfNonMatch option is null the service will replace the existing entity with the new entity.
* If IfNonMatch option is "*" the service will reject the request if the entity already exists.
*/
@JsonProperty(value = "If-None-Match")
private String ifNoneMatch;

/**
* Get the traceparent property: Identifies the request in a distributed tracing system.
*
Expand Down Expand Up @@ -58,6 +68,21 @@ public String getTraceState() {
return this.tracestate;
}

/**
* Get the ifNoneMatch property
*
* If-Non-Match header makes the request method conditional on a recipient cache or origin server either not having any current representation of the target resource.
* @see <a href="https://tools.ietf.org/html/rfc7232">RFC</a> for documentation
* Acceptable values are null or "*".
* If IfNonMatch option is null the service will replace the existing entity with the new entity.
* If IfNonMatch option is "*" the service will reject the request if the entity already exists.
*
* @return the ifNoneMatch value.
*/
public String getIfNoneMatch() {
return this.ifNoneMatch;
}

/**
* Set the tracestate property: Provides vendor-specific trace identification information and is a companion to
* traceparent.
Expand All @@ -69,4 +94,21 @@ public CreateRelationshipOptions setTraceState(String tracestate) {
this.tracestate = tracestate;
return this;
}

/**
* Set the ifNoneMatch property.
*
* If-Non-Match header makes the request method conditional on a recipient cache or origin server either not having any current representation of the target resource.
* @see <a href="https://tools.ietf.org/html/rfc7232"> RFC </a>.
* Acceptable values are null or "*".
* If IfNonMatch option is null the service will replace the existing entity with the new entity.
* If IfNonMatch option is "*" the service will reject the request if the entity already exists.
*
* @param ifNoneMatch the ifNoneMatch value to set.
* @return the CreateRelationshipOptions object itself.
*/
public CreateRelationshipOptions setIfNoneMatch(String ifNoneMatch) {
this.ifNoneMatch = ifNoneMatch;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.core.util.logging.ClientLogger;
import com.azure.digitaltwins.core.models.BasicDigitalTwin;
import com.azure.digitaltwins.core.models.BasicRelationship;
import com.azure.digitaltwins.core.models.CreateRelationshipOptions;
import com.azure.digitaltwins.core.models.IncomingRelationship;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -113,7 +114,12 @@ public void relationshipLifecycleTest(HttpClient httpClient, DigitalTwinsService
.verifyComplete();

// Create a relation which already exists - should return status code 409 (Conflict).
StepVerifier.create(asyncClient.createRelationship(roomTwinId, ROOM_CONTAINED_IN_FLOOR_RELATIONSHIP_ID, floorTwinContainedInRelationshipPayload, String.class))
StepVerifier.create(asyncClient.createRelationshipWithResponse(
roomTwinId,
ROOM_CONTAINED_IN_FLOOR_RELATIONSHIP_ID,
floorTwinContainedInRelationshipPayload,
String.class,
new CreateRelationshipOptions().setIfNoneMatch("*")))
.verifyErrorSatisfies(ex -> assertRestException(ex, HTTP_PRECON_FAILED));

// Update relationships
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ public void relationshipLifecycleTest(HttpClient httpClient, DigitalTwinsService

// Create a relation which already exists - should return status code 409 (Conflict).
assertRestException(
() -> client.createRelationship(roomTwinId, ROOM_CONTAINED_IN_FLOOR_RELATIONSHIP_ID, floorTwinContainedInRelationshipPayload, String.class),
() -> client.createRelationshipWithResponse(
roomTwinId,
ROOM_CONTAINED_IN_FLOOR_RELATIONSHIP_ID,
floorTwinContainedInRelationshipPayload,
String.class,
new CreateRelationshipOptions().setIfNoneMatch("*"),
Context.NONE),
HTTP_PRECON_FAILED
);

Expand Down
Loading