Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DANS-KNAW/easy-convert-bag-to-dep…
Browse files Browse the repository at this point in the history
…osit
  • Loading branch information
lindareijnhoudt committed Jan 19, 2022
2 parents 75834b9 + 36a23a5 commit 1db8b8a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class EasyConvertBagToDepositApp(configuration: Configuration) extends DebugEnha
newDcmi = (ddmOut \ "dcmiMetadata").headOption.getOrElse(<dcmiMetadata/>)
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"
Expand Down Expand Up @@ -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(
Expand Down
29 changes: 23 additions & 6 deletions src/test/scala/nl.knaw.dans.easy.bag2deposit/AppSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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("<depositorId>user001</depositorId>")

new EasyConvertBagToDepositApp(appConfig).addPropsToBags(
(testDir / "exports").children,
maybeOutputDir = Some((testDir / "ingest-dir").createDirectories()),
Expand Down

0 comments on commit 1db8b8a

Please sign in to comment.