@@ -169,30 +169,6 @@ public ResourceResponse<Database> createDatabase(Database database, RequestOptio
169
169
return new ResourceResponse <Database >(this .doCreate (request ), Database .class );
170
170
}
171
171
172
- /**
173
- * Replaces a database.
174
- *
175
- * @param database the database.
176
- * @param options the request options.
177
- * @return the resource response with the replaced database.
178
- * @throws DocumentClientException the document client exception.
179
- */
180
- public ResourceResponse <Database > replaceDatabase (Database database ,
181
- RequestOptions options )
182
- throws DocumentClientException {
183
- if (database == null ) {
184
- throw new IllegalArgumentException ("Database" );
185
- }
186
-
187
- String path = DocumentClient .joinPath (database .getSelfLink (), null );
188
- Map <String , String > requestHeaders = this .getRequestHeaders (options );
189
- DocumentServiceRequest request = DocumentServiceRequest .create (ResourceType .Database ,
190
- path ,
191
- database ,
192
- requestHeaders );
193
- return new ResourceResponse <Database >(this .doReplace (request ), Database .class );
194
- }
195
-
196
172
/**
197
173
* Deletes a database.
198
174
*
@@ -1741,7 +1717,7 @@ public ResourceResponse<Permission> createPermission(String userLink, Permission
1741
1717
* @throws DocumentClientException the document client exception.
1742
1718
*/
1743
1719
public ResourceResponse <Permission > replacePermission (Permission permission , RequestOptions options )
1744
- throws DocumentClientException {
1720
+ throws DocumentClientException {
1745
1721
1746
1722
if (permission == null ) {
1747
1723
throw new IllegalArgumentException ("permission" );
@@ -1873,6 +1849,95 @@ public FeedResponse<Permission> queryPermissions(String permissionLink,
1873
1849
Permission .class ));
1874
1850
}
1875
1851
1852
+ /**
1853
+ * Replaces an offer.
1854
+ *
1855
+ * @param offer the offer to use.
1856
+ * @return the resource response with the replaced offer.
1857
+ * @throws DocumentClientException the document client exception.
1858
+ */
1859
+ public ResourceResponse <Offer > replaceOffer (Offer offer ) throws DocumentClientException {
1860
+
1861
+ if (offer == null ) {
1862
+ throw new IllegalArgumentException ("offer" );
1863
+ }
1864
+
1865
+ String path = DocumentClient .joinPath (offer .getSelfLink (), null );
1866
+ DocumentServiceRequest request = DocumentServiceRequest .create (ResourceType .Offer ,
1867
+ path ,
1868
+ offer ,
1869
+ null );
1870
+ return new ResourceResponse <Offer >(this .doReplace (request ), Offer .class );
1871
+ }
1872
+
1873
+ /**
1874
+ * Reads an offer.
1875
+ *
1876
+ * @param offerLink the offer link.
1877
+ * @return the resource response with the read offer.
1878
+ * @throws DocumentClientException the document client exception.
1879
+ */
1880
+ public ResourceResponse <Offer > readOffer (String offerLink ) throws DocumentClientException {
1881
+
1882
+ if (StringUtils .isEmpty (offerLink )) {
1883
+ throw new IllegalArgumentException ("offerLink" );
1884
+ }
1885
+
1886
+ String path = DocumentClient .joinPath (offerLink , null );
1887
+ DocumentServiceRequest request = DocumentServiceRequest .create (ResourceType .Offer , path , null );
1888
+ return new ResourceResponse <Offer >(this .doRead (request ), Offer .class );
1889
+ }
1890
+
1891
+ /**
1892
+ * Reads offers.
1893
+ *
1894
+ * @param options the feed options.
1895
+ * @return the feed response with the read offers.
1896
+ */
1897
+ public FeedResponse <Offer > readOffers (FeedOptions options ) {
1898
+ String path = DocumentClient .joinPath (Paths .OFFERS_PATH_SEGMENT , null );
1899
+ Map <String , String > requestHeaders = this .getFeedHeaders (options );
1900
+ DocumentServiceRequest request = DocumentServiceRequest .create (ResourceType .Offer , path , requestHeaders );
1901
+ return new FeedResponse <Offer >(new QueryIterable <Offer >(this , request , ReadType .Feed , Offer .class ));
1902
+ }
1903
+
1904
+ /**
1905
+ * Query for offers in a database.
1906
+ *
1907
+ * @param query the query.
1908
+ * @param options the feed options.
1909
+ * @return the feed response with the obtained offers.
1910
+ */
1911
+ public FeedResponse <Offer > queryOffers (String query , FeedOptions options ) {
1912
+ if (StringUtils .isEmpty (query )) {
1913
+ throw new IllegalArgumentException ("query" );
1914
+ }
1915
+
1916
+ return queryOffers (new SqlQuerySpec (query , null ), options );
1917
+ }
1918
+
1919
+ /**
1920
+ * Query for offers in a database.
1921
+ *
1922
+ * @param querySpec the query specification.
1923
+ * @param options the feed options.
1924
+ * @return the feed response with the obtained offers.
1925
+ */
1926
+ public FeedResponse <Offer > queryOffers (SqlQuerySpec querySpec , FeedOptions options ) {
1927
+ if (querySpec == null ) {
1928
+ throw new IllegalArgumentException ("querySpec" );
1929
+ }
1930
+
1931
+ String path = DocumentClient .joinPath (Paths .OFFERS_PATH_SEGMENT , null );
1932
+ Map <String , String > requestHeaders = this .getFeedHeaders (options );
1933
+ DocumentServiceRequest request = DocumentServiceRequest .create (ResourceType .Offer ,
1934
+ path ,
1935
+ querySpec ,
1936
+ this .queryCompatibilityMode ,
1937
+ requestHeaders );
1938
+ return new FeedResponse <Offer >(new QueryIterable <Offer >(this , request , ReadType .Query , Offer .class ));
1939
+ }
1940
+
1876
1941
/**
1877
1942
* Gets database account information.
1878
1943
*
@@ -1889,20 +1954,10 @@ public DatabaseAccount getDatabaseAccount() throws DocumentClientException {
1889
1954
// read the headers and set to the account
1890
1955
Map <String , String > responseHeader = response .getResponseHeaders ();
1891
1956
1892
- account .setCapacityUnitsConsumed (Long .valueOf (responseHeader .get (
1893
- HttpConstants .HttpHeaders .DATABASE_ACCOUNT_CAPACITY_UNITS_CONSUMED )));
1894
- account .setCapacityUnitsProvisioned (Long .valueOf (responseHeader .get (
1895
- HttpConstants .HttpHeaders .DATABASE_ACCOUNT_CAPACITY_UNITS_PROVISIONED )));
1896
1957
account .setMaxMediaStorageUsageInMB (Long .valueOf (responseHeader .get (
1897
1958
HttpConstants .HttpHeaders .MAX_MEDIA_STORAGE_USAGE_IN_MB )));
1898
1959
account .setMediaStorageUsageInMB (Long .valueOf (responseHeader .get (
1899
1960
HttpConstants .HttpHeaders .CURRENT_MEDIA_STORAGE_USAGE_IN_MB )));
1900
- account .setConsumedDocumentStorageInMB (Long .valueOf (responseHeader .get (
1901
- HttpConstants .HttpHeaders .DATABASE_ACCOUNT_CONSUMED_DOCUMENT_STORAGE_IN_MB )));
1902
- account .setReservedDocumentStorageInMB (Long .valueOf (responseHeader .get (
1903
- HttpConstants .HttpHeaders .DATABASE_ACCOUNT_RESERVED_DOCUMENT_STORAGE_IN_MB )));
1904
- account .setProvisionedDocumentStorageInMB (Long .valueOf (responseHeader .get (
1905
- HttpConstants .HttpHeaders .DATABASE_ACCOUNT_PROVISIONED_DOCUMENT_STORAGE_IN_MB )));
1906
1961
1907
1962
return account ;
1908
1963
}
@@ -2034,6 +2089,10 @@ private Map<String, String> getRequestHeaders(RequestOptions options) {
2034
2089
String .valueOf (options .getResourceTokenExpirySeconds ()));
2035
2090
}
2036
2091
2092
+ if (options .getOfferType () != null ) {
2093
+ headers .put (HttpConstants .HttpHeaders .OFFER_TYPE , options .getOfferType ());
2094
+ }
2095
+
2037
2096
return headers ;
2038
2097
}
2039
2098
0 commit comments