diff --git a/sdk/cosmos/azure-cosmos-examples/src/main/java/com/azure/cosmos/rx/examples/multimaster/samples/ConflictWorker.java b/sdk/cosmos/azure-cosmos-examples/src/main/java/com/azure/cosmos/rx/examples/multimaster/samples/ConflictWorker.java index 13d8ea9c94b1..8f708ec9e3a1 100644 --- a/sdk/cosmos/azure-cosmos-examples/src/main/java/com/azure/cosmos/rx/examples/multimaster/samples/ConflictWorker.java +++ b/sdk/cosmos/azure-cosmos-examples/src/main/java/com/azure/cosmos/rx/examples/multimaster/samples/ConflictWorker.java @@ -3,8 +3,6 @@ package com.azure.cosmos.rx.examples.multimaster.samples; -import com.azure.cosmos.models.AccessCondition; -import com.azure.cosmos.models.AccessConditionType; import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.models.ConflictResolutionPolicy; import com.azure.cosmos.CosmosClientException; @@ -530,9 +528,7 @@ private Mono tryUpdateDocument(AsyncDocumentClient client, String coll BridgeInternal.setProperty(document, "regionEndpoint", client.getReadEndpoint()); RequestOptions options = new RequestOptions(); - options.setAccessCondition(new AccessCondition()); - options.getAccessCondition().setType(AccessConditionType.IF_MATCH); - options.getAccessCondition().setCondition(document.getETag()); + options.setIfMatchETag(document.getETag()); return client.replaceDocument(document.getSelfLink(), document, null).onErrorResume(e -> { @@ -552,9 +548,7 @@ private Mono tryDeleteDocument(AsyncDocumentClient client, String coll BridgeInternal.setProperty(document, "regionEndpoint", client.getReadEndpoint()); RequestOptions options = new RequestOptions(); - options.setAccessCondition(new AccessCondition()); - options.getAccessCondition().setType(AccessConditionType.IF_MATCH); - options.getAccessCondition().setCondition(document.getETag()); + options.setIfMatchETag(document.getETag()); return client.deleteDocument(document.getSelfLink(), options).onErrorResume(e -> { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RequestOptions.java index 31cc4e95ec4e..39e73e3868f4 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RequestOptions.java @@ -3,7 +3,6 @@ package com.azure.cosmos.implementation; -import com.azure.cosmos.models.AccessCondition; import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.models.IndexingDirective; import com.azure.cosmos.models.PartitionKey; @@ -20,12 +19,13 @@ public class RequestOptions { private Map customOptions; private List preTriggerInclude; private List postTriggerInclude; - private AccessCondition accessCondition; private IndexingDirective indexingDirective; private ConsistencyLevel consistencyLevel; private String sessionToken; private Integer resourceTokenExpirySeconds; private String offerType; + private String ifMatchETag; + private String ifNoneMatchETag; private Integer offerThroughput; private PartitionKey partitionkey; private String partitionKeyRangeId; @@ -71,21 +71,39 @@ public void setPostTriggerInclude(List postTriggerInclude) { } /** - * Gets the conditions associated with the request. + * Gets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @return the access condition. + * @return tthe ifMatchETag associated with the request. */ - public AccessCondition getAccessCondition() { - return this.accessCondition; + public String getIfMatchETag() { + return this.ifMatchETag; } /** - * Sets the conditions associated with the request. + * Sets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @param accessCondition the access condition. + * @param ifMatchETag the ifMatchETag associated with the request. */ - public void setAccessCondition(AccessCondition accessCondition) { - this.accessCondition = accessCondition; + public void setIfMatchETag(String ifMatchETag) { + this.ifMatchETag = ifMatchETag; + } + + /** + * Gets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @return the ifNoneMatchETag associated with the request. + */ + public String getIfNoneMatchETag() { + return this.ifNoneMatchETag; + } + + /** + * Sets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @param ifNoneMatchETag the ifNoneMatchETag associated with the request. + */ + public void setIfNoneMatchETag(String ifNoneMatchETag) { + this.ifNoneMatchETag = ifNoneMatchETag; } /** diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java index 31e246975910..4456303a5756 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java @@ -35,7 +35,6 @@ import com.azure.cosmos.implementation.routing.PartitionKeyAndResourceTokenPair; import com.azure.cosmos.implementation.routing.PartitionKeyInternal; import com.azure.cosmos.implementation.routing.PartitionKeyInternalHelper; -import com.azure.cosmos.models.AccessConditionType; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import org.slf4j.Logger; @@ -874,12 +873,12 @@ private Map getRequestHeaders(RequestOptions options, ResourceTy headers.putAll(customOptions); } - if (options.getAccessCondition() != null) { - if (options.getAccessCondition().getType() == AccessConditionType.IF_MATCH) { - headers.put(HttpConstants.HttpHeaders.IF_MATCH, options.getAccessCondition().getCondition()); - } else { - headers.put(HttpConstants.HttpHeaders.IF_NONE_MATCH, options.getAccessCondition().getCondition()); - } + if (options.getIfMatchETag() != null) { + headers.put(HttpConstants.HttpHeaders.IF_MATCH, options.getIfMatchETag()); + } + + if(options.getIfNoneMatchETag() != null) { + headers.put(HttpConstants.HttpHeaders.IF_NONE_MATCH, options.getIfNoneMatchETag()); } if (options.getConsistencyLevel() != null) { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/DocumentServiceLeaseStore.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/DocumentServiceLeaseStore.java index 5d8eaef10843..73f6b264bf05 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/DocumentServiceLeaseStore.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/DocumentServiceLeaseStore.java @@ -2,8 +2,6 @@ // Licensed under the MIT License. package com.azure.cosmos.implementation.changefeed.implementation; -import com.azure.cosmos.models.AccessCondition; -import com.azure.cosmos.models.AccessConditionType; import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.CosmosClientException; import com.azure.cosmos.implementation.CosmosItemProperties; @@ -133,10 +131,7 @@ public Mono releaseInitializationLock() { requestOptions = new CosmosItemRequestOptions(); } - AccessCondition accessCondition = new AccessCondition(); - accessCondition.setType(AccessConditionType.IF_MATCH); - accessCondition.setCondition(this.lockETag); - requestOptions.setAccessCondition(accessCondition); + requestOptions.setIfMatchETag(this.lockETag); return this.client.deleteItem(lockId, new PartitionKey(lockId), requestOptions) .map(documentResourceResponse -> { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/DocumentServiceLeaseUpdaterImpl.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/DocumentServiceLeaseUpdaterImpl.java index 310ff890ad75..e510a0ee1d31 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/DocumentServiceLeaseUpdaterImpl.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/implementation/DocumentServiceLeaseUpdaterImpl.java @@ -2,8 +2,6 @@ // Licensed under the MIT License. package com.azure.cosmos.implementation.changefeed.implementation; -import com.azure.cosmos.models.AccessCondition; -import com.azure.cosmos.models.AccessConditionType; import com.azure.cosmos.BridgeInternal; import com.azure.cosmos.CosmosClientException; import com.azure.cosmos.implementation.CosmosItemProperties; @@ -17,7 +15,6 @@ import com.azure.cosmos.implementation.changefeed.exceptions.LeaseLostException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.time.ZoneId; @@ -150,12 +147,8 @@ private Mono tryReplaceLease(Lease lease, String itemId, P } private CosmosItemRequestOptions getCreateIfMatchOptions(Lease lease) { - AccessCondition ifMatchCondition = new AccessCondition(); - ifMatchCondition.setType(AccessConditionType.IF_MATCH); - ifMatchCondition.setCondition(lease.getConcurrencyToken()); - CosmosItemRequestOptions createIfMatchOptions = new CosmosItemRequestOptions(); - createIfMatchOptions.setAccessCondition(ifMatchCondition); + createIfMatchOptions.setIfMatchETag(lease.getConcurrencyToken()); return createIfMatchOptions; } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/AccessCondition.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/AccessCondition.java deleted file mode 100644 index 9335c8b36ecd..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/AccessCondition.java +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.cosmos.models; - -/** - * Represents a set of access conditions to be used for operations against the Azure Cosmos DB database service. - */ -public final class AccessCondition { - - private AccessConditionType type = AccessConditionType.IF_MATCH; - private String condition; - - /** - * Gets the condition type. - * - * @return the condition type. - */ - public AccessConditionType getType() { - return this.type; - } - - /** - * Sets the condition type. - * - * @param type the condition type to use. - * @return the Access Condition - */ - public AccessCondition setType(AccessConditionType type) { - this.type = type; - return this; - } - - /** - * Gets the value of the condition - for AccessConditionType IfMatchs and IfNotMatch, this is the ETag that has to - * be compared to. - * - * @return the condition. - */ - public String getCondition() { - return this.condition; - } - - /** - * Sets the value of the condition - for AccessConditionType IfMatchs and IfNotMatch, this is the ETag that has to - * be compared to. - * - * @param condition the condition to use. - * @return the Access Condition - */ - public AccessCondition setCondition(String condition) { - this.condition = condition; - return this; - } -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/AccessConditionType.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/AccessConditionType.java deleted file mode 100644 index 3bdc5a6ff4b3..000000000000 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/AccessConditionType.java +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.cosmos.models; - -/** - * Specifies the set of access condition types that can be used for operations in the Azure Cosmos DB database service. - */ -public enum AccessConditionType { - /** - * Check if the resource's ETag value matches the ETag value performed. - */ - IF_MATCH, - - /** - * Check if the resource's ETag value does not match ETag value performed. - */ - IF_NONE_MATCH -} diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosConflictRequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosConflictRequestOptions.java index 7988080c84fa..f40e104138da 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosConflictRequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosConflictRequestOptions.java @@ -8,31 +8,53 @@ * The type Cosmos conflict request options. */ public final class CosmosConflictRequestOptions { - private AccessCondition accessCondition; + private String ifMatchETag; + private String ifNoneMatchETag; /** - * Gets the conditions associated with the request. + * Gets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @return the access condition. + * @return ifMatchETag the ifMatchETag associated with the request. */ - public AccessCondition getAccessCondition() { - return accessCondition; + public String getIfMatchETag() { + return this.ifMatchETag; } /** - * Sets the conditions associated with the request. + * Sets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @param accessCondition the access condition. + * @param ifMatchETag the ifMatchETag associated with the request. * @return the current request options */ - public CosmosConflictRequestOptions setAccessCondition(AccessCondition accessCondition) { - this.accessCondition = accessCondition; + public CosmosConflictRequestOptions setIfMatchETag(String ifMatchETag) { + this.ifMatchETag = ifMatchETag; + return this; + } + + /** + * Gets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @return the ifNoneMatchETag associated with the request. + */ + public String getIfNoneMatchETag() { + return this.ifNoneMatchETag; + } + + /** + * Sets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @param ifNoneMatchEtag the ifNoneMatchETag associated with the request. + * @return the current request options + */ + public CosmosConflictRequestOptions setIfNoneMatchETag(String ifNoneMatchEtag) { + this.ifNoneMatchETag = ifNoneMatchEtag; return this; } RequestOptions toRequestOptions() { RequestOptions requestOptions = new RequestOptions(); - requestOptions.setAccessCondition(accessCondition); + requestOptions.setIfMatchETag(getIfMatchETag()); + requestOptions.setIfNoneMatchETag(getIfNoneMatchETag()); return requestOptions; } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosContainerRequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosContainerRequestOptions.java index 5374f8732dee..bdfbf57beb69 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosContainerRequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosContainerRequestOptions.java @@ -13,7 +13,8 @@ public final class CosmosContainerRequestOptions { private boolean populateQuotaInfo; private ConsistencyLevel consistencyLevel; private String sessionToken; - private AccessCondition accessCondition; + private String ifMatchETag; + private String ifNoneMatchETag; private ThroughputProperties throughputProperties; /** @@ -101,22 +102,42 @@ public CosmosContainerRequestOptions setSessionToken(String sessionToken) { } /** - * Gets the conditions associated with the request. + * Gets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @return the access condition. + * @return the ifMatchETag associated with the request. */ - public AccessCondition getAccessCondition() { - return accessCondition; + public String getIfMatchETag() { + return this.ifMatchETag; } /** - * Sets the conditions associated with the request. + * Sets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @param accessCondition the access condition. + * @param ifMatchETag the ifMatchETag associated with the request. * @return the current request options */ - public CosmosContainerRequestOptions setAccessCondition(AccessCondition accessCondition) { - this.accessCondition = accessCondition; + public CosmosContainerRequestOptions setIfMatchETag(String ifMatchETag) { + this.ifMatchETag = ifMatchETag; + return this; + } + + /** + * Gets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @return the ifNoneMatchETag associated with the request. + */ + public String getIfNoneMatchETag() { + return this.ifNoneMatchETag; + } + + /** + * Sets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @param ifNoneMatchETag the ifNoneMatchETag associated with the request. + * @return the current request options + */ + public CosmosContainerRequestOptions setIfNoneMatchETag(String ifNoneMatchETag) { + this.ifNoneMatchETag = ifNoneMatchETag; return this; } @@ -127,7 +148,8 @@ CosmosContainerRequestOptions setThroughputProperties(ThroughputProperties throu RequestOptions toRequestOptions() { RequestOptions options = new RequestOptions(); - options.setAccessCondition(accessCondition); + options.setIfMatchETag(getIfMatchETag()); + options.setIfNoneMatchETag(getIfNoneMatchETag()); options.setOfferThroughput(offerThroughput); options.setPopulateQuotaInfo(populateQuotaInfo); options.setSessionToken(sessionToken); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosDatabaseRequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosDatabaseRequestOptions.java index 4ba9b6d7d4a6..94a2e9e0e10c 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosDatabaseRequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosDatabaseRequestOptions.java @@ -9,26 +9,47 @@ */ public final class CosmosDatabaseRequestOptions { private Integer offerThroughput; - private AccessCondition accessCondition; + private String ifMatchETag; + private String ifNoneMatchETag; private ThroughputProperties throughputProperties; /** - * Gets the conditions associated with the request. + * Gets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @return the access condition. + * @return the ifMatchETag associated with the request. */ - public AccessCondition getAccessCondition() { - return accessCondition; + public String getIfMatchETag() { + return this.ifMatchETag; } /** - * Sets the conditions associated with the request. + * Sets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @param accessCondition the access condition. + * @param ifMatchETag the ifMatchETag associated with the request. * @return the current request options */ - public CosmosDatabaseRequestOptions setAccessCondition(AccessCondition accessCondition) { - this.accessCondition = accessCondition; + public CosmosDatabaseRequestOptions setIfMatchETag(String ifMatchETag) { + this.ifMatchETag = ifMatchETag; + return this; + } + + /** + * Gets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @return the ifNoneMatchETag associated with the request. + */ + public String getIfNoneMatchETag() { + return this.ifNoneMatchETag; + } + + /** + * Sets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @param ifNoneMatchETag the ifNoneMatchETag associated with the request. + * @return the current request options + */ + public CosmosDatabaseRequestOptions setIfNoneMatchETag(String ifNoneMatchETag) { + this.ifNoneMatchETag = ifNoneMatchETag; return this; } @@ -59,7 +80,8 @@ CosmosDatabaseRequestOptions setThroughputProperties(ThroughputProperties throug RequestOptions toRequestOptions() { RequestOptions options = new RequestOptions(); - options.setAccessCondition(accessCondition); + options.setIfMatchETag(getIfMatchETag()); + options.setIfNoneMatchETag(getIfNoneMatchETag()); options.setOfferThroughput(offerThroughput); options.setThroughputProperties(this.throughputProperties); return options; diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemRequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemRequestOptions.java index eca7ee674abc..4f56ebcdb94a 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemRequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemRequestOptions.java @@ -17,7 +17,8 @@ public final class CosmosItemRequestOptions { private List postTriggerInclude; private String sessionToken; private PartitionKey partitionKey; - private AccessCondition accessCondition; + private String ifMatchETag; + private String ifNoneMatchETag; /** * Constructor @@ -37,22 +38,42 @@ public CosmosItemRequestOptions() { } /** - * Gets the conditions associated with the request. + * Gets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @return the access condition. + * @return the ifMatchETag associated with the request. */ - public AccessCondition getAccessCondition() { - return accessCondition; + public String getIfMatchETag() { + return this.ifMatchETag; } /** - * Sets the conditions associated with the request. + * Sets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @param accessCondition the access condition. + * @param ifMatchETag the ifMatchETag associated with the request. * @return the current request options */ - public CosmosItemRequestOptions setAccessCondition(AccessCondition accessCondition) { - this.accessCondition = accessCondition; + public CosmosItemRequestOptions setIfMatchETag(String ifMatchETag) { + this.ifMatchETag = ifMatchETag; + return this; + } + + /** + * Gets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @return the ifNoneMatchETag associated with the request. + */ + public String getIfNoneMatchETag() { + return this.ifNoneMatchETag; + } + + /** + * Sets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @param ifNoneMatchETag the ifNoneMatchETag associated with the request. + * @return the current request options + */ + public CosmosItemRequestOptions setIfNoneMatchETag(String ifNoneMatchETag) { + this.ifNoneMatchETag = ifNoneMatchETag; return this; } @@ -61,6 +82,7 @@ public CosmosItemRequestOptions setAccessCondition(AccessCondition accessConditi * * @return the consistency level. */ + ConsistencyLevel getConsistencyLevel() { return consistencyLevel; } @@ -179,8 +201,8 @@ CosmosItemRequestOptions setPartitionKey(PartitionKey partitionKey) { RequestOptions toRequestOptions() { //TODO: Should we set any default values instead of nulls? RequestOptions requestOptions = new RequestOptions(); - requestOptions.setAccessCondition(accessCondition); - requestOptions.setAccessCondition(getAccessCondition()); + requestOptions.setIfMatchETag(getIfMatchETag()); + requestOptions.setIfNoneMatchETag(getIfNoneMatchETag()); requestOptions.setConsistencyLevel(getConsistencyLevel()); requestOptions.setIndexingDirective(indexingDirective); requestOptions.setPreTriggerInclude(preTriggerInclude); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosPermissionRequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosPermissionRequestOptions.java index 0afb3817c729..5fcaede8b479 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosPermissionRequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosPermissionRequestOptions.java @@ -9,32 +9,54 @@ */ public final class CosmosPermissionRequestOptions { //TODO: Need to add respective options - private AccessCondition accessCondition; + private String ifMatchETag; + private String ifNoneMatchETag; /** - * Gets the conditions associated with the request. + * Gets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @return the access condition. + * @return the ifMatchETag associated with the request. */ - public AccessCondition getAccessCondition() { - return accessCondition; + public String getIfMatchETag() { + return this.ifMatchETag; } /** - * Sets the conditions associated with the request. + * Sets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @param accessCondition the access condition. + * @param ifMatchETag the ifMatchETag associated with the request. * @return the current request options */ - public CosmosPermissionRequestOptions setAccessCondition(AccessCondition accessCondition) { - this.accessCondition = accessCondition; + public CosmosPermissionRequestOptions setIfMatchETag(String ifMatchETag) { + this.ifMatchETag = ifMatchETag; + return this; + } + + /** + * Gets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @return the ifNoneMatchETag associated with the request. + */ + public String getIfNoneMatchETag() { + return this.ifNoneMatchETag; + } + + /** + * Sets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @param ifNoneMatchETag the ifNoneMatchETag associated with the request. + * @return the current request options + */ + public CosmosPermissionRequestOptions setIfNoneMatchETag(String ifNoneMatchETag) { + this.ifNoneMatchETag = ifNoneMatchETag; return this; } RequestOptions toRequestOptions() { //TODO: Should we set any default values instead of nulls? RequestOptions requestOptions = new RequestOptions(); - requestOptions.setAccessCondition(accessCondition); + requestOptions.setIfMatchETag(getIfMatchETag()); + requestOptions.setIfNoneMatchETag(getIfNoneMatchETag()); return requestOptions; } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosStoredProcedureRequestOptions.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosStoredProcedureRequestOptions.java index 9c8197859cc8..b68fe54ff873 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosStoredProcedureRequestOptions.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosStoredProcedureRequestOptions.java @@ -12,25 +12,46 @@ public final class CosmosStoredProcedureRequestOptions { private ConsistencyLevel consistencyLevel; private PartitionKey partitionKey; private String sessionToken; - private AccessCondition accessCondition; + private String ifMatchETag; + private String ifNoneMatchETag; /** - * Gets the conditions associated with the request. + * Gets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @return the access condition. + * @return the ifMatchETag associated with the request. */ - public AccessCondition getAccessCondition() { - return accessCondition; + public String getIfMatchETag() { + return this.ifMatchETag; } /** - * Sets the conditions associated with the request. + * Sets the If-Match (ETag) associated with the request in the Azure Cosmos DB service. * - * @param accessCondition the access condition. + * @param ifMatchETag the ifMatchETag associated with the request. * @return the current request options */ - public CosmosStoredProcedureRequestOptions setAccessCondition(AccessCondition accessCondition) { - this.accessCondition = accessCondition; + public CosmosStoredProcedureRequestOptions setIfMatchETag(String ifMatchETag) { + this.ifMatchETag = ifMatchETag; + return this; + } + + /** + * Gets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @return the ifNoneMatchETag associated with the request. + */ + public String getIfNoneMatchETag() { + return this.ifNoneMatchETag; + } + + /** + * Sets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service. + * + * @param ifNoneMatchETag the ifNoneMatchETag associated with the request. + * @return the current request options + */ + public CosmosStoredProcedureRequestOptions setIfNoneMatchETag(String ifNoneMatchETag) { + this.ifNoneMatchETag = ifNoneMatchETag; return this; } @@ -96,7 +117,8 @@ public CosmosStoredProcedureRequestOptions setSessionToken(String sessionToken) RequestOptions toRequestOptions() { RequestOptions requestOptions = new RequestOptions(); - requestOptions.setAccessCondition(accessCondition); + requestOptions.setIfMatchETag(getIfMatchETag()); + requestOptions.setIfNoneMatchETag(getIfNoneMatchETag()); requestOptions.setConsistencyLevel(getConsistencyLevel()); requestOptions.setPartitionKey(partitionKey); requestOptions.setSessionToken(sessionToken); diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java index 2c7bdcc3cd76..90419d102166 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ConsistencyTestsBase.java @@ -7,10 +7,7 @@ import com.azure.cosmos.DirectConnectionConfig; import com.azure.cosmos.GatewayConnectionConfig; import com.azure.cosmos.implementation.apachecommons.collections.map.UnmodifiableMap; -import com.azure.cosmos.models.AccessCondition; -import com.azure.cosmos.models.AccessConditionType; import com.azure.cosmos.BridgeInternal; -import com.azure.cosmos.ConnectionMode; import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.models.PartitionKey; @@ -518,12 +515,9 @@ void validateSessionTokenWithPreConditionFailure(boolean useGateway) throws Exce writeClient.upsertDocument(BridgeInternal.getAltLink(createdCollection), documentResponse.getResource(), requestOptions, true).block(); // create a conditioned read request, with first write request's etag, so the read fails with PreconditionFailure - AccessCondition ac = new AccessCondition(); - ac.setCondition(documentResponse.getResource().getETag()); - ac.setType(AccessConditionType.IF_MATCH); RequestOptions requestOptions1 = new RequestOptions(); requestOptions.setPartitionKey(new PartitionKey(ModelBridgeInternal.getObjectFromJsonSerializable(documentResponse.getResource(), "mypk"))); - requestOptions1.setAccessCondition(ac); + requestOptions1.setIfMatchETag(documentResponse.getResource().getETag()); Mono> preConditionFailureResponseObservable = validationClient.upsertDocument(BridgeInternal.getAltLink(createdCollection), documentResponse.getResource(), requestOptions1, true); FailureValidator failureValidator = new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.PRECONDITION_FAILED).build();