From 36a23a5cbe7ccfce03153eca0a4a6198110ff028 Mon Sep 17 00:00:00 2001 From: Jo Pol Date: Wed, 19 Jan 2022 10:31:36 +0100 Subject: [PATCH] DD-796: process hidden bags unless state!=deleted (#77) --- .../EasyConvertBagToDepositApp.scala | 4 ++- .../AppSpec.scala | 29 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/scala/nl.knaw.dans.easy.bag2deposit/EasyConvertBagToDepositApp.scala b/src/main/scala/nl.knaw.dans.easy.bag2deposit/EasyConvertBagToDepositApp.scala index 9d716dfb..5a2b73f2 100644 --- a/src/main/scala/nl.knaw.dans.easy.bag2deposit/EasyConvertBagToDepositApp.scala +++ b/src/main/scala/nl.knaw.dans.easy.bag2deposit/EasyConvertBagToDepositApp.scala @@ -107,6 +107,8 @@ class EasyConvertBagToDepositApp(configuration: Configuration) extends DebugEnha newDcmi = (ddmOut \ "dcmiMetadata").headOption.getOrElse() amdFile = metadata / "amd.xml" amdIn <- getAmdXml(datasetId, amdFile) + _ = if (bagDir.name.startsWith(".") && (amdIn \\ "datasetState").text != "DELETED") + throw InvalidBagException(s"Inactive bag does not have state DELETED: $amdFile") fromVault = depositProps.getString("deposit.origin") == "VAULT" amdOut <- configuration.amdTransformer.transform(amdIn, ddmOut \ "ddm:created") agreementsFile = metadata / "depositor-info" / "agreements.xml" @@ -226,7 +228,7 @@ class EasyConvertBagToDepositApp(configuration: Configuration) extends DebugEnha private def getBagDir(bagParentDir: File): Try[File] = Try { trace(bagParentDir) - val children = bagParentDir.children.toList + val children = bagParentDir.list.toList if (children.size > 1) throw InvalidBagException(s"more than just one item in $bagParentDir") children.find(_.isDirectory).getOrElse( diff --git a/src/test/scala/nl.knaw.dans.easy.bag2deposit/AppSpec.scala b/src/test/scala/nl.knaw.dans.easy.bag2deposit/AppSpec.scala index 1b5574ff..e3134657 100644 --- a/src/test/scala/nl.knaw.dans.easy.bag2deposit/AppSpec.scala +++ b/src/test/scala/nl.knaw.dans.easy.bag2deposit/AppSpec.scala @@ -17,14 +17,14 @@ package nl.knaw.dans.easy.bag2deposit import better.files.File import nl.knaw.dans.easy.bag2deposit.BagSource._ -import nl.knaw.dans.easy.bag2deposit.Fixture.{ AppConfigSupport, FileSystemSupport, XmlSupport } +import nl.knaw.dans.easy.bag2deposit.Fixture.{AppConfigSupport, FileSystemSupport, XmlSupport} import nl.knaw.dans.easy.bag2deposit.IdType._ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import scalaj.http.HttpResponse import scala.language.postfixOps -import scala.util.{ Success, Try } +import scala.util.{Failure, Success, Try} import scala.xml.XML class AppSpec extends AnyFlatSpec with XmlSupport with Matchers with AppConfigSupport with FileSystemSupport { @@ -169,6 +169,27 @@ class AppSpec extends AnyFlatSpec with XmlSupport with Matchers with AppConfigSu normalized(XML.loadFile(amdXml.toJava)) shouldBe normalized(getAmdResult) } + it should "complain about inactive bag without state deleted" in { + val delegate = mock[MockBagIndex] + (delegate.execute(_: String)) expects s"bag-sequence?contains=$validUUID" returning + new HttpResponse[String]("123", 200, Map.empty) + + val appConfig = testConfig(delegatingBagIndex(delegate), Some(mock[MockFedoraProvider])) + + val bagDir = (resourceBags / validUUID).copyTo(testDir / "exports" / validUUID) + .children.toList.head + val hiddenBag = testDir / "exports" / validUUID / s".${bagDir.name}" + bagDir.moveTo(hiddenBag) + + val outputDir = (testDir / "ingest-dir").createDirectories() + new EasyConvertBagToDepositApp(appConfig).addPropsToBags( + bagParentDirs = (testDir / "exports").children, + maybeOutputDir = Some(outputDir), + properties = DepositPropertiesFactory(appConfig, DOI, VAULT) + ) shouldBe Success("No fatal errors") + outputDir.list shouldBe empty + } + it should "remove pre-staged files" in { val preStagedProvider = { @@ -437,10 +458,6 @@ class AppSpec extends AnyFlatSpec with XmlSupport with Matchers with AppConfigSu (testBag / "metadata" / "files.xml") .writeText(originalFilesXml.serialize) - // pre-condition: another user than in account-substitutes.csv - (testBag / "metadata" / "amd.xml").contentAsString should - include("user001") - new EasyConvertBagToDepositApp(appConfig).addPropsToBags( (testDir / "exports").children, maybeOutputDir = Some((testDir / "ingest-dir").createDirectories()),