Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions app/Iterators/BagItIterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,72 +19,72 @@ class BagItIterator(pathToFolder : String, collection : Option[models.Collection
var bytes : Long = 0L

private def addBagItTextToZip(pathToFolder : String, totalbytes: Long, totalFiles: Long, zip: ZipOutputStream, collection: models.Collection, user: Option[models.User]) = {
zip.putNextEntry(new ZipEntry(pathToFolder+"/bagit.txt"))
val softwareLine = "Bag-Software-Agent: clowder.ncsa.illinois.edu\n"
val baggingDate = "Bagging-Date: "+(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(Calendar.getInstance.getTime)+"\n"
zip.putNextEntry(new ZipEntry(pathToFolder + "/bagit.txt"))
val softwareLine = "Bag-Software-Agent: clowder\n"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any specific information about what should go in this field. Did you find something regarding this? I saw something along the lines emails: clowder <https://clowderframework.org/>.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the agent definition is typically the name of the software, along with versioning. For example, this is how a similar field is used in the HTTP standard:

https://en.wikipedia.org/wiki/User_agent

My reasoning here would be that at a minimum it should be clowder rather than a specific domain as a clowder instance can (and will) be installed in other locations than at NCSA

val baggingDate = "Bagging-Date: " + (new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(Calendar.getInstance.getTime) + "\n"
val baggingSize = "Bag-Size: " + totalbytes + "\n"
val payLoadOxum = "Payload-Oxum: "+ totalbytes + "." + totalFiles +"\n"
val senderIdentifier="Internal-Sender-Identifier: "+collection.id+"\n"
val senderDescription = "Internal-Sender-Description: "+collection.description+"\n"
val payLoadOxum = "Payload-Oxum: " + totalbytes + "." + totalFiles + "\n"
val senderIdentifier = "Internal-Sender-Identifier: " + collection.id + "\n"
val senderDescription = "Internal-Sender-Description: " + collection.description + "\n"
var s:String = ""
if (user.isDefined) {
val contactName = "Contact-Name: " + user.get.fullName + "\n"
val contactEmail = "Contact-Email: " + user.get.email.getOrElse("") + "\n"
s = softwareLine+baggingDate+baggingSize+payLoadOxum+contactName+contactEmail+senderIdentifier+senderDescription
s = softwareLine + baggingDate + baggingSize + payLoadOxum + contactName + contactEmail + senderIdentifier + senderDescription
} else {
s = softwareLine+baggingDate+baggingSize+payLoadOxum+senderIdentifier+senderDescription
s = softwareLine + baggingDate + baggingSize + payLoadOxum + senderIdentifier + senderDescription
}

Some(new ByteArrayInputStream(s.getBytes("UTF-8")))
}

// If no collection provided, assume this is for Selected download
private def addBagItTextToZip(pathToFolder : String, totalbytes: Long, totalFiles: Long, zip: ZipOutputStream, user: Option[models.User]) = {
zip.putNextEntry(new ZipEntry(pathToFolder+"/bagit.txt"))
val softwareLine = "Bag-Software-Agent: clowder.ncsa.illinois.edu\n"
val baggingDate = "Bagging-Date: "+(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(Calendar.getInstance.getTime)+"\n"
zip.putNextEntry(new ZipEntry(pathToFolder + "/bagit.txt"))
val softwareLine = "Bag-Software-Agent: clowder\n"
val baggingDate = "Bagging-Date: " + (new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(Calendar.getInstance.getTime) + "\n"
val baggingSize = "Bag-Size: " + totalbytes + "\n"
val payLoadOxum = "Payload-Oxum: "+ totalbytes + "." + totalFiles +"\n"
val payLoadOxum = "Payload-Oxum: " + totalbytes + "." + totalFiles + "\n"

val s:String = if (user.isDefined) {
val senderIdentifier="Internal-Sender-Identifier: user "+user.get.id+"\n"
val senderIdentifier = "Internal-Sender-Identifier: user " + user.get.id + "\n"
val senderDescription = "Internal-Sender-Description: User Dataset Selections\n"
val contactName = "Contact-Name: " + user.get.fullName + "\n"
val contactEmail = "Contact-Email: " + user.get.email.getOrElse("") + "\n"
softwareLine+baggingDate+baggingSize+payLoadOxum+contactName+contactEmail+senderIdentifier+senderDescription
softwareLine + baggingDate + baggingSize + payLoadOxum + contactName + contactEmail + senderIdentifier + senderDescription
} else {
val senderIdentifier="Internal-Sender-Identifier: unknown user\n"
val senderIdentifier = "Internal-Sender-Identifier: unknown user\n"
val senderDescription = "Internal-Sender-Description: User Dataset Selections\n"
softwareLine+baggingDate+baggingSize+payLoadOxum+senderIdentifier+senderDescription
softwareLine + baggingDate + baggingSize + payLoadOxum + senderIdentifier + senderDescription
}

Some(new ByteArrayInputStream(s.getBytes("UTF-8")))
}

private def addBagInfoToZip(pathToFolder : String ,zip : ZipOutputStream) : Option[InputStream] = {
zip.putNextEntry(new ZipEntry(pathToFolder+"/bag-info.txt"))
val s : String = "BagIt-Version: 0.97\n"+"Tag-File-Character-Encoding: UTF-8\n"
zip.putNextEntry(new ZipEntry(pathToFolder + "/bag-info.txt"))
val s : String = "BagIt-Version: 0.97\n" + "Tag-File-Character-Encoding: UTF-8\n"
Some(new ByteArrayInputStream(s.getBytes("UTF-8")))
}

private def addManifestMD5ToZip(pathToFolder : String, md5map : Map[String,MessageDigest] ,zip : ZipOutputStream) : Option[InputStream] = {
zip.putNextEntry(new ZipEntry(pathToFolder+"/manifest-md5.txt"))
zip.putNextEntry(new ZipEntry(pathToFolder + "/manifest-md5.txt"))
var s : String = ""
md5map.foreach{
case (filePath,md) => {
val current = Hex.encodeHexString(md.digest())+" "+filePath+"\n"
val current = Hex.encodeHexString(md.digest()) + " " + filePath + "\n"
s = s + current
}
}
Some(new ByteArrayInputStream(s.getBytes("UTF-8")))
}

private def addTagManifestMD5ToZip(pathToFolder : String, md5map : Map[String,MessageDigest],zip : ZipOutputStream) : Option[InputStream] = {
zip.putNextEntry(new ZipEntry(pathToFolder+"/tagmanifest-md5.txt"))
zip.putNextEntry(new ZipEntry(pathToFolder + "/tagmanifest-md5.txt"))
var s : String = ""
md5map.foreach{
case (filePath,md) => {
val current = Hex.encodeHexString(md.digest())+" "+filePath+"\n"
val current = Hex.encodeHexString(md.digest()) + " " + filePath + "\n"
s = s + current
}
}
Expand All @@ -109,38 +109,38 @@ class BagItIterator(pathToFolder : String, collection : Option[models.Collection
case 1 => {
is = collection match {
case Some(coll) => {
addBagItTextToZip(pathToFolder,bytes,0,zip,coll,user)
addBagItTextToZip(pathToFolder, bytes, 0, zip, coll, user)
}
case None => {
addBagItTextToZip(pathToFolder,bytes,0,zip,user)
addBagItTextToZip(pathToFolder, bytes, 0, zip, user)
}
}

val md5 = MessageDigest.getInstance("MD5")
md5Bag.put("bagit.txt",md5)
md5Bag.put("bagit.txt", md5)
file_type = 2
Some(new DigestInputStream(is.get, md5))

}
case 0 => {
is = addBagInfoToZip(pathToFolder,zip)
val md5 = MessageDigest.getInstance("MD5")
md5Bag.put("bag-info.txt",md5)
md5Bag.put("bag-info.txt", md5)
file_type = 1
Some(new DigestInputStream(is.get, md5))

}
case 2 => {
is = addManifestMD5ToZip(pathToFolder,md5Files.toMap[String,MessageDigest],zip)
val md5 = MessageDigest.getInstance("MD5")
md5Bag.put("manifest-md5.txt",md5)
md5Bag.put("manifest-md5.txt", md5)
file_type = 3
Some(new DigestInputStream(is.get, md5))
}
case 3 => {
is = addTagManifestMD5ToZip(pathToFolder,md5Bag.toMap[String,MessageDigest],zip)
val md5 = MessageDigest.getInstance("MD5")
md5Bag.put("tagmanifest-md5.txt",md5)
md5Bag.put("tagmanifest-md5.txt", md5)
file_type = 4
Some(new DigestInputStream(is.get, md5))
}
Expand All @@ -149,4 +149,4 @@ class BagItIterator(pathToFolder : String, collection : Option[models.Collection
}
}
}
}
}
40 changes: 20 additions & 20 deletions app/Iterators/CollectionIterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ class CollectionIterator(pathToFolder : String, parent_collection : models.Colle
}

private def addCollectionInfoToZip(folderName: String, collection: models.Collection, zip: ZipOutputStream): Option[InputStream] = {
val path = folderName + "/"+collection.name+"_info.json"
zip.putNextEntry(new ZipEntry(folderName + "/"+collection.name+"_info.json"))
val path = folderName + "/" + collection.name + "_info.json"
zip.putNextEntry(new ZipEntry(folderName + "/" + collection.name + "_info.json"))
val infoListMap = Json.prettyPrint(jsonCollection(collection))
Some(new ByteArrayInputStream(infoListMap.getBytes("UTF-8")))
}

private def addCollectionMetadataToZip(folderName : String , collection : models.Collection, zip : ZipOutputStream) : Option[InputStream] = {
val path = folderName+"/"+collection.name+"_metadata.json"
zip.putNextEntry(new ZipEntry(folderName+"/"+collection.name+"_metadata.json"))
val path = folderName + "/" + collection.name + "_metadata.json"
zip.putNextEntry(new ZipEntry(folderName + "/" + collection.name + "_metadata.json"))
val collectionMetadata = getCollectionInfoAsJson(collection)
val metadataMap = Json.prettyPrint(collectionMetadata)
Some(new ByteArrayInputStream(metadataMap.getBytes("UTF-8")))
Expand All @@ -74,14 +74,14 @@ class CollectionIterator(pathToFolder : String, parent_collection : models.Colle
if (file_type < 2){
true
}
else if (file_type ==2){
else if (file_type == 2){
if (datasetIterator.hasNext()){
true
} else if (numChildCollections > 0){

currentCollectionIterator = Some(new CollectionIterator(pathToFolder+"/"+child_collections(childCollectionCount).name, child_collections(childCollectionCount),zip,md5Files,user,collections,datasets,files,
folders,metadataService,spaces))
file_type +=1
currentCollectionIterator = Some(new CollectionIterator(pathToFolder + "/" + child_collections(childCollectionCount).name, child_collections(childCollectionCount), zip, md5Files, user, collections, datasets, files,
folders, metadataService, spaces))
file_type += 1
true
} else {
false
Expand All @@ -91,14 +91,14 @@ class CollectionIterator(pathToFolder : String, parent_collection : models.Colle
case Some(collectionIterator) => {
if (collectionIterator.hasNext()){
true
} else if (childCollectionCount < numChildCollections -2){
childCollectionCount+=1
currentCollectionIterator = Some(new CollectionIterator(pathToFolder+"/"+child_collections(childCollectionCount).name, child_collections(childCollectionCount),zip,md5Files,user,
collections,datasets,files,
folders,metadataService,spaces))
} else if (childCollectionCount < numChildCollections - 2){
childCollectionCount += 1
currentCollectionIterator = Some(new CollectionIterator(pathToFolder + "/" + child_collections(childCollectionCount).name, child_collections(childCollectionCount), zip, md5Files, user,
collections, datasets, files,
folders, metadataService, spaces))
true
} else {
file_type+=1
file_type += 1
false
}
}
Expand All @@ -114,17 +114,17 @@ class CollectionIterator(pathToFolder : String, parent_collection : models.Colle
//collection info
case 0 => {
val md5 = MessageDigest.getInstance("MD5")
md5Files.put(pathToFolder+"_info.json",md5)
val is = addCollectionInfoToZip(pathToFolder, parent_collection,zip)
file_type+=1
md5Files.put(pathToFolder + "_info.json", md5)
val is = addCollectionInfoToZip(pathToFolder, parent_collection, zip)
file_type += 1
Some(new DigestInputStream(is.get, md5))
}
//collection metadata
case 1 => {
val md5 = MessageDigest.getInstance("MD5")
md5Files.put(pathToFolder+"_metadata.json",md5)
val is = addCollectionMetadataToZip(pathToFolder, parent_collection,zip)
file_type+=1
md5Files.put(pathToFolder + "_metadata.json", md5)
val is = addCollectionMetadataToZip(pathToFolder, parent_collection, zip)
file_type += 1
Some(new DigestInputStream(is.get, md5))
}
//datasets in this collection
Expand Down
20 changes: 10 additions & 10 deletions app/Iterators/DatasetIterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class DatasetIterator(pathToFolder : String, dataset : models.Dataset, zip: ZipO
}

def addDatasetInfoToZip(folderName: String, dataset: models.Dataset, zip: ZipOutputStream): Option[InputStream] = {
val path = folderName + "/"+dataset.name+"_info.json"
zip.putNextEntry(new ZipEntry(folderName + "/"+dataset.name+"_info.json"))
val path = folderName + "/" + dataset.name + "_info.json"
zip.putNextEntry(new ZipEntry(folderName + "/" + dataset.name + "_info.json"))
val infoListMap = Json.prettyPrint(getDatasetInfoAsJson(dataset))
Some(new ByteArrayInputStream(infoListMap.getBytes("UTF-8")))
}

def addDatasetMetadataToZip(folderName: String, dataset : models.Dataset, zip: ZipOutputStream): Option[InputStream] = {
val path = folderName + "/"+dataset.name+"_dataset_metadata.json"
zip.putNextEntry(new ZipEntry(folderName + "/"+dataset.name+"_metadata.json"))
val path = folderName + "/" + dataset.name + "_dataset_metadata.json"
zip.putNextEntry(new ZipEntry(folderName + "/" + dataset.name + "_metadata.json"))
val datasetMetadata = metadataService.getMetadataByAttachTo(ResourceRef(ResourceRef.dataset, dataset.id))
.map(JSONLD.jsonMetadataWithContext(_))
val s : String = Json.prettyPrint(Json.toJson(datasetMetadata))
Expand Down Expand Up @@ -85,7 +85,7 @@ class DatasetIterator(pathToFolder : String, dataset : models.Dataset, zip: ZipO
while(f1.parentType == "folder") {
folders.get(f1.parentId) match {
case Some(fparent) => {
name = fparent.displayName + "/"+ name
name = fparent.displayName + "/" + name
f1 = fparent
}
case None =>
Expand Down Expand Up @@ -125,7 +125,7 @@ class DatasetIterator(pathToFolder : String, dataset : models.Dataset, zip: ZipO
if (fileIterator.hasNext()){
true
} else if (fileCounter < numFiles -1){
fileCounter +=1
fileCounter += 1
currentFileIterator = Some(new FileIterator(folderNameMap(inputFiles(fileCounter).id),inputFiles(fileCounter),zip,md5Files,files,folders,metadataService))
true
} else {
Expand All @@ -146,18 +146,18 @@ class DatasetIterator(pathToFolder : String, dataset : models.Dataset, zip: ZipO
is = addDatasetInfoToZip(pathToFolder,dataset,zip)
val md5 = MessageDigest.getInstance("MD5")
md5Files.put("_info.json",md5)
file_type+=1
file_type += 1
Some(new DigestInputStream(is.get, md5))
}
case 1 => {
is = addDatasetMetadataToZip(pathToFolder,dataset,zip)
val md5 = MessageDigest.getInstance("MD5")
md5Files.put("_metadata.json",md5)
if (numFiles > 0){
file_type+=1
file_type += 1
currentFileIterator = Some(new FileIterator(folderNameMap(inputFiles(fileCounter).id),inputFiles(fileCounter),zip,md5Files,files,folders,metadataService))
} else {
file_type+=2
file_type += 2
}

Some(new DigestInputStream(is.get, md5))
Expand All @@ -172,4 +172,4 @@ class DatasetIterator(pathToFolder : String, dataset : models.Dataset, zip: ZipO
}
}
}
}
}
12 changes: 6 additions & 6 deletions app/Iterators/DatasetsInCollectionIterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class DatasetsInCollectionIterator(pathToFolder : String, collection : models.Co

var currentDatasetIterator : Option[DatasetIterator] = if (numDatasets > 0){

Some(new DatasetIterator(pathToFolder+"/"+currentDataset.get.name,currentDataset.get, zip, md5Files,
folders, files,metadataService,datasets,spaces))
Some(new DatasetIterator(pathToFolder + "/" + currentDataset.get.name, currentDataset.get, zip, md5Files,
folders, files, metadataService, datasets, spaces))
} else {
None
}
Expand All @@ -51,13 +51,13 @@ class DatasetsInCollectionIterator(pathToFolder : String, collection : models.Co
if (datasetIterator.hasNext()){
true
} else {
if (datasetCount < numDatasets -1){
datasetCount +=1
if (datasetCount < numDatasets - 1){
datasetCount += 1
currentDataset = Some(datasetsInCollection(datasetCount))
currentDataset match {
case Some(cd) => {
currentDatasetIterator = Some(new DatasetIterator(pathToFolder+"/"+cd.name,cd, zip, md5Files,
folders, files,metadataService,datasets,spaces))
currentDatasetIterator = Some(new DatasetIterator(pathToFolder + "/" + cd.name, cd, zip, md5Files,
folders, files, metadataService, datasets, spaces))
true
}
case None => false
Expand Down
22 changes: 11 additions & 11 deletions app/Iterators/FileIterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import services.{FolderService, MetadataService, FileService}
import util.JSONLD

//this is used for file downloads
//called by the dataset interator
//called by the dataset iterator
class FileIterator (pathToFile : String, file : models.File,zip : ZipOutputStream, md5Files :scala.collection.mutable.HashMap[String, MessageDigest], files : FileService, folders : FolderService , metadataService : MetadataService) extends Iterator[Option[InputStream]] {

def getFileInfoAsJson(file : models.File) : JsValue = {
Expand All @@ -31,7 +31,7 @@ class FileIterator (pathToFile : String, file : models.File,zip : ZipOutputStrea
Json.obj("id" -> file.id, "filename" -> file.filename, "author" -> file.author.email, "uploadDate" -> file.uploadDate.toString,"contentType"->file.contentType,"description"->file.description,"license"->licenseInfo)
}
def addFileInfoToZip(folderName: String, file: models.File, zip: ZipOutputStream): Option[InputStream] = {
zip.putNextEntry(new ZipEntry(folderName + "/"+file.filename+"_info.json"))
zip.putNextEntry(new ZipEntry(folderName + "/" + file.filename + "_info.json"))
val fileInfo = getFileInfoAsJson(file)
val s : String = Json.prettyPrint(fileInfo)
Some(new ByteArrayInputStream(s.getBytes("UTF-8")))
Expand All @@ -48,7 +48,7 @@ class FileIterator (pathToFile : String, file : models.File,zip : ZipOutputStrea
}

def addFileMetadataToZip(folderName: String, file: models.File, zip: ZipOutputStream): Option[InputStream] = {
zip.putNextEntry(new ZipEntry(folderName + "/"+file.filename+"_metadata.json"))
zip.putNextEntry(new ZipEntry(folderName + "/" + file.filename + "_metadata.json"))
val fileMetadata = metadataService.getMetadataByAttachTo(ResourceRef(ResourceRef.file, file.id)).map(JSONLD.jsonMetadataWithContext(_))
val s : String = Json.prettyPrint(Json.toJson(fileMetadata))
Some(new ByteArrayInputStream(s.getBytes("UTF-8")))
Expand All @@ -66,24 +66,24 @@ class FileIterator (pathToFile : String, file : models.File,zip : ZipOutputStrea
def next() = {
file_type match {
case 0 => {
file_type +=1
file_type += 1
is = addFileInfoToZip(pathToFile, file, zip)
val md5 = MessageDigest.getInstance("MD5")
md5Files.put(file.filename+"_info.json",md5)
md5Files.put(file.filename + "_info.json", md5)
Some(new DigestInputStream(is.get,md5))
}
case 1 => {
file_type+=1
is = addFileMetadataToZip(pathToFile,file,zip)
file_type += 1
is = addFileMetadataToZip(pathToFile, file, zip)
val md5 = MessageDigest.getInstance("MD5")
md5Files.put(file.filename+"_metadata.json",md5)
md5Files.put(file.filename + "_metadata.json", md5)
Some(new DigestInputStream(is.get,md5))
}
case 2 => {
file_type+=1
is = addFileToZip(pathToFile,file,zip)
file_type += 1
is = addFileToZip(pathToFile, file, zip)
val md5 = MessageDigest.getInstance("MD5")
md5Files.put(file.filename,md5)
md5Files.put(file.filename, md5)
Some(new DigestInputStream(is.get,md5))
}
case _ => None
Expand Down
Loading