Skip to content

Commit

Permalink
DD-731 DateCreatedRewriteRule is not used (#68)
Browse files Browse the repository at this point in the history
* Work in progress
* Last fixes
* Reverted unnecessary change
* Processed code review by @jo-pol
  • Loading branch information
janvanmansum authored Dec 2, 2021
1 parent 1b4e72c commit 59786eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,44 @@ class DdmTransformer(cfgDir: File, collectionsMap: Map[String, Elem] = Map.empty
private val acquisitionRewriteRule = AcquisitionRewriteRule(cfgDir)
private val relationRewriteRule = RelationRewriteRule(cfgDir)
private val languageRewriteRule = LanguageRewriteRule(cfgDir / "languages.csv")
private val profileTitleRuleTransformer = new RuleTransformer(
private val profileArchaeologicalTitleRuleTransformer = new RuleTransformer(
acquisitionRewriteRule,
reportRewriteRule,
relationRewriteRule,
)
private val archaeologyRuleTransformer = new RuleTransformer(

private val dcmiMetadataArchaeologyRuleTransformer = new RuleTransformer(
SplitNrRewriteRule,
acquisitionRewriteRule,
reportRewriteRule,
AbrRewriteRule.temporalRewriteRule(cfgDir),
AbrRewriteRule.subjectRewriteRule(cfgDir),
languageRewriteRule,
relationRewriteRule,
DateCreatedRewriteRule,
)

private def standardRuleTransformer(newDcmiNodes: NodeSeq, profileTitle: String) = new RuleTransformer(
NewDcmiNodesRewriteRule(newDcmiNodes),
DistinctTitlesRewriteRule(profileTitle),
relationRewriteRule,
languageRewriteRule,
DateCreatedRewriteRule,
ProfileDateRewriteRule,
)

private case class ArchaeologyRewriteRule(profileTitle: String, additionalDcmiNodes: NodeSeq) extends RewriteRule {
override def transform(node: Node): Seq[Node] = {
// TODO apply NewDcmiNodesRewriteRule/DistinctTitlesRewriteRule instead
if (node.label != "dcmiMetadata") node
else <dcmiMetadata>
{ distinctTitles(profileTitle, archaeologyRuleTransformer(node).nonEmptyChildren) }
{ additionalDcmiNodes }
</dcmiMetadata>.copy(prefix = node.prefix, attributes = node.attributes, scope = node.scope)
node.label match {
case "profile" =>
<profile>
{ node.nonEmptyChildren.flatMap(ProfileDateRewriteRule) }
</profile>.copy(prefix = node.prefix, attributes = node.attributes, scope = node.scope)
case "dcmiMetadata" =>
<dcmiMetadata>
{ distinctTitles(profileTitle, dcmiMetadataArchaeologyRuleTransformer(node).nonEmptyChildren) }
{ additionalDcmiNodes }
</dcmiMetadata>.copy(prefix = node.prefix, attributes = node.attributes, scope = node.scope)
case _ => node
}
}
}

Expand All @@ -80,14 +86,15 @@ class DdmTransformer(cfgDir: File, collectionsMap: Map[String, Elem] = Map.empty
.toSeq ++ unknownRightsHolder(ddmIn)

val profile = ddmIn \ "profile"

if (!(profile \ "audience").text.contains("D37000")) {
// not archaeological
val transformer = standardRuleTransformer(newDcmiNodes, (profile \ "title").text)
Success(transformer(ddmIn))
}
else {
// a title in the profile will not change but may produce something for dcmiMetadata
val transformedProfile = profile.flatMap(profileTitleRuleTransformer)
val transformedProfile = profile.flatMap(profileArchaeologicalTitleRuleTransformer)
val fromFirstTitle = transformedProfile.flatMap(_.nonEmptyChildren)
.diff(profile.flatMap(_.nonEmptyChildren))
val notConvertedFirstTitle = transformedProfile \ "title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ package nl.knaw.dans.easy.bag2deposit.ddm
import scala.xml.transform.RewriteRule
import scala.xml.{ Elem, Node, Text }

object DateCreatedRewriteRule extends RewriteRule {
object ProfileDateRewriteRule extends RewriteRule {
val DDM_NAMESPACE = "http://easy.dans.knaw.nl/schemas/md/ddm/"

override def transform(node: Node): Seq[Node] = node match {
case e: Elem if e.label == "created" =>
case e: Elem if (e.label == "created" || e.label == "available") && e.namespace == DDM_NAMESPACE =>
if (e.text.trim.length == 7)
e.copy(child = Text(e.text.trim + "-01"))
else if (e.text.trim.length == 4)
Expand Down

0 comments on commit 59786eb

Please sign in to comment.