Search in sources :

Example 31 with SnapshotVersion

use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.

the class BundleSerializerTest method testDecodesBundledDocumentMetadata.

// BundledDocumentMetadata tests
@Test
public void testDecodesBundledDocumentMetadata() throws JSONException {
    String json = "{\n" + "name: '" + TEST_DOCUMENT + "',\n" + "readTime: '2020-01-01T00:00:01.000000001Z',\n" + "exists: true,\n" + "queries: [ 'query-1', 'query-2' ]\n" + "}";
    BundledDocumentMetadata expectedMetadata = new BundledDocumentMetadata(key("coll/doc"), new SnapshotVersion(new com.google.firebase.Timestamp(1577836801, 1)), true, Arrays.asList("query-1", "query-2"));
    BundledDocumentMetadata actualMetadata = serializer.decodeBundledDocumentMetadata(new JSONObject(json));
    assertEquals(expectedMetadata, actualMetadata);
}
Also used : JSONObject(org.json.JSONObject) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 32 with SnapshotVersion

use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.

the class BundleSerializerTest method testDecodesBundleMetadata.

// BundleMetadata tests
@Test
public void testDecodesBundleMetadata() throws JSONException {
    String json = "{\n" + "id: 'bundle-1',\n" + "version: 1,\n" + "createTime: { seconds: 2, nanos: 3 },\n" + "totalDocuments: 4,\n" + "totalBytes: 5\n" + "}";
    BundleMetadata expectedMetadata = new BundleMetadata("bundle-1", /* schemaVersion= */
    1, new SnapshotVersion(new com.google.firebase.Timestamp(2, 3)), /* totalDocuments= */
    4, /* totalBytes= */
    5);
    BundleMetadata actualMetadata = serializer.decodeBundleMetadata(new JSONObject(json));
    assertEquals(expectedMetadata, actualMetadata);
}
Also used : JSONObject(org.json.JSONObject) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 33 with SnapshotVersion

use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.

the class BundleSerializerTest method assertDecodesValue.

private void assertDecodesValue(String json, Value proto) throws JSONException {
    String documentJson = "{\n" + "  name: '" + TEST_DOCUMENT + "',\n" + "  fields: {\n" + "    foo:\n" + json + "\n" + "  },\n" + "  crateTime: '2020-01-01T00:00:01.000000001Z',\n" + "  updateTime: '2020-01-01T00:00:02.000000002Z'\n" + "}";
    BundleDocument actualDocument = serializer.decodeDocument(new JSONObject(documentJson));
    BundleDocument expectedDocument = new BundleDocument(MutableDocument.newFoundDocument(DocumentKey.fromName(TEST_DOCUMENT), new SnapshotVersion(new com.google.firebase.Timestamp(1577836802, 2)), new ObjectValue(Value.newBuilder().setMapValue(MapValue.newBuilder().putFields("foo", proto)).build())));
    assertEquals(expectedDocument, actualDocument);
}
Also used : ObjectValue(com.google.firebase.firestore.model.ObjectValue) JSONObject(org.json.JSONObject) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion)

Example 34 with SnapshotVersion

use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.

the class RemoteSerializer method decodeMutationResult.

public MutationResult decodeMutationResult(com.google.firestore.v1.WriteResult proto, SnapshotVersion commitVersion) {
    // NOTE: Deletes don't have an updateTime but the commit timestamp from the containing
    // CommitResponse or WriteResponse indicates essentially that the delete happened no later than
    // that. For our purposes we don't care exactly when the delete happened so long as we can tell
    // when an update on the watch stream is at or later than that change.
    SnapshotVersion version = decodeVersion(proto.getUpdateTime());
    if (SnapshotVersion.NONE.equals(version)) {
        version = commitVersion;
    }
    int transformResultsCount = proto.getTransformResultsCount();
    List<Value> transformResults = new ArrayList<>(transformResultsCount);
    for (int i = 0; i < transformResultsCount; i++) {
        transformResults.add(proto.getTransformResults(i));
    }
    return new MutationResult(version, transformResults);
}
Also used : SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) ObjectValue(com.google.firebase.firestore.model.ObjectValue) Value(com.google.firestore.v1.Value) Int32Value(com.google.protobuf.Int32Value) ArrayValue(com.google.firestore.v1.ArrayValue) ArrayList(java.util.ArrayList) MutationResult(com.google.firebase.firestore.model.mutation.MutationResult)

Example 35 with SnapshotVersion

use of com.google.firebase.firestore.model.SnapshotVersion in project firebase-android-sdk by firebase.

the class RemoteSerializer method decodeFoundDocument.

private MutableDocument decodeFoundDocument(BatchGetDocumentsResponse response) {
    Assert.hardAssert(response.getResultCase().equals(ResultCase.FOUND), "Tried to deserialize a found document from a missing document.");
    DocumentKey key = decodeKey(response.getFound().getName());
    ObjectValue value = ObjectValue.fromMap(response.getFound().getFieldsMap());
    SnapshotVersion version = decodeVersion(response.getFound().getUpdateTime());
    hardAssert(!version.equals(SnapshotVersion.NONE), "Got a document response with no snapshot version");
    return MutableDocument.newFoundDocument(key, version, value);
}
Also used : ObjectValue(com.google.firebase.firestore.model.ObjectValue) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) DocumentKey(com.google.firebase.firestore.model.DocumentKey)

Aggregations

SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)43 DocumentKey (com.google.firebase.firestore.model.DocumentKey)16 Test (org.junit.Test)13 MutableDocument (com.google.firebase.firestore.model.MutableDocument)9 Target (com.google.firebase.firestore.core.Target)8 BundledQuery (com.google.firebase.firestore.bundle.BundledQuery)7 ByteString (com.google.protobuf.ByteString)7 NamedQuery (com.google.firebase.firestore.bundle.NamedQuery)6 ArrayList (java.util.ArrayList)6 Timestamp (com.google.firebase.Timestamp)5 ObjectValue (com.google.firebase.firestore.model.ObjectValue)5 MutationResult (com.google.firebase.firestore.model.mutation.MutationResult)4 JSONObject (org.json.JSONObject)4 Query (com.google.firebase.firestore.core.Query)3 Timestamp (com.google.protobuf.Timestamp)3 ResourcePath (com.google.firebase.firestore.model.ResourcePath)2 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)2 DocumentChange (com.google.firebase.firestore.remote.WatchChange.DocumentChange)2 ExistenceFilterWatchChange (com.google.firebase.firestore.remote.WatchChange.ExistenceFilterWatchChange)2 WatchTargetChange (com.google.firebase.firestore.remote.WatchChange.WatchTargetChange)2