Skip to content

Commit

Permalink
EASY-2390: Zet dans-doi-action op 'update' als DOI en BASE-REVISION z…
Browse files Browse the repository at this point in the history
…ijn gegeven (#157)
  • Loading branch information
vesaakerman authored Aug 21, 2020
1 parent 60b9d65 commit 072cfe6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/main/assembly/dist/cfg/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ auth.ldap.url=ldap://localhost
auth.ldap.user=cn=ldapadmin,dc=dans,dc=knaw,dc=nl
auth.ldap.password=changeme
audio-video.ffprobe=/usr/bin/ffprobe
dans.doi.prefix=10.17026/
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import nl.knaw.dans.easy.multideposit.model.Datamanager
import nl.knaw.dans.easy.multideposit.parser.MultiDepositParser
import nl.knaw.dans.lib.logging.DebugEnhancedLogging

class SplitMultiDepositApp(formats: Set[String], userLicenses: Set[String], ldap: Ldap, ffprobe: FfprobeRunner, permissions: DepositPermissions) extends AutoCloseable with DebugEnhancedLogging {
private val createMultiDeposit = new CreateMultiDeposit(formats, ldap, ffprobe, permissions)
class SplitMultiDepositApp(formats: Set[String], userLicenses: Set[String], ldap: Ldap, ffprobe: FfprobeRunner, permissions: DepositPermissions, dansDoiPrefix: String) extends AutoCloseable with DebugEnhancedLogging {
private val createMultiDeposit = new CreateMultiDeposit(formats, ldap, ffprobe, permissions, dansDoiPrefix)

override def close(): Unit = ldap.close()

Expand Down Expand Up @@ -90,7 +90,8 @@ object SplitMultiDepositApp {
require(exeFile.isExecutable, s"Ffprobe at $exeFile is not executable")
FfprobeRunner(exeFile)
}
val dansDoiPrefix = configuration.properties.getString("dans.doi.prefix")

new SplitMultiDepositApp(configuration.formats, configuration.licenses, ldap, ffprobe, permissions)
new SplitMultiDepositApp(configuration.formats, configuration.licenses, ldap, ffprobe, permissions, dansDoiPrefix)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import nl.knaw.dans.easy.multideposit.{ ActionError, FailFast, now }
import nl.knaw.dans.lib.logging.DebugEnhancedLogging
import org.apache.commons.configuration.PropertiesConfiguration

class AddPropertiesToDeposit extends DebugEnhancedLogging {
class AddPropertiesToDeposit(dansDoiPrefix: String) extends DebugEnhancedLogging {

def addDepositProperties(deposit: Deposit, datamanagerId: Datamanager, emailaddress: DatamanagerEmailaddress)(implicit stage: StagingPathExplorer): FailFast[Unit] = {
logger.debug(s"add deposit properties for ${ deposit.depositId }")
Expand All @@ -40,6 +40,7 @@ class AddPropertiesToDeposit extends DebugEnhancedLogging {
}

private def addProperties(deposit: Deposit, datamanagerId: Datamanager, emailaddress: DatamanagerEmailaddress, bagDirName: String)(properties: PropertiesConfiguration): Unit = {
val doiAction = if (deposit.baseUUID.isDefined && hasDansDoiPrefix(deposit)) "update" else "create"
val sf = deposit.springfield
val props: Map[String, Option[String]] = Map(
"bag-store.bag-id" -> Some(deposit.bagId.toString),
Expand All @@ -56,7 +57,7 @@ class AddPropertiesToDeposit extends DebugEnhancedLogging {
"springfield.collection" -> sf.map(_.collection),
"springfield.playmode" -> sf.map(_.playMode.toString),
"identifier.dans-doi.registered" -> Some("no"),
"identifier.dans-doi.action" -> Some("create"),
"identifier.dans-doi.action" -> Some(doiAction),
"bag-store.bag-name" -> Some(bagDirName),
"deposit.origin" -> Some("SMD"),
)
Expand All @@ -65,4 +66,13 @@ class AddPropertiesToDeposit extends DebugEnhancedLogging {
properties.setProperty(key, value)
}
}

private def hasDansDoiPrefix(deposit: Deposit): Boolean = {
var exists = false
for (identifier <- deposit.metadata.identifiers) {
if (identifier.id.startsWith(dansDoiPrefix))
exists = true
}
exists
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ import nl.knaw.dans.lib.logging.DebugEnhancedLogging
class CreateMultiDeposit(formats: Set[String],
ldap: Ldap,
ffprobe: FfprobeRunner,
permissions: DepositPermissions) extends DebugEnhancedLogging {
permissions: DepositPermissions,
dansDoiPrefix:String) extends DebugEnhancedLogging {

private val validator = new ValidatePreconditions(ldap, ffprobe)
private val datamanager = new RetrieveDatamanager(ldap)
private val createDirs = new CreateDirectories()
private val createBag = new AddBagToDeposit()
private val datasetMetadata = new AddDatasetMetadataToDeposit(formats)
private val fileMetadata = new AddFileMetadataToDeposit()
private val depositProperties = new AddPropertiesToDeposit()
private val depositProperties = new AddPropertiesToDeposit(dansDoiPrefix)
private val setPermissions = new SetDepositPermissions(permissions)
private val reportDatasets = new ReportDatasets()
private val moveDeposit = new MoveDepositToOutputDir()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class SplitMultiDepositAppSpec extends TestSupportFixture with MockFactory with
od = outputDepositDir.createIfNotExists(asDirectory = true, createParents = true),
report = reportFile
)
val app = new SplitMultiDepositApp(formats, userLicenses, ldap, ffprobe, DepositPermissions("rwxrwx---", getFileSystemGroup))
val dansDoiPrefix = "10.17026/"
val app = new SplitMultiDepositApp(formats, userLicenses, ldap, ffprobe, DepositPermissions("rwxrwx---", getFileSystemGroup), dansDoiPrefix)

val expectedOutputDir = File(getClass.getResource("/allfields/output").toURI)

Expand Down Expand Up @@ -340,7 +341,8 @@ class SplitMultiDepositAppSpec extends TestSupportFixture with MockFactory with
od = outputDepositDir.createIfNotExists(asDirectory = true, createParents = true),
report = reportFile
)
val app = new SplitMultiDepositApp(formats, userLicenses, mock[Ldap], mock[FfprobeRunner], DepositPermissions("rwxrwx---", getFileSystemGroup))
val dansDoiPrefix = "10.17026/"
val app = new SplitMultiDepositApp(formats, userLicenses, mock[Ldap], mock[FfprobeRunner], DepositPermissions("rwxrwx---", getFileSystemGroup), dansDoiPrefix)

inside(app.convert(paths, "easyadmin").leftValue.toNonEmptyList.toList) {
case List(ParseFailed(report)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ trait TestSupportFixture extends AnyFlatSpec with Matchers with OptionValues wit
subjects = List(Subject("subject 1", Option("abr:ABRcomplex")), Subject("subject 2"), Subject("subject 3")),
publishers = List("publisher 1"),
types = NonEmptyList.of(DcType.STILLIMAGE),
identifiers = List(Identifier("id1234")),
identifiers = List(Identifier("10.17026/abcdef12345")),
rightsholder = NonEmptyList.of("Neo"),
),
files = Map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class AddPropertiesToDepositSpec extends TestSupportFixture with BeforeAndAfterE
private val depositId = "ds1"
private val datamanagerId = "dm"
private val datamanagerEmail = "[email protected]"
private val action = new AddPropertiesToDeposit
private val dansDoiPrefix = "10.17026/"
private val action = new AddPropertiesToDeposit(dansDoiPrefix)

override def beforeEach(): Unit = {
val path = stagingDir / s"sd-$depositId"
Expand Down Expand Up @@ -83,6 +84,52 @@ class AddPropertiesToDepositSpec extends TestSupportFixture with BeforeAndAfterE
resultProps.getString("deposit.origin") shouldBe "SMD"
}

it should "generate the properties file and write the properties in it with dans-doi.action 'update'" in {
val uuid = UUID.randomUUID()
action.addDepositProperties(testInstructions2.copy(audioVideo = AudioVideo()).toDeposit().copy(bagId = uuid), datamanagerId, datamanagerEmail) shouldBe right[Unit]

val props = stagingPropertiesFile(testInstructions2.depositId)
props.toJava should exist

val resultProps = new PropertiesConfiguration {
setDelimiterParsingDisabled(true)
load(props.toJava)
}

resultProps.getKeys.asScala.toList should {
contain only(
"bag-store.bag-id",
"creation.timestamp",
"state.label",
"state.description",
"depositor.userId",
"curation.datamanager.email",
"curation.datamanager.userId",
"curation.required",
"curation.performed",
"identifier.dans-doi.registered",
"identifier.dans-doi.action",
"bag-store.bag-name",
"deposit.origin",
) and contain noneOf(
"springfield.domain",
"springfield.user",
"springfield.collection",
"springfield.playmode",
)
}

resultProps.getString("bag-store.bag-id") shouldBe uuid.toString
resultProps.getString("depositor.userId") shouldBe "ruimtereiziger2"
resultProps.getString("curation.datamanager.email") shouldBe datamanagerEmail
resultProps.getString("curation.datamanager.userId") shouldBe datamanagerId
resultProps.getString("curation.required") shouldBe "yes"
resultProps.getString("curation.performed") shouldBe "yes"
resultProps.getString("identifier.dans-doi.registered") shouldBe "no"
resultProps.getString("identifier.dans-doi.action") shouldBe "update"
resultProps.getString("deposit.origin") shouldBe "SMD"
}

it should "generate the properties file with springfield fields and write the properties in it" in {
val uuid = UUID.randomUUID()

Expand Down

0 comments on commit 072cfe6

Please sign in to comment.