Skip to content

Commit

Permalink
DD-710: Add agreements.xml to VAULT deposits (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindareijnhoudt authored Dec 13, 2021
1 parent 59786eb commit f9f765f
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 16 deletions.
35 changes: 35 additions & 0 deletions src/main/assembly/dist/cfg/agreements/TESTUSER-agreements.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2019 DANS - Data Archiving and Networked Services ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<agreements xsi:schemaLocation="http://easy.dans.knaw.nl/schemas/bag/metadata/agreements/ https://easy.dans.knaw.nl/schemas/bag/metadata/agreements/agreements.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns="http://easy.dans.knaw.nl/schemas/bag/metadata/agreements/"
>
<depositAgreement contractNumber="20999">
<signerId easy-account="TESTUSER" email="[email protected]">Test User</signerId>
<dcterms:dateAccepted>2019-01-02</dcterms:dateAccepted>
<depositAgreementAccepted>true</depositAgreementAccepted>
</depositAgreement>
<personalDataStatement>
<signerId easy-account="TESTUSER" email="[email protected]">Test User</signerId>
<dateSigned>2019-01-02</dateSigned>
<containsPrivacySensitiveData>true</containsPrivacySensitiveData>
</personalDataStatement>
</agreements>

3 changes: 2 additions & 1 deletion src/main/scala/nl.knaw.dans.easy.bag2deposit/Command.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ object Command extends App with DebugEnhancedLogging {
fedoraProvider = fedoraProvider,
maybePreStagedProvider = if (commandLine.preStaged())
Some(PreStagedProvider(new URI(properties.getString("migration-info.url"))))
else None
else None,
agreementsPath = cfgPath / "agreements"
)
trace(configuration.maybePreStagedProvider)
private val propertiesFactory = DepositPropertiesFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ case class Configuration(version: String,
userTransformer: UserTransformer,
fedoraProvider: Option[FedoraProvider],
maybePreStagedProvider: Option[PreStagedProvider],
agreementsPath: File,
)
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class EasyConvertBagToDepositApp(configuration: Configuration) extends DebugEnha
amdIn <- getAmdXml(datasetId, amdFile)
fromVault = depositProps.getString("deposit.origin") == "VAULT"
amdOut <- configuration.userTransformer.transform(amdIn)
agreementsFile = metadata / "depositor-info" / "agreements.xml"
_ = checkAgreementsXml((amdOut \ "depositorId").text, agreementsFile)
provenanceXml = provenance.collectChangesInXmls(Map(
"http://easy.dans.knaw.nl/easy/dataset-administrative-metadata/" -> compare(amdIn, amdOut),
"http://easy.dans.knaw.nl/schemas/md/ddm/" -> compare(oldDcmi, newDcmi),
Expand Down Expand Up @@ -180,6 +182,23 @@ class EasyConvertBagToDepositApp(configuration: Configuration) extends DebugEnha
}
}

private def checkAgreementsXml(depositorId: String, agreementsFile: File) = {
if (agreementsFile.exists) { //the agreementsfile is created by easy-fedora-to-bag for FEDORA datasets
Success
}
else {
val templateFile: File = configuration.agreementsPath / (depositorId + "-agreements.xml")
if (!templateFile.exists) {
Failure(new FileNotFoundException(templateFile + " not found"))
}
else {
agreementsFile.parent.createIfNotExists(true)
templateFile.copyTo(agreementsFile)
}
}
}


private def copyMigrationFiles(metadata: File, migration: File, fromVault: Boolean): Try[Unit] = Try {
trace(metadata, migration)
val filesXmlFile = (metadata / "files.xml").toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<datasetState>PUBLISHED</datasetState>
<previousState>DRAFT</previousState>
<lastStateChange>2020-02-02T20:02:00.000+01:00</lastStateChange>
<depositorId>user001</depositorId>
<depositorId>TESTUSER</depositorId>
<stateChangeDates>
<damd:stateChangeDate>
<fromState>DRAFT</fromState>
Expand Down

This file was deleted.

35 changes: 35 additions & 0 deletions src/test/resources/debug-config/agreements/TESTUSER-agreements.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2019 DANS - Data Archiving and Networked Services ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<agreements xsi:schemaLocation="http://easy.dans.knaw.nl/schemas/bag/metadata/agreements/ https://easy.dans.knaw.nl/schemas/bag/metadata/agreements/agreements.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns="http://easy.dans.knaw.nl/schemas/bag/metadata/agreements/"
>
<depositAgreement contractNumber="20999">
<signerId easy-account="TESTUSER" email="[email protected]">Test User</signerId>
<dcterms:dateAccepted>2019-01-02</dcterms:dateAccepted>
<depositAgreementAccepted>true</depositAgreementAccepted>
</depositAgreement>
<personalDataStatement>
<signerId easy-account="TESTUSER" email="[email protected]">Test User</signerId>
<dateSigned>2019-01-02</dateSigned>
<containsPrivacySensitiveData>true</containsPrivacySensitiveData>
</personalDataStatement>
</agreements>

25 changes: 25 additions & 0 deletions src/test/scala/nl.knaw.dans.easy.bag2deposit/AppSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import scala.xml.XML
class AppSpec extends AnyFlatSpec with XmlSupport with Matchers with AppConfigSupport with FileSystemSupport {
private val resourceBags: File = File("src/test/resources/bags/01")
private val validUUID = "04e638eb-3af1-44fb-985d-36af12fccb2d"
private val vaultUUID = "87151a3a-12ed-426a-94f2-97313c7ae1f2"

"addPropsToBags" should "move valid exports" in {
val delegate = mock[MockBagIndex]
Expand Down Expand Up @@ -368,6 +369,30 @@ class AppSpec extends AnyFlatSpec with XmlSupport with Matchers with AppConfigSu
normalized(XML.loadFile(filesXml.toJava)) shouldBe normalized(expectedFilesXml)
}

it should "add agreements.xml file to VAULT datasets" in {
val delegate = mock[MockBagIndex]
(delegate.execute(_: String)) expects s"bag-sequence?contains=$vaultUUID" returning
new HttpResponse[String]("123", 200, Map.empty)
(delegate.execute(_: String)) expects s"bags/4722d09d-e431-4899-904c-0733cd773034" returning
new HttpResponse[String]("<result><bag-info><urn>urn:nbn:nl:ui:13-z4-f8cm</urn><doi>10.5072/dans-2xg-umq8</doi></bag-info></result>", 200, Map.empty)
val appConfig = testConfig(delegatingBagIndex(delegate), null)
(appConfig.maybePreStagedProvider.get.get(_: String, _: Int)) expects(*, 1) returning Success(Seq.empty)


(resourceBags / vaultUUID).copyTo(testDir / "exports" / vaultUUID)

new EasyConvertBagToDepositApp(appConfig).addPropsToBags(
(testDir / "exports").children,
maybeOutputDir = Some((testDir / "ingest-dir").createDirectories()),
DepositPropertiesFactory(appConfig, DOI, VAULT)
) shouldBe Success("No fatal errors")

val movedBag = testDir / "ingest-dir" / vaultUUID / "base-bag-not-found"
(resourceBags / vaultUUID / "base-bag-not-found" / "metadata").list.toSeq.map(_.name) shouldNot contain("agreements.xml")
(movedBag / "metadata" ).list.toSeq.map(_.name) should contain("depositor-info")
(movedBag / "metadata" / "depositor-info").list.toSeq.map(_.name) shouldBe Seq("agreements.xml")
}

it should "produce proper prefix in new files.xml elements AND apply preferred user ID" in {
val delegate = mock[MockBagIndex]
val appConfig = testConfig(delegatingBagIndex(delegate), null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ trait AppConfigSupport extends BagIndexSupport with FedoraProviderSupport with P
userTransformer = new UserTransformer(cfgFile),
fedoraProvider = fedoraProvider,
maybePreStagedProvider = Some(preStagedProvider),
agreementsPath = cfgFile / "agreements"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class RewriteSpec extends AnyFlatSpec with XmlSupport with SchemaSupport with Ma
userTransformer = new UserTransformer(cfgDir),
fedoraProvider = None,
maybePreStagedProvider = None,
agreementsPath = cfgDir / "agreements"
))

// a few steps of EasyConvertBagToDepositApp.addPropsToBags
Expand Down

0 comments on commit f9f765f

Please sign in to comment.