use of com.google.cloud.firestore.DocumentSnapshot in project spring-cloud-gcp by spring-cloud.
the class FirestoreDefaultClassMapper method entityToDocument.
public <T> Document entityToDocument(T entity, String documentResourceName) {
DocumentSnapshot documentSnapshot = INTERNAL.snapshotFromObject(NOT_USED_PATH, entity);
Map<String, Value> valuesMap = INTERNAL.protoFromSnapshot(documentSnapshot);
return Document.newBuilder().putAllFields(valuesMap).setName(documentResourceName).build();
}
use of com.google.cloud.firestore.DocumentSnapshot in project jade-data-repo by DataBiosphere.
the class FireStoreDependencyDao method getDatasetSnapshotFileIds.
public List<String> getDatasetSnapshotFileIds(Dataset dataset, String snapshotId) throws InterruptedException {
DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
FireStoreProject fireStoreProject = FireStoreProject.get(dataProject.getGoogleProjectId());
String dependencyCollectionName = getDatasetDependencyId(dataset.getId().toString());
CollectionReference depColl = fireStoreProject.getFirestore().collection(dependencyCollectionName);
Query query = depColl.whereEqualTo("snapshotId", snapshotId);
ApiFuture<QuerySnapshot> querySnapshot = query.get();
List<String> fileIds = new ArrayList<>();
try {
List<QueryDocumentSnapshot> documents = querySnapshot.get().getDocuments();
for (DocumentSnapshot docSnap : documents) {
FireStoreDependency fireStoreDependency = docSnap.toObject(FireStoreDependency.class);
fileIds.add(fireStoreDependency.getFileId());
}
return fileIds;
} catch (ExecutionException ex) {
throw new FileSystemExecutionException("get file ids - execution exception", ex);
}
}
use of com.google.cloud.firestore.DocumentSnapshot in project jade-data-repo by DataBiosphere.
the class FireStoreDirectoryDao method lookupByFilePath.
private DocumentSnapshot lookupByFilePath(Firestore firestore, String collectionId, String lookupPath, Transaction xn) {
try {
DocumentReference docRef = firestore.collection(collectionId).document(encodePathAsFirestoreDocumentName(lookupPath));
ApiFuture<DocumentSnapshot> docSnapFuture = xn.get(docRef);
return docSnapFuture.get();
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new FileSystemExecutionException("lookupByEntryPath - execution interrupted", ex);
} catch (AbortedException | ExecutionException ex) {
throw handleExecutionException("lookupByEntryPath", ex);
}
}
use of com.google.cloud.firestore.DocumentSnapshot in project jade-data-repo by DataBiosphere.
the class FireStoreDirectoryDao method createDirectoryEntry.
// Note that this does not test for duplicates. If invoked on an existing path it will overwrite
// the entry. Existence checking is handled at upper layers.
public void createDirectoryEntry(Firestore firestore, String collectionId, FireStoreDirectoryEntry createEntry) {
ApiFuture<Void> transaction = firestore.runTransaction(xn -> {
List<FireStoreDirectoryEntry> createList = new ArrayList<>();
// Walk up the lookup directory path, finding missing directories we get to an existing one
// We will create the ROOT_DIR_NAME directory here if it does not exist.
String lookupDirPath = makeLookupPath(createEntry.getPath());
for (String testPath = lookupDirPath; !testPath.isEmpty(); testPath = fireStoreUtils.getDirectoryPath(testPath)) {
// !!! In this case we are using a lookup path
DocumentSnapshot docSnap = lookupByFilePath(firestore, collectionId, testPath, xn);
if (docSnap.exists()) {
break;
}
FireStoreDirectoryEntry dirToCreate = makeDirectoryEntry(testPath);
createList.add(dirToCreate);
}
for (FireStoreDirectoryEntry dirToCreate : createList) {
xn.set(getDocRef(firestore, collectionId, dirToCreate), dirToCreate);
}
xn.set(getDocRef(firestore, collectionId, createEntry), createEntry);
return null;
});
fireStoreUtils.transactionGet("createFileRef", transaction);
}
use of com.google.cloud.firestore.DocumentSnapshot in project jade-data-repo by DataBiosphere.
the class FireStoreDirectoryDao method storeDirectoryEntry.
// Non-transactional store of a directory entry
private void storeDirectoryEntry(Firestore firestore, String collectionId, FireStoreDirectoryEntry entry) {
try {
DocumentReference newRef = getDocRef(firestore, collectionId, entry);
ApiFuture<DocumentSnapshot> newSnapFuture = newRef.get();
DocumentSnapshot newSnap = newSnapFuture.get();
if (!newSnap.exists()) {
ApiFuture<WriteResult> writeFuture = newRef.set(entry);
writeFuture.get();
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new FileSystemExecutionException("storeDirectoryEntry - execution interrupted", ex);
} catch (AbortedException | ExecutionException ex) {
throw handleExecutionException("storeDirectoryEntry", ex);
}
}
Aggregations