From ed7bc857a05b34eed6be182d4798a62bf09cd394 Mon Sep 17 00:00:00 2001 From: Michael Lehenbauer Date: Tue, 22 Jan 2019 10:57:33 -0800 Subject: [PATCH] Firestore: Include a trailing /documents on root resource paths (#4352) This is required for v1 and accepted in v1beta1. Port of https://github.com/googleapis/nodejs-firestore/pull/516/commits/52c7381bc4f964c0ca0925f19c5192bf4a3e63c6 --- .../main/java/com/google/cloud/firestore/FirestoreImpl.java | 2 +- .../src/main/java/com/google/cloud/firestore/ResourcePath.java | 3 +-- .../java/com/google/cloud/firestore/LocalFirestoreHelper.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index 568ee6f0b87b..fda247f81626 100644 --- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -398,7 +398,7 @@ boolean areTimestampsInSnapshotsEnabled() { /** Returns the name of the Firestore project associated with this client. */ String getDatabaseName() { - return databasePath.toString(); + return databasePath.getDatabaseName().toString(); } /** Returns the underlying RPC client. */ diff --git a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java index 0633d938866a..6f6be76a9829 100644 --- a/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java +++ b/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/ResourcePath.java @@ -127,9 +127,8 @@ String getPath() { */ String getName() { String path = getPath(); - if (path.isEmpty()) { - return getDatabaseName().toString(); + return getDatabaseName() + "/documents"; } else { return getDatabaseName() + "/documents/" + getPath(); } diff --git a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java index 8876fa83cf64..fe740c7cc476 100644 --- a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java +++ b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java @@ -435,7 +435,7 @@ public static RunQueryRequest query(StructuredQuery... query) { public static RunQueryRequest query( @Nullable ByteString transactionId, StructuredQuery... query) { RunQueryRequest.Builder request = RunQueryRequest.newBuilder(); - request.setParent(LocalFirestoreHelper.DATABASE_NAME); + request.setParent(LocalFirestoreHelper.DATABASE_NAME + "/documents"); StructuredQuery.Builder structuredQuery = request.getStructuredQueryBuilder(); structuredQuery.addFrom( StructuredQuery.CollectionSelector.newBuilder().setCollectionId("coll"));