Skip to content

Commit 1e6fa97

Browse files
committed
Merge pull request #35 from shipunyc/master
Updates SDK version to 1.2.0:
2 parents 207d37d + 596e536 commit 1e6fa97

13 files changed

+406
-73
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
1414
<dependency>
1515
<groupId>com.microsoft.azure</groupId>
1616
<artifactId>azure-documentdb</artifactId>
17-
<version>1.1.0</version>
17+
<version>1.2.0</version>
1818
</dependency>
1919

2020
###Option 2: Source Via Git

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Changes in 1.2.0 : ##
2+
3+
- Supports GeoSpatial index.
4+
- Validates resource id.
5+
- Adds new header "index transformation progress" to ResourceResponse.
6+
17
## Changes in 1.1.0 : ##
28

39
- Implements V2 indexing policy

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.microsoft.azure</groupId>
55
<artifactId>azure-documentdb</artifactId>
6-
<version>1.1.0</version>
6+
<version>1.2.0</version>
77
<name>${project.groupId}:${project.artifactId}</name>
88
<description>Java SDK for Microsoft Azure DocumentDB</description>
99
<url>http://azure.microsoft.com/en-us/services/documentdb/</url>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
package com.microsoft.azure.documentdb;
22

33
public enum DataType {
4+
5+
/**
6+
* Represents a numeric data type.
7+
*/
48
Number,
9+
10+
/**
11+
* Represent a point data type.
12+
*/
13+
Point,
14+
15+
/**
16+
* Represents a string data type.
17+
*/
518
String
619
}

src/com/microsoft/azure/documentdb/DocumentClient.java

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public ResourceResponse<Database> createDatabase(Database database, RequestOptio
161161
throw new IllegalArgumentException("Database");
162162
}
163163

164+
DocumentClient.validateResource(database);
165+
164166
Map<String, String> requestHeaders = this.getRequestHeaders(options);
165167
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Database,
166168
Paths.DATABASES_ROOT,
@@ -284,6 +286,8 @@ public ResourceResponse<DocumentCollection> createCollection(String databaseLink
284286
throw new IllegalArgumentException("collection");
285287
}
286288

289+
DocumentClient.validateResource(collection);
290+
287291
String path = DocumentClient.joinPath(databaseLink, Paths.COLLECTIONS_PATH_SEGMENT);
288292
Map<String, String> requestHeaders = this.getRequestHeaders(options);
289293
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.DocumentCollection,
@@ -293,6 +297,34 @@ public ResourceResponse<DocumentCollection> createCollection(String databaseLink
293297
return new ResourceResponse<DocumentCollection>(this.doCreate(request), DocumentCollection.class);
294298
}
295299

300+
/**
301+
* Replaces a document collection.
302+
*
303+
* @param collection the document collection to use.
304+
* @param options the request options.
305+
* @return the resource response with the replaced document collection.
306+
* @throws DocumentClientException the document client exception.
307+
*/
308+
public ResourceResponse<DocumentCollection> replaceCollection(DocumentCollection collection,
309+
RequestOptions options)
310+
throws DocumentClientException {
311+
312+
if (collection == null) {
313+
throw new IllegalArgumentException("collection");
314+
}
315+
316+
DocumentClient.validateResource(collection);
317+
318+
String path = DocumentClient.joinPath(collection.getSelfLink(), null);
319+
Map<String, String> requestHeaders = this.getRequestHeaders(options);
320+
321+
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.DocumentCollection,
322+
path,
323+
collection,
324+
requestHeaders);
325+
return new ResourceResponse<DocumentCollection>(this.doReplace(request), DocumentCollection.class);
326+
}
327+
296328
/**
297329
* Deletes a document collection by the collection link.
298330
*
@@ -442,6 +474,8 @@ public ResourceResponse<Document> createDocument(String collectionLink,
442474

443475
Document typedDocument = Document.FromObject(document);
444476

477+
DocumentClient.validateResource(typedDocument);
478+
445479
if (typedDocument.getId() == null && !disableAutomaticIdGeneration) {
446480
// We are supposed to use GUID. Basically UUID is the same as GUID
447481
// when represented as a string.
@@ -475,9 +509,12 @@ public ResourceResponse<Document> replaceDocument(String documentLink, Object do
475509
throw new IllegalArgumentException("document");
476510
}
477511

512+
Document typedDocument = Document.FromObject(document);
513+
DocumentClient.validateResource(typedDocument);
514+
478515
String path = DocumentClient.joinPath(documentLink, null);
479516
Map<String, String> requestHeaders = this.getRequestHeaders(options);
480-
Document typedDocument = Document.FromObject(document);
517+
481518
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Document,
482519
path,
483520
typedDocument,
@@ -500,6 +537,8 @@ public ResourceResponse<Document> replaceDocument(Document document, RequestOpti
500537
throw new IllegalArgumentException("document");
501538
}
502539

540+
DocumentClient.validateResource(document);
541+
503542
String path = DocumentClient.joinPath(document.getSelfLink(), null);
504543
Map<String, String> requestHeaders = this.getRequestHeaders(options);
505544
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Document,
@@ -641,6 +680,8 @@ public ResourceResponse<StoredProcedure> createStoredProcedure(String collection
641680
throw new IllegalArgumentException("storedProcedure");
642681
}
643682

683+
DocumentClient.validateResource(storedProcedure);
684+
644685
String path = DocumentClient.joinPath(collectionLink, Paths.STORED_PROCEDURES_PATH_SEGMENT);
645686
Map<String, String> requestHeaders = this.getRequestHeaders(options);
646687
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.StoredProcedure,
@@ -666,6 +707,8 @@ public ResourceResponse<StoredProcedure> replaceStoredProcedure(StoredProcedure
666707
throw new IllegalArgumentException("storedProcedure");
667708
}
668709

710+
DocumentClient.validateResource(storedProcedure);
711+
669712
String path = DocumentClient.joinPath(storedProcedure.getSelfLink(), null);
670713
Map<String, String> requestHeaders = this.getRequestHeaders(options);
671714
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.StoredProcedure,
@@ -839,6 +882,8 @@ public ResourceResponse<Trigger> createTrigger(String collectionLink, Trigger tr
839882
throw new IllegalArgumentException("trigger");
840883
}
841884

885+
DocumentClient.validateResource(trigger);
886+
842887
String path = DocumentClient.joinPath(collectionLink, Paths.TRIGGERS_PATH_SEGMENT);
843888
Map<String, String> requestHeaders = this.getRequestHeaders(options);
844889
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Trigger,
@@ -863,6 +908,8 @@ public ResourceResponse<Trigger> replaceTrigger(Trigger trigger, RequestOptions
863908
throw new IllegalArgumentException("trigger");
864909
}
865910

911+
DocumentClient.validateResource(trigger);
912+
866913
String path = DocumentClient.joinPath(trigger.getSelfLink(), null);
867914
Map<String, String> requestHeaders = this.getRequestHeaders(options);
868915
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Trigger,
@@ -1008,6 +1055,8 @@ public ResourceResponse<UserDefinedFunction> createUserDefinedFunction(
10081055
throw new IllegalArgumentException("udf");
10091056
}
10101057

1058+
DocumentClient.validateResource(udf);
1059+
10111060
String path = DocumentClient.joinPath(collectionLink, Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT);
10121061
Map<String, String> requestHeaders = this.getRequestHeaders(options);
10131062
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.UserDefinedFunction,
@@ -1032,6 +1081,8 @@ public ResourceResponse<UserDefinedFunction> replaceUserDefinedFunction(UserDefi
10321081
throw new IllegalArgumentException("udf");
10331082
}
10341083

1084+
DocumentClient.validateResource(udf);
1085+
10351086
String path = DocumentClient.joinPath(udf.getSelfLink(), null);
10361087
Map<String, String> requestHeaders = this.getRequestHeaders(options);
10371088
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.UserDefinedFunction,
@@ -1184,7 +1235,9 @@ public ResourceResponse<Attachment> createAttachment(String documentLink,
11841235
if (attachment == null) {
11851236
throw new IllegalArgumentException("attachment");
11861237
}
1187-
1238+
1239+
DocumentClient.validateResource(attachment);
1240+
11881241
String path = DocumentClient.joinPath(documentLink, Paths.ATTACHMENTS_PATH_SEGMENT);
11891242
Map<String, String> requestHeaders = this.getRequestHeaders(options);
11901243
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Attachment,
@@ -1208,6 +1261,8 @@ public ResourceResponse<Attachment> replaceAttachment(Attachment attachment, Req
12081261
throw new IllegalArgumentException("attachment");
12091262
}
12101263

1264+
DocumentClient.validateResource(attachment);
1265+
12111266
String path = DocumentClient.joinPath(attachment.getSelfLink(), null);
12121267
Map<String, String> requestHeaders = this.getRequestHeaders(options);
12131268
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Attachment,
@@ -1546,6 +1601,8 @@ public ResourceResponse<User> createUser(String databaseLink, User user, Request
15461601
throw new IllegalArgumentException("user");
15471602
}
15481603

1604+
DocumentClient.validateResource(user);
1605+
15491606
String path = DocumentClient.joinPath(databaseLink, Paths.USERS_PATH_SEGMENT);
15501607
Map<String, String> requestHeaders = this.getRequestHeaders(options);
15511608
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.User, path, user, requestHeaders);
@@ -1566,6 +1623,8 @@ public ResourceResponse<User> replaceUser(User user, RequestOptions options) thr
15661623
throw new IllegalArgumentException("user");
15671624
}
15681625

1626+
DocumentClient.validateResource(user);
1627+
15691628
String path = DocumentClient.joinPath(user.getSelfLink(), null);
15701629
Map<String, String> requestHeaders = this.getRequestHeaders(options);
15711630
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.User, path, user, requestHeaders);
@@ -1699,6 +1758,8 @@ public ResourceResponse<Permission> createPermission(String userLink, Permission
16991758
throw new IllegalArgumentException("permission");
17001759
}
17011760

1761+
DocumentClient.validateResource(permission);
1762+
17021763
String path = DocumentClient.joinPath(userLink, Paths.PERMISSIONS_PATH_SEGMENT);
17031764
Map<String, String> requestHeaders = this.getRequestHeaders(options);
17041765
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Permission,
@@ -1723,6 +1784,8 @@ public ResourceResponse<Permission> replacePermission(Permission permission, Req
17231784
throw new IllegalArgumentException("permission");
17241785
}
17251786

1787+
DocumentClient.validateResource(permission);
1788+
17261789
String path = DocumentClient.joinPath(permission.getSelfLink(), null);
17271790
Map<String, String> requestHeaders = this.getRequestHeaders(options);
17281791
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Permission,
@@ -1862,6 +1925,8 @@ public ResourceResponse<Offer> replaceOffer(Offer offer) throws DocumentClientEx
18621925
throw new IllegalArgumentException("offer");
18631926
}
18641927

1928+
DocumentClient.validateResource(offer);
1929+
18651930
String path = DocumentClient.joinPath(offer.getSelfLink(), null);
18661931
DocumentServiceRequest request = DocumentServiceRequest.create(ResourceType.Offer,
18671932
path,
@@ -2193,4 +2258,17 @@ private static String serializeProcedureParams(Object[] objectArray) {
21932258

21942259
return String.format("[%s]", StringUtils.join(stringArray, ","));
21952260
}
2261+
2262+
private static void validateResource(Resource resource) {
2263+
if (!StringUtils.isEmpty(resource.getId())) {
2264+
if (resource.getId().indexOf('/') != -1 || resource.getId().indexOf('\\') != -1 ||
2265+
resource.getId().indexOf('?') != -1 || resource.getId().indexOf('#') != -1) {
2266+
throw new IllegalArgumentException("Id contains illagel chars.");
2267+
}
2268+
2269+
if (resource.getId().endsWith(" ")) {
2270+
throw new IllegalArgumentException("Id ends with a space.");
2271+
}
2272+
}
2273+
}
21962274
}

0 commit comments

Comments
 (0)