use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.
the class DocumentSnapshot method extractField.
/**
* Returns the Value Proto at 'fieldPath'. Returns null if the field was not found.
*/
@Nullable
Value extractField(@Nonnull FieldPath fieldPath) {
Value value = null;
if (fields != null) {
Iterator<String> components = fieldPath.getSegments().iterator();
value = fields.get(components.next());
while (value != null && components.hasNext()) {
if (value.getValueTypeCase() != Value.ValueTypeCase.MAP_VALUE) {
return null;
}
value = value.getMapValue().getFieldsOrDefault(components.next(), null);
}
}
return value;
}
use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.
the class DocumentReferenceTest method updateNestedDocument.
@Test
public void updateNestedDocument() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
Map<String, Object> nestedObject = new HashMap<>();
nestedObject.put("a", "b");
nestedObject.put("c.d", "e");
nestedObject.put("f.g.h", "i");
Map<String, Value> expandedObject = new HashMap<>();
expandedObject.put("a", string("b"));
expandedObject.put("c", object("d", string("e")));
expandedObject.put("f", object("g", object("h", string("i"))));
documentReference.update(nestedObject).get();
CommitRequest expectedCommit = commit(update(expandedObject, new ArrayList<>(nestedObject.keySet())));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.
the class DocumentReferenceTest method updateNestedMap.
@Test
public void updateNestedMap() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.update("a.b", "foo", "a.c", FieldValue.delete()).get();
Map<String, Value> nestedUpdate = new HashMap<>();
Value.Builder valueProto = Value.newBuilder();
valueProto.getMapValueBuilder().putFields("b", Value.newBuilder().setStringValue("foo").build());
nestedUpdate.put("a", valueProto.build());
CommitRequest expectedCommit = commit(update(nestedUpdate, Arrays.asList("a.b", "a.c")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.
the class DocumentReferenceTest method deserializeCustomList.
@Test
public void deserializeCustomList() throws ExecutionException, InterruptedException {
ImmutableMap CUSTOM_LIST_PROTO = ImmutableMap.<String, Value>builder().put("fooList", Value.newBuilder().setArrayValue(ArrayValue.newBuilder().addValues(Value.newBuilder().setMapValue(MapValue.newBuilder().putAllFields(SINGLE_FIELD_PROTO)).build())).build()).build();
doAnswer(getAllResponse(CUSTOM_LIST_PROTO)).when(firestoreMock).streamRequest(getAllCapture.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
DocumentSnapshot snapshot = documentReference.get().get();
LocalFirestoreHelper.CustomList customList = snapshot.toObject(LocalFirestoreHelper.CustomList.class);
assertEquals(FOO_LIST, customList.fooList);
assertEquals(SINGLE_FIELD_OBJECT, customList.fooList.get(0));
}
use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.
the class DocumentReferenceTest method deleteField.
@Test
public void deleteField() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.update("foo", "bar", "bar.foo", FieldValue.delete()).get();
Value.Builder emptyMap = Value.newBuilder();
emptyMap.getMapValueBuilder();
Map<String, Value> fieldMap = new HashMap<>();
fieldMap.put("foo", string("bar"));
CommitRequest expectedCommit = commit(update(fieldMap, Arrays.asList("foo", "bar.foo")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
Aggregations