use of com.google.firebase.firestore.UserDataReader in project firebase-android-sdk by firebase.
the class TestUtil method patchMutationHelper.
private static PatchMutation patchMutationHelper(String path, Map<String, Object> values, Precondition precondition, @Nullable List<FieldPath> updateMask) {
// Replace '<DELETE>' from JSON
for (Entry<String, Object> entry : values.entrySet()) {
if (entry.getValue().equals(DELETE_SENTINEL)) {
values.put(entry.getKey(), FieldValue.delete());
}
}
UserDataReader dataReader = new UserDataReader(DatabaseId.forProject("project"));
ParsedUpdateData parsed = dataReader.parseUpdateData(values);
// `mergeMutation()` provides an update mask for the merged fields, whereas `patchMutation()`
// requires the update mask to be parsed from the values.
Collection<FieldPath> mask = updateMask != null ? updateMask : parsed.getFieldMask().getMask();
// We sort the fieldMaskPaths to make the order deterministic in tests. (Otherwise, when we
// flatten a Set to a proto repeated field, we'll end up comparing in iterator order and
// possibly consider {foo,bar} != {bar,foo}.)
SortedSet<FieldPath> fieldMaskPaths = new TreeSet<>(mask);
// The order of the transforms doesn't matter, but we sort them so tests can assume a particular
// order.
ArrayList<FieldTransform> fieldTransforms = new ArrayList<>(parsed.getFieldTransforms());
Collections.sort(fieldTransforms, (ft1, ft2) -> ft1.getFieldPath().compareTo(ft2.getFieldPath()));
return new PatchMutation(key(path), parsed.getData(), FieldMask.fromSet(fieldMaskPaths), precondition, fieldTransforms);
}
use of com.google.firebase.firestore.UserDataReader in project firebase-android-sdk by firebase.
the class TestUtil method setMutation.
public static SetMutation setMutation(String path, Map<String, Object> values) {
UserDataReader dataReader = new UserDataReader(DatabaseId.forProject("project"));
ParsedSetData parsed = dataReader.parseSetData(values);
// The order of the transforms doesn't matter, but we sort them so tests can assume a particular
// order.
ArrayList<FieldTransform> fieldTransforms = new ArrayList<>(parsed.getFieldTransforms());
Collections.sort(fieldTransforms, (ft1, ft2) -> ft1.getFieldPath().compareTo(ft2.getFieldPath()));
return new SetMutation(key(path), parsed.getData(), Precondition.NONE, fieldTransforms);
}
use of com.google.firebase.firestore.UserDataReader in project firebase-android-sdk by firebase.
the class TestUtil method wrap.
public static Value wrap(Object value) {
DatabaseId databaseId = DatabaseId.forProject("project");
UserDataReader dataReader = new UserDataReader(databaseId);
// our tests currently use wrap() pretty generically so we don't know the intent.
return dataReader.parseQueryValue(value);
}
Aggregations