Skip to content

Commit

Permalink
Merge pull request DANS-KNAW#153 from janvanmansum/EASY-2507
Browse files Browse the repository at this point in the history
EASY-2507 StreamWriteException in ingest flow bij deposit zonder data files
  • Loading branch information
janvanmansum authored Jan 8, 2020
2 parents ef37c88 + 129e08b commit d5b89a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,25 @@ object EasyStageDataset extends DebugEnhancedLogging {
foxmlContent = getDatasetFOXML(s.ownerId, emdContent)
additionalLicenseFilenameAndMimeType <- AdditionalLicense.createOptionally(sdoDir)
audiences <- readAudiences()
manifestSha1Exists = new File(s.bagitDir, "manifest-sha1.txt").exists()
sha1ManifestFile = new File(s.bagitDir, "manifest-sha1.txt")
manifestSha1ExistsAndNonEmpty = sha1ManifestFile.exists() && sha1ManifestFile.length() > 0
agreementsXmlExists = new File(s.bagitDir, "metadata/depositor-info/agreements.xml").exists()
messageFromDepositorExists = new File(s.bagitDir, "metadata/depositor-info/message-from-depositor.txt").exists()
jsonCfgContent <- JSON.createDatasetCfg(additionalLicenseFilenameAndMimeType, audiences, manifestSha1Exists, agreementsXmlExists, messageFromDepositorExists)
jsonCfgContent <- JSON.createDatasetCfg(additionalLicenseFilenameAndMimeType, audiences, manifestSha1ExistsAndNonEmpty, agreementsXmlExists, messageFromDepositorExists)
_ <- writeAMD(sdoDir, amdContent.toString())
_ <- writeFoxml(sdoDir, foxmlContent)
_ <- writePrsql(sdoDir, PRSQL.create())
_ <- if (s.includeBagMetadata) writeBagMetadata(sdoDir, manifestSha1Exists, agreementsXmlExists, messageFromDepositorExists)
_ <- if (s.includeBagMetadata) writeBagMetadata(sdoDir, manifestSha1ExistsAndNonEmpty, agreementsXmlExists, messageFromDepositorExists)
else Success(())
_ <- writeJsonCfg(sdoDir, jsonCfgContent)
} yield (emdContent, amdContent) // easy-ingest-flow hands these over to easy-ingest
}

private def writeBagMetadata(sdoDir: File, manifestSha1Exists: Boolean, agreementsXmlExists: Boolean, messageFromDepositorExists: Boolean)(implicit s: Settings): Try[Unit] = {
private def writeBagMetadata(sdoDir: File, manifestSha1ExistsAndNonEmpty: Boolean, agreementsXmlExists: Boolean, messageFromDepositorExists: Boolean)(implicit s: Settings): Try[Unit] = {
for {
_ <- readFile("metadata/dataset.xml").flatMap(writeDatasetXML(sdoDir, _))
_ <- readFile("metadata/files.xml").flatMap(writeFilesXML(sdoDir, _))
_ <- if (manifestSha1Exists) readFile("manifest-sha1.txt").flatMap(writeSha1Manifest(sdoDir, _))
_ <- if (manifestSha1ExistsAndNonEmpty) readFile("manifest-sha1.txt").flatMap(writeSha1Manifest(sdoDir, _))
else Success(())
_ <- if (agreementsXmlExists) readFile("metadata/depositor-info/agreements.xml").flatMap(writeAgreementsXML(sdoDir, _))
else Success(())
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/scala/nl.knaw.dans.easy.stage/lib/JSON.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object JSON extends DebugEnhancedLogging {

def createDatasetCfg(additionalLicenseFilenameAndMimetype: Option[(String, String)],
audiences: Seq[String],
manifestSha1Exists: Boolean,
manifestSha1ExistsAndNonEmpty: Boolean,
agreementsXmlExists: Boolean,
messageFromDepositorExists: Boolean,
)(implicit s: Settings): Try[String] = Try {
Expand Down Expand Up @@ -66,7 +66,7 @@ object JSON extends DebugEnhancedLogging {
("mimeType" -> "text/xml"),
)

val maybeManifestSha1Entry = manifestSha1Exists
val maybeManifestSha1Entry = manifestSha1ExistsAndNonEmpty
.map(_ => {
("contentFile" -> "manifest-sha1.txt") ~
("dsId" -> "manifest-sha1.txt") ~
Expand Down

0 comments on commit d5b89a0

Please sign in to comment.