use of com.google.firebase.firestore.core.UserData.ParseAccumulator in project firebase-android-sdk by firebase.
the class UserDataReader method parseSetData.
/**
* Parse document data from a non-merge {@code set()} call.
*
* @param input A map or POJO object representing document data.
*/
public ParsedSetData parseSetData(Object input) {
ParseAccumulator accumulator = new ParseAccumulator(UserData.Source.Set);
ObjectValue updateData = convertAndParseDocumentData(input, accumulator.rootContext());
return accumulator.toSetData(updateData);
}
use of com.google.firebase.firestore.core.UserData.ParseAccumulator in project firebase-android-sdk by firebase.
the class UserDataReader method parseUpdateData.
/**
* Parse update data from an {@code update()} call.
*/
public ParsedUpdateData parseUpdateData(Map<String, Object> data) {
checkNotNull(data, "Provided update data must not be null.");
ParseAccumulator accumulator = new ParseAccumulator(UserData.Source.Update);
ParseContext context = accumulator.rootContext();
ObjectValue updateData = new ObjectValue();
for (Entry<String, Object> entry : data.entrySet()) {
FieldPath fieldPath = com.google.firebase.firestore.FieldPath.fromDotSeparatedPath(entry.getKey()).getInternalPath();
Object fieldValue = entry.getValue();
if (fieldValue instanceof DeleteFieldValue) {
// Add it to the field mask, but don't add anything to updateData.
context.addToFieldMask(fieldPath);
} else {
@Nullable Value parsedValue = convertAndParseFieldData(fieldValue, context.childContext(fieldPath));
if (parsedValue != null) {
context.addToFieldMask(fieldPath);
updateData.set(fieldPath, parsedValue);
}
}
}
return accumulator.toUpdateData(updateData);
}
use of com.google.firebase.firestore.core.UserData.ParseAccumulator in project firebase-android-sdk by firebase.
the class UserDataReader method parseMergeData.
/**
* Parse document data from a {@code set()} call with {@link SetOptions#merge()} set.
*
* @param input A map or POJO object representing document data.
* @param fieldMask A {@code FieldMask} object representing the fields to be merged.
*/
public ParsedSetData parseMergeData(Object input, @Nullable FieldMask fieldMask) {
ParseAccumulator accumulator = new ParseAccumulator(UserData.Source.MergeSet);
ObjectValue updateData = convertAndParseDocumentData(input, accumulator.rootContext());
if (fieldMask != null) {
// Verify that all elements specified in the field mask are part of the parsed context.
for (FieldPath field : fieldMask.getMask()) {
if (!accumulator.contains(field)) {
throw new IllegalArgumentException("Field '" + field.toString() + "' is specified in your field mask but not in your input data.");
}
}
return accumulator.toMergeData(updateData, fieldMask);
} else {
return accumulator.toMergeData(updateData);
}
}
use of com.google.firebase.firestore.core.UserData.ParseAccumulator in project firebase-android-sdk by firebase.
the class UserDataReader method parseQueryValue.
/**
* Parse a "query value" (e.g. value in a where filter or a value in a cursor bound).
*
* @param allowArrays Whether the query value is an array that may directly contain additional
* arrays (e.g. the operand of a `whereIn` query).
*/
public Value parseQueryValue(Object input, boolean allowArrays) {
ParseAccumulator accumulator = new ParseAccumulator(allowArrays ? UserData.Source.ArrayArgument : UserData.Source.Argument);
@Nullable Value parsed = convertAndParseFieldData(input, accumulator.rootContext());
hardAssert(parsed != null, "Parsed data should not be null.");
hardAssert(accumulator.getFieldTransforms().isEmpty(), "Field transforms should have been disallowed.");
return parsed;
}
use of com.google.firebase.firestore.core.UserData.ParseAccumulator in project firebase-android-sdk by firebase.
the class UserDataReader method parseArrayTransformElements.
private List<Value> parseArrayTransformElements(List<Object> elements) {
ParseAccumulator accumulator = new ParseAccumulator(UserData.Source.Argument);
List<Value> result = new ArrayList<>(elements.size());
for (int i = 0; i < elements.size(); i++) {
Object element = elements.get(i);
// Although array transforms are used with writes, the actual elements
// being unioned or removed are not considered writes since they cannot
// contain any FieldValue sentinels, etc.
ParseContext context = accumulator.rootContext();
result.add(convertAndParseFieldData(element, context.childContext(i)));
}
return result;
}
Aggregations