Skip to content

Commit aeff094

Browse files
---
yaml --- r: 8837 b: refs/heads/lesv-patch-1 c: a53f7a8 h: refs/heads/master i: 8835: 91dd8f4
1 parent 53a6881 commit aeff094

12 files changed

Lines changed: 64 additions & 35 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ refs/tags/v0.22.0: 18b298fe4bfe8ec2f20b0e0bf7ffdcce5cc3c5fe
6666
refs/heads/vam-google-patch-1: d0c8fee3a4074d0bf7360ce8c4f7f7223d0ee7b9
6767
refs/heads/vam-google-patch-CODEOWNERS: 2ac1616e25229e51d08a984708ef1918f91a35ee
6868
refs/heads/danoscarmike-patch-1: 7342a9916bce4ed00002c7202e2a16c5d46afaea
69-
refs/heads/lesv-patch-1: 830d5ccd8939708d3d76acfcfecafa0f6818501b
69+
refs/heads/lesv-patch-1: a53f7a8420f63ee5c0bc20ef820ae3afd5eb0e57
7070
refs/heads/ml-update-branch: 079dd6610017f5c51b9d1938c12d6d55b61513cf
7171
refs/heads/vkedia-patch-2: 7d8241388a9769a5c069334761b06c7012c878e7
7272
refs/heads/vkedia-patch-3: 4d128043acaa7db9160faf439d2ca6104e8a88cb

branches/lesv-patch-1/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public DocumentReference getParent() {
7070
*/
7171
@Nonnull
7272
public String getPath() {
73-
return path.toString();
73+
return path.getPath();
7474
}
7575

7676
/**

branches/lesv-patch-1/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,34 @@ public String getId() {
6868
}
6969

7070
/**
71-
* A reference to the Collection to which this DocumentReference belongs to.
71+
* A string representing the path of the referenced document (relative to the root of the
72+
* database).
7273
*
73-
* @return The parent Collection.
74+
* @return The slash-separated path relative to the root of the database.
7475
*/
7576
@Nonnull
76-
public CollectionReference getParent() {
77-
return new CollectionReference(firestore, path.getParent());
77+
public String getPath() {
78+
return path.getPath();
7879
}
7980

8081
/**
81-
* A string representing the path of the referenced document (relative to the root of the
82-
* database).
82+
* A string representing the fully-qualified path of the referenced document.
8383
*
84-
* @return The slash-separated path relative to the root of the database.
84+
* @return The fully-qualified path of the document.
8585
*/
8686
@Nonnull
87-
public String getPath() {
88-
return path.toString();
87+
String getName() {
88+
return path.getName();
89+
}
90+
91+
/**
92+
* A reference to the Collection to which this DocumentReference belongs to.
93+
*
94+
* @return The parent Collection.
95+
*/
96+
@Nonnull
97+
public CollectionReference getParent() {
98+
return new CollectionReference(firestore, path.getParent());
8999
}
90100

91101
/**

branches/lesv-patch-1/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public DocumentReference getReference() {
388388
Document.Builder toPb() {
389389
Preconditions.checkState(exists(), "Can't call toDocument() on a document that doesn't exist");
390390
Document.Builder document = Document.newBuilder();
391-
document.setName(docRef.getPath());
391+
document.setName(docRef.getName());
392392
document.putAllFields(fields);
393393
return document;
394394
}

branches/lesv-patch-1/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentTransform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Write toPb() {
116116
Write.Builder write = Write.newBuilder();
117117
com.google.firestore.v1beta1.DocumentTransform.Builder transform = write.getTransformBuilder();
118118
transform.addAllFieldTransforms(transforms);
119-
transform.setDocument(documentReference.getPath());
119+
transform.setDocument(documentReference.getName());
120120
return write.build();
121121
}
122122
}

branches/lesv-patch-1/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static Value encodeValue(@Nullable Object sanitizedObject) {
118118
return Value.newBuilder().setBytesValue(blob.toByteString()).build();
119119
} else if (sanitizedObject instanceof DocumentReference) {
120120
DocumentReference docRef = (DocumentReference) sanitizedObject;
121-
return Value.newBuilder().setReferenceValue(docRef.getPath()).build();
121+
return Value.newBuilder().setReferenceValue(docRef.getName()).build();
122122
} else if (sanitizedObject instanceof Map) {
123123
MapValue.Builder res = MapValue.newBuilder();
124124
for (Map.Entry<String, Object> entry : ((Map<String, Object>) sanitizedObject).entrySet()) {
@@ -256,7 +256,7 @@ public void onCompleted() {
256256
}
257257

258258
for (DocumentReference docRef : documentReferences) {
259-
request.addDocuments(docRef.getPath());
259+
request.addDocuments(docRef.getName());
260260
}
261261

262262
streamRequest(request.build(), responseObserver, firestoreClient.batchGetDocumentsCallable());

branches/lesv-patch-1/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ boolean isCollection() {
8484
/**
8585
* The Path's id (last component).
8686
*
87-
* @return The last component of the Path or null if the path points to the root..
87+
* @return The last component of the Path or null if the path points to the root.
8888
*/
8989
@Nullable
9090
String getId() {
@@ -98,26 +98,46 @@ String getId() {
9898
}
9999

100100
/**
101-
* String representation as expected by the Firestore API.
101+
* The Path's name (the location relative to the root of the database).
102102
*
103-
* @return The formatted name of the resource.
103+
* @return The resource path relative to the root of the database.
104104
*/
105-
@Override
106-
public String toString() {
105+
String getPath() {
107106
StringBuilder result = new StringBuilder();
108-
result.append(getDatabaseName());
109107

110-
ImmutableList<String> parts = getSegments();
111-
if (parts.size() > 0) {
112-
result.append("/documents");
113-
for (String part : parts) {
108+
boolean first = true;
109+
for (String part : getSegments()) {
110+
if (first) {
111+
result.append(part);
112+
first = false;
113+
} else {
114114
result.append("/").append(part);
115115
}
116116
}
117117

118118
return result.toString();
119119
}
120120

121+
/**
122+
* String representation as expected by the Firestore API.
123+
*
124+
* @return The formatted name of the resource.
125+
*/
126+
String getName() {
127+
String path = getPath();
128+
129+
if (path.isEmpty()) {
130+
return getDatabaseName().toString();
131+
} else {
132+
return getDatabaseName() + "/documents/" + getPath();
133+
}
134+
}
135+
136+
@Override
137+
public String toString() {
138+
return getName();
139+
}
140+
121141
@Override
122142
String[] splitChildPath(String name) {
123143
return name.split("/");

branches/lesv-patch-1/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public T delete(@Nonnull DocumentReference documentReference) {
451451
private T performDelete(
452452
@Nonnull DocumentReference documentReference, @Nonnull Precondition precondition) {
453453
Write.Builder writeBuilder = Write.newBuilder();
454-
writeBuilder.setDelete(documentReference.getPath());
454+
writeBuilder.setDelete(documentReference.getName());
455455
writeBuilder.setCurrentDocument(precondition.toPb());
456456
writes.add(writeBuilder.build());
457457
return (T) this;

branches/lesv-patch-1/google-cloud-firestore/src/test/java/com/google/cloud/firestore/CollectionReferenceTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ public void getParent() {
8484
assertNull(documentReference);
8585
CollectionReference subcollection = collectionReference.document("doc").collection("subcoll");
8686
assertEquals("subcoll", subcollection.getId());
87-
assertEquals(
88-
"projects/test-project/databases/(default)/documents/coll/doc/subcoll",
89-
subcollection.getPath());
87+
assertEquals("coll/doc/subcoll", subcollection.getPath());
9088
documentReference = subcollection.getParent();
9189
assertEquals("doc", documentReference.getId());
9290
}

branches/lesv-patch-1/google-cloud-firestore/src/test/java/com/google/cloud/firestore/DocumentReferenceTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static com.google.cloud.firestore.LocalFirestoreHelper.BLOB;
2323
import static com.google.cloud.firestore.LocalFirestoreHelper.DATE;
2424
import static com.google.cloud.firestore.LocalFirestoreHelper.DOCUMENT_NAME;
25+
import static com.google.cloud.firestore.LocalFirestoreHelper.DOCUMENT_PATH;
2526
import static com.google.cloud.firestore.LocalFirestoreHelper.EMPTY_MAP_PROTO;
2627
import static com.google.cloud.firestore.LocalFirestoreHelper.GEO_POINT;
2728
import static com.google.cloud.firestore.LocalFirestoreHelper.NESTED_CLASS_OBJECT;
@@ -116,7 +117,7 @@ public void getCollection() {
116117

117118
@Test
118119
public void getPath() {
119-
assertEquals(DOCUMENT_NAME, documentReference.getPath());
120+
assertEquals(DOCUMENT_PATH, documentReference.getPath());
120121
}
121122

122123
@Test

0 commit comments

Comments
 (0)