From cd1b635b2ae90d9ac2d8b1779183a1fbd8c5fd5c Mon Sep 17 00:00:00 2001 From: vlad Date: Tue, 13 Jun 2017 16:12:20 -0700 Subject: Adding domain entities --- .../storage/MedicalRecordDocumentStorage.scala | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala (limited to 'src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala') diff --git a/src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala b/src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala new file mode 100644 index 0000000..d50be2c --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/storage/MedicalRecordDocumentStorage.scala @@ -0,0 +1,27 @@ +package xyz.driver.pdsuidomain.storage + +import com.google.cloud.storage.StorageOptions +import com.typesafe.scalalogging.StrictLogging +import xyz.driver.pdsuidomain.entities.MedicalRecord.PdfSource + +import scala.concurrent.{ExecutionContext, Future, blocking} + +object MedicalRecordDocumentStorage extends StrictLogging { + private val storage = StorageOptions.getDefaultInstance.getService + + def fetchPdf(bucket: String, path: String) + (implicit ec: ExecutionContext): Future[PdfSource] = { + logger.trace(s"fetchPdf(bucket=$bucket, path=$path)") + Future { + blocking { + Option(storage.get(bucket, path)) match { + case Some(blob) => + PdfSource.Channel(() => blob.reader()) + case None => + logger.error(s"Failed to find the pdf file $path in bucket: $bucket") + PdfSource.Empty + } + } + } + } +} -- cgit v1.2.3