Skip to content

Commit

Permalink
DD-733: Add dans license to restricted datasets without license (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-pol authored Jan 18, 2022
1 parent 927cd21 commit 32396e8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Fixes EASY-
Fixes DD-

When applied it will
--------------------
Expand All @@ -11,6 +11,7 @@ Where should the reviewer @DANS-KNAW/easy start?

How should this be manually tested?
-----------------------------------
* [ ] ran `mvn clean install` witout `-DskipTests `

Related pull requests on github
-------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import nl.knaw.dans.easy.bag2deposit.ddm.LanguageRewriteRule.logNotMappedLanguag
import nl.knaw.dans.easy.bag2deposit.ddm.ReportRewriteRule.logBriefRapportTitles
import nl.knaw.dans.lib.logging.DebugEnhancedLogging

import scala.util.{ Failure, Success, Try }
import scala.xml.transform.{ RewriteRule, RuleTransformer }
import scala.xml.{ Elem, Node, NodeSeq }
import scala.util.{Failure, Success, Try}
import scala.xml.transform.{RewriteRule, RuleTransformer}
import scala.xml.{Elem, Node, NodeSeq, Text}

class DdmTransformer(cfgDir: File, collectionsMap: Map[String, Seq[Elem]] = Map.empty) extends DebugEnhancedLogging {
trace(())
Expand Down Expand Up @@ -84,8 +84,9 @@ class DdmTransformer(cfgDir: File, collectionsMap: Map[String, Seq[Elem]] = Map.
trace(datasetId)
val tmp = collectionsMap.mapValues(_.size).filter(_._2>1).keys.toList.sortBy(identity)
trace(tmp.mkString(","))
val newDcmiNodes = collectionsMap.get(datasetId)
.toSeq.flatten ++ unknownRightsHolder(ddmIn)
val newDcmiNodes = missingLicense(ddmIn) ++
collectionsMap.get(datasetId).toSeq.flatten ++
unknownRightsHolder(ddmIn)

val profile = ddmIn \ "profile"

Expand Down Expand Up @@ -119,5 +120,17 @@ class DdmTransformer(cfgDir: File, collectionsMap: Map[String, Seq[Elem]] = Map.
logNotMappedLanguages(ddm, datasetId)
ddm
}

private def missingLicense(ddm: Node): Seq[Node] = {
val value = (ddm \\ "license").nonEmpty
if (value) Seq.empty
else {
(ddm \\ "accessRights").headOption.map(_.text match {
case "OPEN_ACCESS_FOR_REGISTERED_USERS" | "REQUEST_PERMISSION" =>
<dcterms:license xsi:type="dcterms:URI">http://dans.knaw.nl/en/about/organisation-and-policy/legal-information/DANSLicence.pdf</dcterms:license>
case _ => Text("")
}).getOrElse(Seq.empty)
}
}
}

34 changes: 31 additions & 3 deletions src/test/scala/nl.knaw.dans.easy.bag2deposit/ddm/RewriteSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
package nl.knaw.dans.easy.bag2deposit.ddm

import better.files.File
import nl.knaw.dans.easy.bag2deposit.Fixture.{ DdmSupport, SchemaSupport, XmlSupport }
import nl.knaw.dans.easy.bag2deposit.Fixture.{DdmSupport, SchemaSupport, XmlSupport}
import nl.knaw.dans.easy.bag2deposit.ddm.LanguageRewriteRule.logNotMappedLanguages
import nl.knaw.dans.easy.bag2deposit.{ BagIndex, Configuration, EasyConvertBagToDepositApp, InvalidBagException, AmdTransformer, parseCsv }
import nl.knaw.dans.easy.bag2deposit.{AmdTransformer, BagIndex, Configuration, EasyConvertBagToDepositApp, InvalidBagException, parseCsv}
import org.apache.commons.csv.CSVRecord
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

import java.net.URI
import java.nio.charset.Charset
import java.util.UUID
import scala.util.{ Failure, Success, Try }
import scala.util.{Failure, Success, Try}

class RewriteSpec extends AnyFlatSpec with XmlSupport with SchemaSupport with Matchers with DdmSupport {
private val cfgDir: File = File("src/main/assembly/dist/cfg")
Expand Down Expand Up @@ -602,4 +602,32 @@ class RewriteSpec extends AnyFlatSpec with XmlSupport with SchemaSupport with Ma
archisIds.size shouldNot be(strings.size)
strings.filter(_.matches(".*[^0-9].*")) shouldBe Seq("10HZ-18 (Objectcode Archis)", "36141 (ARCHIS rapportnummer)", " 405800 (Archis nummers)", "http://livelink.archis.nl/Livelink/livelink.exe?func=ll&objId=4835986&objAction=browse (URI)", "66510 (Archisnummer)", "ARCHIS2: 63389", "Onderzoeksnaam Archis: 4042 Den Haag", "Objectnummer Archis: 1121031", "Archis2 nummer 65495", "3736 (RAAP) (Archis art. 41)", "6663 (ADC) (Archis art. 41)", "2866 (RAAP) (Archis art. 41)", "7104 (ADC) (Archis art. 41)", "16065 (BeVdG) (Archis art. 41)", "Archis2: CIS-code: 25499 (Tjeppenboer) en 25500 (Hilaard)")
}
it should "add dans license" in {
val transformer = new DdmTransformer(cfgDir, Map.empty)
val ddmIn = ddm(
<ddm:profile><ddm:accessRights>REQUEST_PERMISSION</ddm:accessRights></ddm:profile>
<ddm:dcmiMetadata/>
)
transformer.transform(ddmIn, "easy-dataset:123").map(normalized) shouldBe Success(normalized(ddm(
<ddm:profile><ddm:accessRights>REQUEST_PERMISSION</ddm:accessRights></ddm:profile>
<ddm:dcmiMetadata>
<dcterms:license xsi:type="dcterms:URI">http://dans.knaw.nl/en/about/organisation-and-policy/legal-information/DANSLicence.pdf</dcterms:license>
<dcterms:rightsHolder>Unknown</dcterms:rightsHolder>
</ddm:dcmiMetadata>
)))
}
it should "keep the original license" in {
val transformer = new DdmTransformer(cfgDir, Map.empty)
val ddmIn = ddm(
<ddm:profile><ddm:accessRights>OPEN_ACCESS_FOR_REGISTERED_USERS</ddm:accessRights></ddm:profile>
<ddm:dcmiMetadata><dcterms:license xsi:type="dcterms:URI">http://does.not.exist.dans.knaw.nl</dcterms:license></ddm:dcmiMetadata>
)
transformer.transform(ddmIn, "easy-dataset:123").map(normalized) shouldBe Success(normalized(ddm(
<ddm:profile><ddm:accessRights>OPEN_ACCESS_FOR_REGISTERED_USERS</ddm:accessRights></ddm:profile>
<ddm:dcmiMetadata>
<dcterms:license xsi:type="dcterms:URI">http://does.not.exist.dans.knaw.nl</dcterms:license>
<dcterms:rightsHolder>Unknown</dcterms:rightsHolder>
</ddm:dcmiMetadata>
)))
}
}

0 comments on commit 32396e8

Please sign in to comment.