use of com.google.cloud.firestore.DocumentSnapshot in project java-docs-samples by GoogleCloudPlatform.
the class QuickstartIT method validate.
private void validate(DocumentReference docRef, Map<String, Object> data) throws Exception {
DocumentSnapshot documentSnapshot = docRef.get().get();
assertTrue(Objects.equals(documentSnapshot.getData(), data));
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippetsIT method getResults.
private List<String> getResults(Query query) throws Exception {
// asynchronously retrieve query results
ApiFuture<QuerySnapshot> future = query.get();
// block on response
QuerySnapshot querySnapshot = future.get();
List<String> docIds = new ArrayList<>();
for (DocumentSnapshot document : querySnapshot.getDocuments()) {
docIds.add(document.getId());
}
return docIds;
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-docs-samples by GoogleCloudPlatform.
the class RetrieveDataSnippetsIT method testRetrieveQueryResults.
@Test
public void testRetrieveQueryResults() throws Exception {
List<QueryDocumentSnapshot> docs = retrieveDataSnippets.getQueryResults();
assertEquals(docs.size(), 3);
Set<String> docIds = new HashSet<>();
for (DocumentSnapshot doc : docs) {
docIds.add(doc.getId());
}
assertTrue(docIds.contains("BJ") && docIds.contains("TOK") && docIds.contains("DC"));
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-docs-samples by GoogleCloudPlatform.
the class RetrieveDataSnippetsIT method deleteAllDocuments.
private static void deleteAllDocuments() throws Exception {
ApiFuture<QuerySnapshot> future = db.collection("cities").get();
QuerySnapshot querySnapshot = future.get();
for (DocumentSnapshot doc : querySnapshot.getDocuments()) {
// block on delete operation
db.collection("cities").document(doc.getId()).delete().get();
}
}
use of com.google.cloud.firestore.DocumentSnapshot in project getting-started-java by GoogleCloudPlatform.
the class TranslateServlet method doGet.
// [START getting_started_background_app_list]
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Firestore firestore = (Firestore) this.getServletContext().getAttribute("firestore");
CollectionReference translations = firestore.collection("translations");
QuerySnapshot snapshot;
try {
snapshot = translations.limit(10).get().get();
} catch (InterruptedException | ExecutionException e) {
throw new ServletException("Exception retrieving documents from Firestore.", e);
}
List<TranslateMessage> translateMessages = Lists.newArrayList();
List<QueryDocumentSnapshot> documents = Lists.newArrayList(snapshot.getDocuments());
documents.sort(Comparator.comparing(DocumentSnapshot::getCreateTime));
for (DocumentSnapshot document : Lists.reverse(documents)) {
String encoded = gson.toJson(document.getData());
TranslateMessage message = gson.fromJson(encoded, TranslateMessage.class);
message.setData(decode(message.getData()));
translateMessages.add(message);
}
req.setAttribute("messages", translateMessages);
req.setAttribute("page", "list");
req.getRequestDispatcher("/base.jsp").forward(req, resp);
}
Aggregations