Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wiki identifier for provider values in the wiki markup #559

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class EnrichmentDriver(conf: i3Conf) extends Serializable {

enriched.copy(
provider = wikiEntityEnrichment.enrichEntity(enriched.provider),

dataProvider = enrichDataProvider(enriched),

sourceResource = enriched.sourceResource.copy(
date = enriched.sourceResource.date.map(date => dateEnrichment.generateBeginEnd(date.originalSourceDate)).distinct,
language = enriched.sourceResource.language.map(languageEnrichment.enrichLanguage).distinct,
Expand Down
33 changes: 24 additions & 9 deletions src/main/scala/dpla/ingestion3/model/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ package object model {
*/
def buildWikiMarkup(record: OreAggregation): String = {
val dataProviderWikiUri = getDataProviderWikiId(record)
val providerWikiUri = getProviderWikiId(record)
val dplaId = getDplaId(record)
val permissionsTemplate = getWikiPermissionTemplate(record.edmRights)
val permissions = record.edmRights.toString match {
Expand All @@ -248,7 +249,7 @@ package object model {
| | permission = {{${permissions}}}
| | source = {{ DPLA
| | ${escapeWikiChars(dataProviderWikiUri)}
| | hub = ${escapeWikiChars(record.provider.name.getOrElse(""))}
| | hub = ${escapeWikiChars(providerWikiUri)}
| | url = ${escapeWikiChars(record.isShownAt.uri.toString)}
| | dpla_id = $dplaId
| | local_id = ${record.sourceResource.identifier.map(escapeWikiChars).mkString("; ")}
Expand Down Expand Up @@ -313,18 +314,32 @@ package object model {
* @param record
* @return
*/
def getDataProviderWikiId(record: OreAggregation): String =
record
.dataProvider
private def getDataProviderWikiId(record: OreAggregation): String = {
getWikiId(record.dataProvider) match {
case Some(uri) => uri
case None =>
throw new RuntimeException(s"dataProvider ${record.dataProvider.name.getOrElse("__MISSING__")} " +
s"in ${getDplaId(record)} does not have wiki identifier ")
}
}

private def getProviderWikiId(record: OreAggregation): String = {
getWikiId(record.provider) match {
case Some(uri) => uri
case None =>
throw new RuntimeException(s"provider ${record.provider.name.getOrElse("__MISSING__")} " +
s"in ${getDplaId(record)} does not have wiki identifier ")
}
}
private def getWikiId(agent: EdmAgent): Option[String] = {
agent
.exactMatch
.map(_.toString)
.find(_.startsWith(WikiUri.baseWikiUri)) match {
case Some(uri) => uri.replace(WikiUri.baseWikiUri, "")
case None =>
throw new RuntimeException(s"dataProvider ${record.dataProvider.name.getOrElse("__MISSING__")} " +
s"in ${getDplaId(record)} does not have wiki identifier ")
case Some(uri) => Some(uri.replace(WikiUri.baseWikiUri, ""))
case None => None
}

}

// Taken from
// https://stackoverflow.com/questions/40128816/remove-json-field-when-empty-value-in-serialize-with-json4s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ object EnrichedRecordFixture {
dplaUri = URI("https://dp.la/item/123"),
originalRecord = "The Original Record",
provider = EdmAgent(
uri = Some(URI("http://dp.la/api/contributor/thedataprovider")),
name = Some("The Provider")
uri = Some(URI("http://dp.la/api/contributor/bscdn")),
name = Some("Big Sky Digital Network"),
exactMatch = Seq(URI(s"${WikiUri.baseWikiUri}Q83878447"))
),
intermediateProvider = Some(
EdmAgent(name = Some("The Intermediate Provider"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WikiMarkupStringTest extends FlatSpec {
| | permission = {{NoC-US | Q83878447}}
| | source = {{ DPLA
| | Q83878447
| | hub = The Provider
| | hub = Q83878447
| | url = https://example.org/record/123
| | dpla_id = 4b1bd605bd1d75ee23baadb0e1f24457
| | local_id = us-history-13243; j-doe-archives-2343
Expand All @@ -40,7 +40,7 @@ class WikiMarkupStringTest extends FlatSpec {
| | permission = {{Cc-by-sa-1.0}}
| | source = {{ DPLA
| | Q83878447
| | hub = The Provider
| | hub = Q83878447
| | url = https://example.org/record/123
| | dpla_id = 4b1bd605bd1d75ee23baadb0e1f24457
| | local_id = us-history-13243; j-doe-archives-2343
Expand Down
Loading