-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support recipe schema.org metadata from CAPI in LinkedData (#26931)
* Retrieves new CAPI model content field `schemaOrg` in CAPI item requests * Renames fields (`_atType`, `_atContext` to `@type`, `@context`) due to a Thrift incompatibility with the `@` sign * Includes the `recipe` part of the `schemaOrg` object in the `LinkedData` for consumption by DCR --------- Co-authored-by: frederickobrien <[email protected]> Co-authored-by: Andy Gallagher <[email protected]> Co-authored-by: Alina Boghiu <[email protected]>
- Loading branch information
1 parent
198684c
commit 213c2bc
Showing
51 changed files
with
246 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package model.dotcomrendering | ||
|
||
import com.gu.contentapi.client.model.schemaorg.{RecipeStep, SchemaOrg, SchemaRecipe} | ||
import com.gu.contentapi.client.model.v1.{CapiDateTime, Tag, TagType, Content => ApiContent} | ||
import com.gu.contentapi.client.utils.CapiModelEnrichment.RichOffsetDateTime | ||
import model.{Article, Content, ContentType, DotcomContentType, MetaData, RelatedContent} | ||
import conf.Configuration | ||
import org.mockito.Mockito.when | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatestplus.mockito.MockitoSugar | ||
import test.{TestRequest, WithTestExecutionContext} | ||
import org.joda.time.{DateTime, DateTimeZone} | ||
|
||
import java.time.ZoneOffset | ||
import implicits.Dates.jodaToJavaInstant | ||
import play.api.libs.json.Json | ||
|
||
class LinkedDataTest extends AnyFlatSpec with Matchers with MockitoSugar { | ||
|
||
val publishDate = Some(jodaToJavaInstant(new DateTime()).atOffset(ZoneOffset.UTC).toCapiDateTime) | ||
|
||
val testArticle = { | ||
val item = ApiContent( | ||
id = "foo/2012/jan/07/bar", | ||
sectionId = None, | ||
sectionName = None, | ||
webPublicationDate = publishDate, | ||
webTitle = "Some article", | ||
webUrl = "http://www.guardian.co.uk/foo/2012/jan/07/bar", | ||
apiUrl = "http://content.guardianapis.com/foo/2012/jan/07/bar", | ||
tags = List(), | ||
elements = None, | ||
schemaOrg = None, | ||
) | ||
Article.make(Content.make(item)) | ||
} | ||
|
||
val testArticleWithRecipe = { | ||
val item = ApiContent( | ||
id = "foo/2012/jan/07/bar", | ||
sectionId = None, | ||
sectionName = None, | ||
webPublicationDate = publishDate, | ||
webTitle = "Some article", | ||
webUrl = "http://www.guardian.co.uk/foo/2012/jan/07/bar", | ||
apiUrl = "http://content.guardianapis.com/foo/2012/jan/07/bar", | ||
tags = List(), | ||
elements = None, | ||
schemaOrg = Some( | ||
SchemaOrg( | ||
recipe = Some( | ||
Seq( | ||
SchemaRecipe( | ||
_atContext = "http://schema.org", | ||
_atType = "Recipe", | ||
name = Some("Test recipe"), | ||
description = Some("This is yummy"), | ||
image = Some("https://path.to/image/on/server.jpg"), | ||
datePublished = Some("2012-01-02T03:04:05Z"), | ||
url = Some("https://path.to/content/on/server.html"), | ||
recipeCategory = Some(Seq("test", "food")), | ||
recipeCuisine = Some(Seq("test", "British")), | ||
recipeIngredient = Some(Seq("23 litres of sprunge", "6 baked beans")), | ||
recipeInstructions = Some( | ||
Seq( | ||
RecipeStep( | ||
_atType = "HowToStep", | ||
text = "Open the can", | ||
name = Some("Open"), | ||
url = None, | ||
image = None, | ||
), | ||
RecipeStep( | ||
_atType = "HowToStep", | ||
text = "Pour the contents", | ||
name = Some("Pour"), | ||
url = None, | ||
image = None, | ||
), | ||
), | ||
), | ||
recipeYield = Some(Seq("1 serving")), | ||
prepTime = Some("30 seconds"), | ||
cookTime = Some("10 hours"), | ||
totalTime = Some("10 hours 30 seconds"), | ||
author = Some( | ||
com.gu.contentapi.client.model.schemaorg | ||
.AuthorInfo(_atType = "Person", name = "John Smith", sameAs = None), | ||
), | ||
suitableForDiet = Some(Seq("https://schema.org/VeganDiet", "https://schema.org/VegetarianDiet")), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
) | ||
Article.make(Content.make(item)) | ||
} | ||
|
||
/// This string should always correct validate at https://validator.schema.org/ | ||
val expectedRecipeJson = | ||
"""{"@context":"http://schema.org","@type":"Recipe","name":"Test recipe","description":"This is yummy","image":"https://path.to/image/on/server.jpg","datePublished":"2012-01-02T03:04:05Z","url":"https://path.to/content/on/server.html","recipeCategory":["test","food"],"recipeCuisine":["test","British"],"recipeIngredient":["23 litres of sprunge","6 baked beans"],"recipeInstructions":[{"@type":"HowToStep","text":"Open the can","name":"Open"},{"@type":"HowToStep","text":"Pour the contents","name":"Pour"}],"recipeYield":["1 serving"],"prepTime":"30 seconds","cookTime":"10 hours","totalTime":"10 hours 30 seconds","author":{"@type":"Person","name":"John Smith"},"suitableForDiet":["https://schema.org/VeganDiet","https://schema.org/VegetarianDiet"]}""" | ||
|
||
"LinkedData.forArticle" should "return news article linkedData" in { | ||
val linkedData = LinkedData.forArticle( | ||
article = testArticle, | ||
baseURL = Configuration.dotcom.baseUrl, | ||
fallbackLogo = Configuration.images.fallbackLogo, | ||
) | ||
|
||
linkedData.length shouldEqual (2) | ||
linkedData.head.`@type` shouldEqual ("NewsArticle") | ||
linkedData(1).`@type` shouldEqual ("WebPage") | ||
} | ||
|
||
"LinkedData.forArticle" should "return recipe linkedData if there is any present" in { | ||
val linkedData = LinkedData.forArticle( | ||
article = testArticleWithRecipe, | ||
baseURL = Configuration.dotcom.baseUrl, | ||
fallbackLogo = Configuration.images.fallbackLogo, | ||
) | ||
|
||
linkedData.foreach(d => println(d)) | ||
linkedData.length shouldEqual (3) | ||
linkedData.head.`@type` shouldEqual ("NewsArticle") | ||
linkedData(1).`@type` shouldEqual ("WebPage") | ||
|
||
val jsonString = Json.toJson(linkedData(2)).toString() | ||
println(jsonString) | ||
jsonString shouldEqual (expectedRecipeJson) | ||
} | ||
} |
Binary file added
BIN
+695 KB
data/database/1704d93a18159317866a160f41a123f644bf0a6944bc238e002a0a04be41c1c4
Binary file not shown.
Binary file added
BIN
+1 MB
data/database/1bc75495e7c942c9ca4bc7b686d52a2223ff62071ab01c57117189352e603feb
Binary file not shown.
Binary file added
BIN
+16 KB
data/database/1f72742ff5464c3462f608c278da357737528b144aae9e9d891ae9e7bcae6e50
Binary file not shown.
Binary file added
BIN
+32 KB
data/database/234b6001ffebf904374614a82889da22dc98891a8c3130eed53d260db4305faa
Binary file not shown.
Binary file added
BIN
+16 KB
data/database/258b9b6c75fa024dee899537b49371bca00b0fc6ec234f631d2f554b643e882a
Binary file not shown.
Binary file added
BIN
+256 KB
data/database/282426917b0bb5c4a3dc97271b9d8025b3ca146a5cccae01352ff532fcdc3b5c
Binary file not shown.
Binary file added
BIN
+32 KB
data/database/3911ccfdc0f59cbd3c2732ecb60175e5c1fe03710b8c89df946e0d514bdaa2f1
Binary file not shown.
Binary file added
BIN
+348 KB
data/database/40072292ecd45e3cba6d32650aafff82f30c89f020b3d62d2014716061235989
Binary file not shown.
Binary file added
BIN
+512 KB
data/database/5345932d44e8854dfc215bd13d7c6436904b199af6a4156cdac52cea5a84cb04
Binary file not shown.
Binary file added
BIN
+256 KB
data/database/54305be7a26e61bf18791ad9cade9ffdd20efd5e494671a522c17e542e166bf7
Binary file not shown.
Binary file added
BIN
+32 KB
data/database/593b6b78e3fa6fda1798ab9c89dd52dbf72041157d0ca08f2e6e00f48549ef87
Binary file not shown.
Binary file added
BIN
+32 KB
data/database/5c2ee59ae981f71fb8e2d03cd3ca4d2fe09158ae15b48dc0f3b0f7e8f6aafa3a
Binary file not shown.
Binary file added
BIN
+128 KB
data/database/5debd1bb6593509c136aa0c7a4796b11eee952cc0cb360b2af98a7a2c811bcdc
Binary file not shown.
Binary file added
BIN
+256 KB
data/database/5e7eea2045af29b480014b60e65622e4b79f0e5648f3c4bf8587a88d3b32fddf
Binary file not shown.
Binary file added
BIN
+128 KB
data/database/6346ed6536b7be3fd32ffaccbf29ccd94e0c1725c22b7b00ae6c9e9ef454146c
Binary file not shown.
Binary file added
BIN
+128 KB
data/database/6ce6d81bc9655c8b5a3c4ee157c1c1c7a0b8833ff4713718c52707c27b3322b4
Binary file not shown.
Binary file added
BIN
+16 KB
data/database/6efe7479f6ef18fcf7fac56778937820ecd19d60d6042ae61d73d9e3781ef23a
Binary file not shown.
Binary file added
BIN
+16 KB
data/database/6f693e458c1ae63f0d588dc1265e5c7b87f02273e3d970e1d34a0c6d0a300f3b
Binary file not shown.
Binary file added
BIN
+256 KB
data/database/7248425a9f3959e00da855c73c9fef197d0f7d9d733f523bc555986dde764284
Binary file not shown.
Binary file added
BIN
+32 KB
data/database/7f3b1c2a95d0e5f1a613a39c701d690ccae5afd31125cbfc333e2ee3fa714e7c
Binary file not shown.
Binary file added
BIN
+512 KB
data/database/821e3a729cb8d0d463682f87cab2d60ec04430872f4b418379443f3a68ef3254
Binary file not shown.
Binary file added
BIN
+128 KB
data/database/84ee25bff47ef754305ae548a39ba13e391bd98894c1b722ddeea8b8e1dc4d80
Binary file not shown.
Binary file added
BIN
+628 KB
data/database/89bb4573e8d69e7cb7e8b53e59bd172e00759ec75a62b5e0b3aa4b0745cf3b6d
Binary file not shown.
Binary file added
BIN
+64 KB
data/database/8ac5965735782c310cc8b306504a1e3cc65ef5fe5696ff66e0f2b31f2b456161
Binary file not shown.
Binary file added
BIN
+32 KB
data/database/90d7c62ec1387a2aec8e739786f5174e2fc9c114b68b006fac41b4c5b0a4b3fe
Binary file not shown.
Binary file added
BIN
+32 KB
data/database/9332cd98b74f9dd374601ae0b2936fda8ef34ddda2f9bec8c290af80ba58f58c
Binary file not shown.
Binary file added
BIN
+512 KB
data/database/95008b40e541cc24eae7909454e901828d7f2d6a93f0c08bffee3c55b5c6cde6
Binary file not shown.
Binary file added
BIN
+16 KB
data/database/9c23a077df634d7666c101aeacf87242d74633cd55805f17e0faf32ab3120ef8
Binary file not shown.
Binary file added
BIN
+256 KB
data/database/a6f16a24445a3cd1508aa6d41e2e1ae92f27dd9281f5332216d93c85cb2ac5a8
Binary file not shown.
Binary file added
BIN
+695 KB
data/database/aafd4adcfe652c5b52953fec948b79627edcc16e22d07d5710a8602581a826bb
Binary file not shown.
Binary file added
BIN
+16 KB
data/database/ba90b82b17fe2503ffe8a949ef2e773f39de0d418382d901f33f6a8237b2ac27
Binary file not shown.
Binary file added
BIN
+64 KB
data/database/bf5dab439649e2c848b005463f32904f6817cad41921bb7d1f0d06ab79d4db9e
Binary file not shown.
Binary file added
BIN
+32 KB
data/database/c21a2442f0f523edd857cd061e98776bcc570ffee659d34d8b7f2fff405458b0
Binary file not shown.
Binary file added
BIN
+128 KB
data/database/c53d720376e76c0d8db84d9bacf9a740847f398b00df2dda8813201e84cb231e
Binary file not shown.
Binary file added
BIN
+256 KB
data/database/c640e4f6abb3dc7d68d37da8864863a39be514010e408c67c9bef1a81261a1c3
Binary file not shown.
Binary file added
BIN
+32 KB
data/database/ca9962ea35e2c965300115f260f39b6057e14af53796fc8ebf21e43586bbb52e
Binary file not shown.
Binary file added
BIN
+512 KB
data/database/d7b20d784d221ff45de3480f7df4eb283d81b3fe719bfe187bf7e85f6b7a15a7
Binary file not shown.
Binary file added
BIN
+16 KB
data/database/d88eb0d60780e5a0eea1afe1f81be8fd7f3cd72ae846c63f2e920dc71448ddcd
Binary file not shown.
Binary file added
BIN
+512 KB
data/database/db2f06ca7c53a079c790826f277704227b48632b5105aabe8509c3ab858e53dd
Binary file not shown.
Binary file added
BIN
+256 KB
data/database/dc1e2b492d19ab7bfe16ef54c28b87d204a0b8fcca4824907414367bedcba9ca
Binary file not shown.
Binary file added
BIN
+348 KB
data/database/e070c4a7dbb65fd3120b5eb29fb68e44eadda494d456aeb50f7697534a4de1e3
Binary file not shown.
Binary file added
BIN
+32 KB
data/database/e389fc65b3c6e29a8c770cc6a828206f30ce2c455bfd2efbcf5db80ea0142103
Binary file not shown.
Binary file added
BIN
+1.23 MB
data/database/e76ee61a87f1ceea0ef12a381c7dba0d287438af460303b48b28ffd9fd43a178
Binary file not shown.
Binary file added
BIN
+64 KB
data/database/f62fc2ab202b194274850db63abba9a54a6f5148f18b51528a1d29919122672c
Binary file not shown.
Binary file added
BIN
+128 KB
data/database/fe8e58e5de60057c402b5ad4fbd3d332776725fd35cc19ce7b99189e493bb037
Binary file not shown.
Binary file added
BIN
+695 KB
data/database/ff8403d3c30d1bc77cd52bbefdecbcdd11028f505413f5b63347fa5fdd2ae9d8
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters