in app/model/commands/PublishAtomCommand.scala [34:96]
def process(): T = {
log.info(s"Request to publish atom $id")
val thriftPreviewAtom = getPreviewAtom(id)
val previewAtom = MediaAtom.fromThrift(thriftPreviewAtom)
if(previewAtom.privacyStatus.contains(PrivacyStatus.Private)) {
log.error(s"Unable to publish atom ${previewAtom.id}, privacy status is set to private")
AtomPublishFailed("Atom status set to private")
}
val contentChangeDetails = thriftPreviewAtom.contentChangeDetails
val now = Instant.now().toEpochMilli
(contentChangeDetails.expiry, contentChangeDetails.scheduledLaunch, contentChangeDetails.embargo) match {
case (Some(expiry), _, _) if expiry.date <= now => {
log.error(s"Unable to publish expired atom. atom=${previewAtom.id} expiry=${expiry.date}")
AtomPublishFailed("Atom has expired")
}
case (_, _, Some(embargo)) if embargo.date > now => {
log.error(s"Unable to publish atom with embargo date. atom=${previewAtom.id} embargo=${embargo.date}")
AtomPublishFailed("Atom embargoed")
}
case (_, Some(schedule), _) if schedule.date > now => {
log.error(s"Unable to publish atom as schedule time in the future. atom=${previewAtom.id} schedule=${schedule.date} now=$now")
AtomPublishFailed("Atom scheduled for the future")
}
case (_, Some(schedule), Some(embargo)) if schedule.date < embargo.date => {
log.error(s"Unable to publish atom as embargoed after schedule. atom=${previewAtom.id} schedule=${schedule.date} embargo=${embargo.date}")
AtomPublishFailed("Embargo set after schedule")
}
case (_, _, _) => {
previewAtom.getActiveYouTubeAsset() match {
case Some(asset) =>
val publishedAtom = getPublishedAtom()
val adSettings = AdSettings(youtube.minDurationForAds, youtube.minDurationForMidroll, previewAtom)
val status = getResultingPrivacyStatus(previewAtom, publishedAtom)
val updatedPreviewAtom = if (publishedAtom.isDefined) {
previewAtom.copy(
blockAds = adSettings.blockAds,
privacyStatus = Some(status)
)
} else {
// on first publish, set YouTube title and description to that of the Atom
// this is because there's no guarantee that the YouTube furniture gets subbed before publication and can result in draft furniture being used
previewAtom.copy(
blockAds = adSettings.blockAds,
privacyStatus = Some(status),
youtubeTitle = previewAtom.title,
youtubeDescription = YoutubeDescription.clean(previewAtom.description)
)
}
updateYouTube(publishedAtom, updatedPreviewAtom, asset).map { atomWithYoutubeUpdates =>
publish(atomWithYoutubeUpdates, user)
}
case _ => Future.successful(publish(previewAtom, user))
}
}
}
}