diff --git a/src/main/scala/nl.knaw.dans.easy.bag2deposit/ddm/DdmTransformer.scala b/src/main/scala/nl.knaw.dans.easy.bag2deposit/ddm/DdmTransformer.scala
index cc010af3..699a3b87 100644
--- a/src/main/scala/nl.knaw.dans.easy.bag2deposit/ddm/DdmTransformer.scala
+++ b/src/main/scala/nl.knaw.dans.easy.bag2deposit/ddm/DdmTransformer.scala
@@ -32,12 +32,13 @@ 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,
@@ -45,7 +46,6 @@ class DdmTransformer(cfgDir: File, collectionsMap: Map[String, Elem] = Map.empty
AbrRewriteRule.subjectRewriteRule(cfgDir),
languageRewriteRule,
relationRewriteRule,
- DateCreatedRewriteRule,
)
private def standardRuleTransformer(newDcmiNodes: NodeSeq, profileTitle: String) = new RuleTransformer(
@@ -53,17 +53,23 @@ class DdmTransformer(cfgDir: File, collectionsMap: Map[String, Elem] = Map.empty
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
- { distinctTitles(profileTitle, archaeologyRuleTransformer(node).nonEmptyChildren) }
- { additionalDcmiNodes }
- .copy(prefix = node.prefix, attributes = node.attributes, scope = node.scope)
+ node.label match {
+ case "profile" =>
+
+ { node.nonEmptyChildren.flatMap(ProfileDateRewriteRule) }
+ .copy(prefix = node.prefix, attributes = node.attributes, scope = node.scope)
+ case "dcmiMetadata" =>
+
+ { distinctTitles(profileTitle, dcmiMetadataArchaeologyRuleTransformer(node).nonEmptyChildren) }
+ { additionalDcmiNodes }
+ .copy(prefix = node.prefix, attributes = node.attributes, scope = node.scope)
+ case _ => node
+ }
}
}
@@ -80,6 +86,7 @@ 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)
@@ -87,7 +94,7 @@ class DdmTransformer(cfgDir: File, collectionsMap: Map[String, Elem] = Map.empty
}
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"
diff --git a/src/main/scala/nl.knaw.dans.easy.bag2deposit/ddm/DateCreatedRewriteRule.scala b/src/main/scala/nl.knaw.dans.easy.bag2deposit/ddm/ProfileDateRewriteRule.scala
similarity index 82%
rename from src/main/scala/nl.knaw.dans.easy.bag2deposit/ddm/DateCreatedRewriteRule.scala
rename to src/main/scala/nl.knaw.dans.easy.bag2deposit/ddm/ProfileDateRewriteRule.scala
index ad36c458..3dafe36f 100644
--- a/src/main/scala/nl.knaw.dans.easy.bag2deposit/ddm/DateCreatedRewriteRule.scala
+++ b/src/main/scala/nl.knaw.dans.easy.bag2deposit/ddm/ProfileDateRewriteRule.scala
@@ -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)