in google-cloud-storage/src/main/scala/org/apache/pekko/stream/connectors/googlecloud/storage/impl/Formats.scala [221:286]
private def storageObjectJsonToStorageObject(storageObjectJson: StorageObjectJson): StorageObject = {
def strToLongOrThrow(str: String, fieldName: String) =
Try(str.toLong)
.getOrElse(throw new RuntimeException(s"Storage object $fieldName is not of type Long"))
def strToDateTimeOrThrow(str: String, fieldName: String) =
Try(OffsetDateTime.parse(str))
.getOrElse(throw new RuntimeException(s"Storage object $fieldName is not a valid OffsetDateTime"))
import storageObjectJson.readable._
import storageObjectJson.writeable._
StorageObject(
kind,
id,
name,
bucket,
generation.toLong,
contentType.map(parseContentType).getOrElse(ContentTypes.`application/octet-stream`),
strToLongOrThrow(size, "size"),
etag,
md5Hash.getOrElse(""),
md5Hash,
crc32c.getOrElse(""),
crc32c,
mediaLink,
selfLink,
strToDateTimeOrThrow(updated, "updated"),
strToDateTimeOrThrow(timeCreated, "timeCreated"),
timeDeleted.map(td => strToDateTimeOrThrow(td, "timeDeleted")),
storageClass,
Option(storageClass),
contentDisposition,
contentEncoding,
contentLanguage,
strToLongOrThrow(metageneration, "metageneration"),
temporaryHold,
eventBasedHold,
retentionExpirationTime.map(ret => strToDateTimeOrThrow(ret, "retentionExpirationTime")),
strToDateTimeOrThrow(timeStorageClassUpdated, "retentionExpirationTime"),
cacheControl,
customTime.map(ct => strToDateTimeOrThrow(ct, "customTime")),
metadata,
componentCount,
kmsKeyName,
customerEncryption.map(ce =>
pekko.stream.connectors.googlecloud.storage
.CustomerEncryption(ce.encryptionAlgorithm, ce.keySha256)),
owner.map(o => pekko.stream.connectors.googlecloud.storage.Owner(o.entity, o.entityId)),
acl.map(
_.map(a =>
pekko.stream.connectors.googlecloud.storage.ObjectAccessControls(
a.kind,
a.id,
a.selfLink,
a.bucket,
a.`object`,
a.generation,
a.entity,
a.role,
a.email,
a.entityId,
a.domain,
pekko.stream.connectors.googlecloud.storage
.ProjectTeam(a.projectTeam.projectNumber, a.projectTeam.team),
a.etag))))
}