Search in sources :

Example 1 with Precondition

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

the class RemoteSerializer method decodeMutation.

public Mutation decodeMutation(com.google.firestore.v1.Write mutation) {
    Precondition precondition = mutation.hasCurrentDocument() ? decodePrecondition(mutation.getCurrentDocument()) : Precondition.NONE;
    List<FieldTransform> fieldTransforms = new ArrayList<>();
    for (DocumentTransform.FieldTransform fieldTransform : mutation.getUpdateTransformsList()) {
        fieldTransforms.add(decodeFieldTransform(fieldTransform));
    }
    switch(mutation.getOperationCase()) {
        case UPDATE:
            if (mutation.hasUpdateMask()) {
                return new PatchMutation(decodeKey(mutation.getUpdate().getName()), ObjectValue.fromMap(mutation.getUpdate().getFieldsMap()), decodeDocumentMask(mutation.getUpdateMask()), precondition, fieldTransforms);
            } else {
                return new SetMutation(decodeKey(mutation.getUpdate().getName()), ObjectValue.fromMap(mutation.getUpdate().getFieldsMap()), precondition, fieldTransforms);
            }
        case DELETE:
            return new DeleteMutation(decodeKey(mutation.getDelete()), precondition);
        case VERIFY:
            return new VerifyMutation(decodeKey(mutation.getVerify()), precondition);
        default:
            throw fail("Unknown mutation operation: %d", mutation.getOperationCase());
    }
}
Also used : DocumentTransform(com.google.firestore.v1.DocumentTransform) DeleteMutation(com.google.firebase.firestore.model.mutation.DeleteMutation) Precondition(com.google.firebase.firestore.model.mutation.Precondition) FieldTransform(com.google.firebase.firestore.model.mutation.FieldTransform) ArrayList(java.util.ArrayList) PatchMutation(com.google.firebase.firestore.model.mutation.PatchMutation) VerifyMutation(com.google.firebase.firestore.model.mutation.VerifyMutation) SetMutation(com.google.firebase.firestore.model.mutation.SetMutation)

Aggregations

DeleteMutation (com.google.firebase.firestore.model.mutation.DeleteMutation)1 FieldTransform (com.google.firebase.firestore.model.mutation.FieldTransform)1 PatchMutation (com.google.firebase.firestore.model.mutation.PatchMutation)1 Precondition (com.google.firebase.firestore.model.mutation.Precondition)1 SetMutation (com.google.firebase.firestore.model.mutation.SetMutation)1 VerifyMutation (com.google.firebase.firestore.model.mutation.VerifyMutation)1 DocumentTransform (com.google.firestore.v1.DocumentTransform)1 ArrayList (java.util.ArrayList)1