Skip to content

Commit

Permalink
Merge pull request #4374 from guardian/fix-usages-templates-issue
Browse files Browse the repository at this point in the history
Fix usages stream for cartoons
  • Loading branch information
simonbyford authored Dec 5, 2024
2 parents 2f84440 + 4fe88bd commit 8801a8f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ val commonSettings = Seq(
"org.mockito" % "mockito-core" % "2.18.0" % Test,
"org.scalamock" %% "scalamock" % "5.1.0" % Test,
),
dependencyOverrides += "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.14.3",
dependencyOverrides += "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.17.2",

Compile / doc / sources := Seq.empty,
Compile / packageDoc / publishArtifact := false
Expand Down Expand Up @@ -171,8 +171,8 @@ lazy val thrall = playProject("thrall", 9002)

lazy val usage = playProject("usage", 9009).settings(
libraryDependencies ++= Seq(
"com.gu" %% "content-api-client-default" % "19.0.4",
"com.gu" %% "content-api-client-aws" % "0.7",
"com.gu" %% "content-api-client-default" % "32.0.0",
"com.gu" %% "content-api-client-aws" % "0.7.6",
"io.reactivex" %% "rxscala" % "0.27.0",
"com.amazonaws" % "amazon-kinesis-client" % "1.8.10",
"com.google.protobuf" % "protobuf-java" % "3.19.6"
Expand Down
2 changes: 1 addition & 1 deletion usage/app/lib/ContentApis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class UsageContentApiClient(config: UsageConfig)(implicit val executor:
def usageQuery(contentId: String): ItemQuery = {
ItemQuery(contentId)
.showFields("firstPublicationDate,isLive,internalComposerCode")
.showElements("image")
.showElements("image,cartoon")
.showAtoms("media")
}
}
Expand Down
23 changes: 20 additions & 3 deletions usage/app/model/UsageGroup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,26 @@ class UsageGroupOps(config: UsageConfig, mediaWrapperOps: MediaWrapperOps)
val mediaAtomsUsages = extractMediaAtoms(content, usageStatus, isReindex)(extractJobLogMarkers).flatMap { atom =>
getImageId(atom) match {
case Some(id) =>
val mediaWrapper = mediaWrapperOps.build(id, contentWrapper, buildId(contentWrapper))
val mediaWrapper = mediaWrapperOps.build(mediaId = id, contentWrapper = contentWrapper, usageGroupId = buildId(contentWrapper))
val usage = MediaUsageBuilder.build(mediaWrapper)
Seq(createUsagesLogging(usage)(logMarker))
case None => Seq.empty
}
}
val imageElementUsages = extractImageElements(content, usageStatus, isReindex)(extractJobLogMarkers).map { element =>
val mediaWrapper = mediaWrapperOps.build(element.id, contentWrapper, buildId(contentWrapper))
val mediaWrapper = mediaWrapperOps.build(mediaId = element.id, contentWrapper = contentWrapper, usageGroupId = buildId(contentWrapper))
val usage = MediaUsageBuilder.build(mediaWrapper)
createUsagesLogging(usage)(logMarker)
}
val cartoonElementUsages = extractCartoonUniqueMediaIds(content).map { mediaId =>
val mediaWrapper = mediaWrapperOps.build(mediaId, contentWrapper = contentWrapper, usageGroupId = buildId(contentWrapper))
val usage = MediaUsageBuilder.build(mediaWrapper)
createUsagesLogging(usage)(logMarker)
}

// TODO capture images from interactive embeds

mediaAtomsUsages ++ imageElementUsages
mediaAtomsUsages ++ imageElementUsages ++ cartoonElementUsages
}

private def createUsagesLogging(usage: MediaUsage)(implicit logMarker: LogMarker) = {
Expand Down Expand Up @@ -202,6 +207,18 @@ class UsageGroupOps(config: UsageConfig, mediaWrapperOps: MediaWrapperOps)
}
}

private def extractCartoonUniqueMediaIds(content: Content): Set[String] =
(for {
elements <- content.elements.toSeq
cartoonElement <- elements.filter(_.`type` == ElementType.Cartoon)
asset <- cartoonElement.assets.toSeq
data <- asset.typeData.toSeq
cartoonVariants <- data.cartoonVariants.toSeq
cartoonVariant <- cartoonVariants
image <- cartoonVariant.images
mediaId <- image.mediaId
} yield mediaId).toSet

private def extractImageElements(
content: Content, usageStatus: UsageStatus, isReindex: Boolean
)(implicit logMarker: LogMarker): Seq[Element] = {
Expand Down

0 comments on commit 8801a8f

Please sign in to comment.