Skip to content

Commit

Permalink
Merge pull request #559 from dpla/feature/wiki-uri-provider
Browse files Browse the repository at this point in the history
Add wiki identifier for provider values in the wiki markup
  • Loading branch information
DominicBM authored Oct 19, 2023
2 parents e95c63d + 77e1aad commit 428fec6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
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

0 comments on commit 428fec6

Please sign in to comment.