diff --git a/app/Iterators/BagItIterator.scala b/app/Iterators/BagItIterator.scala index c87fafd25..17d386d9b 100644 --- a/app/Iterators/BagItIterator.scala +++ b/app/Iterators/BagItIterator.scala @@ -19,20 +19,20 @@ 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" + 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"))) @@ -40,39 +40,39 @@ class BagItIterator(pathToFolder : String, collection : Option[models.Collection // 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 } } @@ -80,11 +80,11 @@ class BagItIterator(pathToFolder : String, collection : Option[models.Collection } 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 } } @@ -109,15 +109,15 @@ 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)) @@ -125,7 +125,7 @@ class BagItIterator(pathToFolder : String, collection : Option[models.Collection 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)) @@ -133,14 +133,14 @@ class BagItIterator(pathToFolder : String, collection : Option[models.Collection 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)) } @@ -149,4 +149,4 @@ class BagItIterator(pathToFolder : String, collection : Option[models.Collection } } } -} \ No newline at end of file +} diff --git a/app/Iterators/CollectionIterator.scala b/app/Iterators/CollectionIterator.scala index cbe326122..21bd27996 100644 --- a/app/Iterators/CollectionIterator.scala +++ b/app/Iterators/CollectionIterator.scala @@ -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"))) @@ -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 @@ -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 } } @@ -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 diff --git a/app/Iterators/DatasetIterator.scala b/app/Iterators/DatasetIterator.scala index ac56bd496..5dac4603b 100644 --- a/app/Iterators/DatasetIterator.scala +++ b/app/Iterators/DatasetIterator.scala @@ -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)) @@ -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 => @@ -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 { @@ -146,7 +146,7 @@ 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 => { @@ -154,10 +154,10 @@ class DatasetIterator(pathToFolder : String, dataset : models.Dataset, zip: ZipO 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)) @@ -172,4 +172,4 @@ class DatasetIterator(pathToFolder : String, dataset : models.Dataset, zip: ZipO } } } -} \ No newline at end of file +} diff --git a/app/Iterators/DatasetsInCollectionIterator.scala b/app/Iterators/DatasetsInCollectionIterator.scala index 24f6b11ba..f2515084c 100644 --- a/app/Iterators/DatasetsInCollectionIterator.scala +++ b/app/Iterators/DatasetsInCollectionIterator.scala @@ -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 } @@ -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 diff --git a/app/Iterators/FileIterator.scala b/app/Iterators/FileIterator.scala index 315d1bdb9..1edac2d96 100644 --- a/app/Iterators/FileIterator.scala +++ b/app/Iterators/FileIterator.scala @@ -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 = { @@ -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"))) @@ -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"))) @@ -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 diff --git a/app/Iterators/RootCollectionIterator.scala b/app/Iterators/RootCollectionIterator.scala index b112dfd86..b571c69c0 100644 --- a/app/Iterators/RootCollectionIterator.scala +++ b/app/Iterators/RootCollectionIterator.scala @@ -17,7 +17,7 @@ import scala.collection.mutable.ListBuffer class RootCollectionIterator(pathToFolder : String, root_collection : models.Collection,zip : ZipOutputStream, md5Files : scala.collection.mutable.HashMap[String, MessageDigest], md5Bag : scala.collection.mutable.HashMap[String, MessageDigest], - user : Option[User],totalBytes : Long,bagit : Boolean, + user : Option[User], totalBytes : Long, bagit : Boolean, collections: CollectionService, datasets : DatasetService, files : FileService, folders : FolderService, metadataService : MetadataService, spaces : SpaceService) extends Iterator[Option[InputStream]] { @@ -38,8 +38,8 @@ class RootCollectionIterator(pathToFolder : String, root_collection : models.Col 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"))) } @@ -54,8 +54,8 @@ class RootCollectionIterator(pathToFolder : String, root_collection : models.Col 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"))) @@ -102,18 +102,18 @@ class RootCollectionIterator(pathToFolder : String, root_collection : models.Col if (file_type < 2){ true } - else if (file_type ==2){ + else if (file_type == 2){ if (datasetIterator.hasNext()){ true } else if (numCollections > 0){ - currentCollectionIterator = Some(new CollectionIterator(pathToFolder+"/"+child_collections(collectionCount).name, child_collections(collectionCount),zip,md5Files,user, - collections,datasets,files, - folders,metadataService,spaces)) - file_type +=1 + currentCollectionIterator = Some(new CollectionIterator(pathToFolder + "/" + child_collections(collectionCount).name, child_collections(collectionCount), zip, md5Files, user, + collections, datasets, files, + folders, metadataService, spaces)) + file_type += 1 true } else if (bagit){ - bagItIterator = Some(new BagItIterator(pathToFolder,Some(root_collection) ,zip,md5Bag,md5Files,bytesSoFar ,user)) + bagItIterator = Some(new BagItIterator(pathToFolder,Some(root_collection), zip, md5Bag, md5Files, bytesSoFar, user)) file_type = 4 true } else { @@ -124,16 +124,16 @@ class RootCollectionIterator(pathToFolder : String, root_collection : models.Col case Some(collectionIterator) => { if (collectionIterator.hasNext()){ true - } else if (collectionCount < numCollections -2){ - collectionCount+=1 - currentCollectionIterator = Some(new CollectionIterator(pathToFolder+"/"+child_collections(collectionCount).name, child_collections(collectionCount),zip,md5Files,user, - collections,datasets,files, - folders,metadataService,spaces)) + } else if (collectionCount < numCollections - 2){ + collectionCount += 1 + currentCollectionIterator = Some(new CollectionIterator(pathToFolder + "/" + child_collections(collectionCount).name, child_collections(collectionCount), zip, md5Files, user, + collections, datasets, files, + folders, metadataService, spaces)) true } else { if (bagit){ - bagItIterator = Some(new BagItIterator(pathToFolder,Some(root_collection) ,zip,md5Bag,md5Files,bytesSoFar ,user)) - file_type+=1 + bagItIterator = Some(new BagItIterator(pathToFolder,Some(root_collection), zip, md5Bag, md5Files, bytesSoFar, user)) + file_type += 1 true } else { false @@ -149,7 +149,7 @@ class RootCollectionIterator(pathToFolder : String, root_collection : models.Col if (bagIterator.hasNext()){ true } else { - file_type +=1 + file_type += 1 false } } @@ -165,15 +165,15 @@ class RootCollectionIterator(pathToFolder : String, root_collection : models.Col //collection info case 0 => { val md5 = MessageDigest.getInstance("MD5") - md5Files.put(pathToFolder+"_info.json",md5) + md5Files.put(pathToFolder + "_info.json", md5) val is = addCollectionInfoToZip(pathToFolder, root_collection,zip) - file_type+=1 + file_type += 1 Some(new DigestInputStream(is.get, md5)) } //collection metadata case 1 => { val md5 = MessageDigest.getInstance("MD5") - md5Files.put(pathToFolder+"_metadata.json",md5) + md5Files.put(pathToFolder + "_metadata.json", md5) val is = addCollectionMetadataToZip(pathToFolder, root_collection,zip) file_type+=1 Some(new DigestInputStream(is.get, md5)) diff --git a/app/Iterators/SelectedIterator.scala b/app/Iterators/SelectedIterator.scala index 4885473d2..cc554fdfa 100644 --- a/app/Iterators/SelectedIterator.scala +++ b/app/Iterators/SelectedIterator.scala @@ -21,8 +21,8 @@ class SelectedIterator(pathToFolder : String, selected : List[Dataset], zip : Zi var datasetCount = 0 var currDs = selected(datasetCount) - var datasetIterator = new DatasetIterator(pathToFolder+"/"+currDs.name, currDs, zip, md5Files, folders, files, - metadataService,datasets,spaces) + var datasetIterator = new DatasetIterator(pathToFolder + "/" + currDs.name, currDs, zip, md5Files, folders, files, + metadataService, datasets, spaces) var file_type = 0 @@ -48,17 +48,17 @@ class SelectedIterator(pathToFolder : String, selected : List[Dataset], zip : Zi } def hasNext() = { - if (file_type ==0){ + if (file_type == 0){ if (datasetIterator.hasNext()){ true - } else if (selected.length > datasetCount+1){ + } else if (selected.length > datasetCount + 1){ datasetCount += 1 currDs = selected(datasetCount) - datasetIterator = new DatasetIterator(pathToFolder+"/"+currDs.name,currDs,zip,md5Files,folders,files, - metadataService,datasets,spaces) + datasetIterator = new DatasetIterator(pathToFolder + "/" + currDs.name, currDs, zip, md5Files, folders, files, + metadataService, datasets, spaces) true } else if (bagit) { - bagItIterator = Some(new BagItIterator(pathToFolder,None ,zip,md5Bag,md5Files,bytesSoFar ,user)) + bagItIterator = Some(new BagItIterator(pathToFolder, None, zip, md5Bag, md5Files, bytesSoFar, user)) file_type = 1 true } else { @@ -70,7 +70,7 @@ class SelectedIterator(pathToFolder : String, selected : List[Dataset], zip : Zi if (bagIterator.hasNext()){ true } else { - file_type +=1 + file_type += 1 false } } @@ -101,6 +101,5 @@ class SelectedIterator(pathToFolder : String, selected : List[Dataset], zip : Zi None } } - } } diff --git a/app/api/ApiHelp.scala b/app/api/ApiHelp.scala index 6321247d8..1ac4c615a 100644 --- a/app/api/ApiHelp.scala +++ b/app/api/ApiHelp.scala @@ -11,7 +11,7 @@ import play.api.Logger */ object ApiHelp extends Controller { - def options(path:String) = Action { + def options(path:String) = Action { Logger.debug("ApiHelp: preflight request") Ok("") } @@ -20,15 +20,15 @@ object ApiHelp extends Controller { */ def getResources() = Action { Ok(toJson(""" - { - apiVersion: "0.1", - swaggerVersion: "1.1", - basePath: "http://localhost:9000/api", - apis: [ - { - path: "/datasets.json", - description: "Datasets are basic containers of data" - }, + { + apiVersion: "0.1", + swaggerVersion: "1.1", + basePath: "http://localhost:9000/api", + apis: [ + { + path: "/datasets.json", + description: "Datasets are basic containers of data" + }, { path: "/files.json", description: "Files include raw bytes and metadata" @@ -37,9 +37,8 @@ object ApiHelp extends Controller { path: "/collections.json", description: "Collections are groupings of datasets" } - ] - } + ] + } """)) } - } diff --git a/app/api/Collections.scala b/app/api/Collections.scala index 09d399014..22e0dfd67 100644 --- a/app/api/Collections.scala +++ b/app/api/Collections.scala @@ -773,7 +773,7 @@ class Collections @Inject() (datasets: DatasetService, // Use a 1MB in memory byte array Ok.chunked(enumeratorFromCollection(collection,1024*1024, compression,bagit,user)).withHeaders( "Content-Type" -> "application/zip", - "Content-Disposition" -> ("attachment; filename=\"" + collection.name+ ".zip\"") + "Content-Disposition" -> ("attachment; filename=\"" + collection.name + ".zip\"") ) } // If the dataset wasn't found by ID diff --git a/app/api/Comments.scala b/app/api/Comments.scala index adfc5db02..6a2964529 100644 --- a/app/api/Comments.scala +++ b/app/api/Comments.scala @@ -20,7 +20,7 @@ class Comments @Inject()(datasets: DatasetService, comments: CommentService, eve def comment(id: UUID) = PermissionAction(Permission.AddComment, Some(ResourceRef(ResourceRef.comment, id)))(parse.json) { implicit request => Logger.trace("Adding comment") - comments.get(id) match { + comments.get(id) match { case Some(parent) => { request.user match { case Some(identity) => { @@ -58,150 +58,150 @@ class Comments @Inject()(datasets: DatasetService, comments: CommentService, eve case None => BadRequest } } - + //Remove comment code starts /** * REST endpoint: DELETE: remove a comment associated with a specific file - * + * * The method takes a single arg: - * + * * id: A UUID that identifies the comment to be removed. - * + * * The request body needs no data, so it should be empty. - * + * * Only the owner of a comment will be allowed to delete it. Any other request will fail. - * + * */ def removeComment(id: UUID) = PermissionAction(Permission.DeleteComment, Some(ResourceRef(ResourceRef.comment, id)))(parse.json) { implicit request => - request.user match { - case Some(identity) => { - var commentId: UUID = id - if (UUID.isValid(commentId.stringify)) { - - Logger.debug(s"removeComment from file with id $commentId.") - //Check to make sure user email matches the comment email - comments.get(commentId) match { - case Some(theComment) => { - //Check to make sure the user is the same as the author, otherwise, they - //shouldn't be able to delete the comment. - if (identity.email == theComment.author.email) { - comments.removeComment(commentId) - Ok(Json.obj("status" -> "success")) - } - else { - Logger.error(s"Only the ${Messages("owner").toLowerCase()} can delete the comment.") - BadRequest(toJson(s"Only ${Messages("owner").toLowerCase()} can delete the comment.")) - } - } - case None => { - //Really shouldn't happen - BadRequest(toJson("Error getting the comment.")) - } - } - } - else { - Logger.error(s"The given id $commentId is not a valid ObjectId.") - BadRequest(toJson(s"The given id $commentId is not a valid ObjectId.")) - } - } - case None => { - //This case shouldn't happen, as there are checks to prevent this API from being - //called without an Identity - BadRequest - } - } + request.user match { + case Some(identity) => { + var commentId: UUID = id + if (UUID.isValid(commentId.stringify)) { + + Logger.debug(s"removeComment from file with id $commentId.") + //Check to make sure user email matches the comment email + comments.get(commentId) match { + case Some(theComment) => { + //Check to make sure the user is the same as the author, otherwise, they + //shouldn't be able to delete the comment. + if (identity.email == theComment.author.email) { + comments.removeComment(commentId) + Ok(Json.obj("status" -> "success")) + } + else { + Logger.error(s"Only the ${Messages("owner").toLowerCase()} can delete the comment.") + BadRequest(toJson(s"Only ${Messages("owner").toLowerCase()} can delete the comment.")) + } + } + case None => { + //Really shouldn't happen + BadRequest(toJson("Error getting the comment.")) + } + } + } + else { + Logger.error(s"The given id $commentId is not a valid ObjectId.") + BadRequest(toJson(s"The given id $commentId is not a valid ObjectId.")) + } + } + case None => { + //This case shouldn't happen, as there are checks to prevent this API from being + //called without an Identity + BadRequest + } + } } //End, remove comment code - + //Edit comment code starts /** * REST endpoint: POST: edit a comment associated with a specific file - * + * * The method takes a single arg: - * + * * id: A UUID that identifies the comment to be edited. - * + * * The data contained in the request body will contain data for the edit, stored in the following key-value pairs: - * + * * "commentText" -> The updated text to be used for the comment. - * + * * Only the owner of the comment will be allowed to edit it. Other requests will fail. - * + * */ def editComment(id: UUID) = PermissionAction(Permission.EditComment, Some(ResourceRef(ResourceRef.comment, id)))(parse.json) { implicit request => - request.user match { - case Some(identity) => { - var commentId: UUID = id - if (UUID.isValid(commentId.stringify)) { - Logger.debug(s"editComment from file with id $commentId.") - - comments.get(commentId) match { - case Some(theComment) => { - //Make sure that the author of the comment is the one editing it - if (identity.email == theComment.author.email) { - //Set up the vars we are looking for - var commentText: String = null; + request.user match { + case Some(identity) => { + var commentId: UUID = id + if (UUID.isValid(commentId.stringify)) { + Logger.debug(s"editComment from file with id $commentId.") + + comments.get(commentId) match { + case Some(theComment) => { + //Make sure that the author of the comment is the one editing it + if (identity.email == theComment.author.email) { + //Set up the vars we are looking for + var commentText: String = null; - var aResult: JsResult[String] = (request.body \ "commentText").validate[String] + var aResult: JsResult[String] = (request.body \ "commentText").validate[String] - // Pattern matching - aResult match { - case s: JsSuccess[String] => { - commentText = s.get - } - case e: JsError => { - Logger.error("Errors: " + JsError.toFlatJson(e).toString()) - BadRequest(toJson(s"description data is missing.")) - } - } + // Pattern matching + aResult match { + case s: JsSuccess[String] => { + commentText = s.get + } + case e: JsError => { + Logger.error("Errors: " + JsError.toFlatJson(e).toString()) + BadRequest(toJson(s"description data is missing.")) + } + } - Logger.debug(s"editComment from file with id $commentId.") + Logger.debug(s"editComment from file with id $commentId.") - comments.editComment(commentId, commentText) - events.addObjectEvent(request.user, commentId, commentText, EventType.EDIT_COMMENT.toString) - Ok(Json.obj("status" -> "success")) - } - else { - Logger.error(s"Only the ${Messages("owner").toLowerCase()} can edit the comment.") - BadRequest(toJson(s"Only ${Messages("owner").toLowerCase()} can edit the comment.")) - } - } - case None => { - //Shouldn't happen - BadRequest(toJson("Error getting the comment")) - } - } - } - else { - Logger.error(s"The given id $commentId is not a valid ObjectId.") - BadRequest(toJson(s"The given id $commentId is not a valid ObjectId.")) - } - } - case None => { - //This case shouldn't happen, as there are checks to prevent this API from being - //called without an Identity - BadRequest - } - } + comments.editComment(commentId, commentText) + events.addObjectEvent(request.user, commentId, commentText, EventType.EDIT_COMMENT.toString) + Ok(Json.obj("status" -> "success")) + } + else { + Logger.error(s"Only the ${Messages("owner").toLowerCase()} can edit the comment.") + BadRequest(toJson(s"Only ${Messages("owner").toLowerCase()} can edit the comment.")) + } + } + case None => { + //Shouldn't happen + BadRequest(toJson("Error getting the comment")) + } + } + } + else { + Logger.error(s"The given id $commentId is not a valid ObjectId.") + BadRequest(toJson(s"The given id $commentId is not a valid ObjectId.")) + } + } + case None => { + //This case shouldn't happen, as there are checks to prevent this API from being + //called without an Identity + BadRequest + } + } } //End, remove comment code - /** - * This will create an event in the specified user's feed indicating they were mentioned in a comment - * on the specified resource. + /** + * This will create an event in the specified user's feed indicating they were mentioned in a comment + * on the specified resource. */ - def mentionInComment(userid: UUID, resourceID: UUID, resourceName: String, resourceType: String, commenterId: UUID) = - PermissionAction(Permission.AddComment, Some(ResourceRef(Symbol(resourceType), resourceID))) { - users.get(commenterId) match { - case Some(u) => { - events.addRequestEvent(users.get(userid), u, resourceID, resourceName, "mention_"+resourceType+"_comment") - Ok(s"Mention event added to user id $userid's feed") - } - case None => { - events.addObjectEvent(users.get(userid), resourceID, resourceName, "mention_"+resourceType+"_comment") - Ok(s"Mention event added to user id $userid's feed") - } - } + def mentionInComment(userid: UUID, resourceID: UUID, resourceName: String, resourceType: String, commenterId: UUID) = + PermissionAction(Permission.AddComment, Some(ResourceRef(Symbol(resourceType), resourceID))) { + users.get(commenterId) match { + case Some(u) => { + events.addRequestEvent(users.get(userid), u, resourceID, resourceName, "mention_" + resourceType + "_comment") + Ok(s"Mention event added to user id $userid's feed") + } + case None => { + events.addObjectEvent(users.get(userid), resourceID, resourceName, "mention_" + resourceType + "_comment") + Ok(s"Mention event added to user id $userid's feed") + } + } - } + } } diff --git a/app/api/CurationObjects.scala b/app/api/CurationObjects.scala index 1b1032fba..323d4068e 100644 --- a/app/api/CurationObjects.scala +++ b/app/api/CurationObjects.scala @@ -48,10 +48,10 @@ class CurationObjects @Inject()(datasets: DatasetService, case Some(f) => f.length case None => 0 } - + var tempMap = Map( - "Identifier" -> Json.toJson("urn:uuid:"+file.id), - "@id" -> Json.toJson("urn:uuid:"+file.id), + "Identifier" -> Json.toJson("urn:uuid:" + file.id), + "@id" -> Json.toJson("urn:uuid:" + file.id), "Creation Date" -> Json.toJson(format.format(file.uploadDate)), "Label" -> Json.toJson(file.filename), "Title" -> Json.toJson(file.filename), @@ -75,16 +75,16 @@ class CurationObjects @Inject()(datasets: DatasetService, } val foldersJson = curations.getCurationFolders(curations.getAllCurationFolderIds(c.id)).map { folder => - val hasPart = folder.files.map(file=>"urn:uuid:"+file) ++ folder.folders.map(fd => "urn:uuid:"+fd) + val hasPart = folder.files.map(file=>"urn:uuid:" + file) ++ folder.folders.map(fd => "urn:uuid:" + fd) val tempMap = Map( "Creation Date" -> Json.toJson(format.format(folder.created)), "Rights" -> Json.toJson(c.datasets(0).licenseData.m_licenseText), - "Identifier" -> Json.toJson("urn:uuid:"+folder.id), + "Identifier" -> Json.toJson("urn:uuid:" + folder.id), "License" -> Json.toJson(c.datasets(0).licenseData.m_licenseText), "Label" -> Json.toJson(folder.name), "Title" -> Json.toJson(folder.displayName), "Uploaded By" -> Json.toJson(folder.author.fullName + ": " + api.routes.Users.findById(folder.author.id).absoluteURL(https)), - "@id" -> Json.toJson("urn:uuid:"+folder.id), + "@id" -> Json.toJson("urn:uuid:" + folder.id), "@type" -> Json.toJson(Seq("AggregatedResource", "http://cet.ncsa.uiuc.edu/2016/Folder")), "Is Version Of" -> Json.toJson(controllers.routes.Datasets.dataset(c.datasets(0).id).absoluteURL(https) +"#folderId=" +folder.folderId), "Has Part" -> Json.toJson(hasPart) @@ -92,7 +92,7 @@ class CurationObjects @Inject()(datasets: DatasetService, tempMap } - val hasPart = c.files.map(file => "urn:uuid:"+file) ++ c.folders.map(folder => "urn:uuid:"+folder) + val hasPart = c.files.map(file => "urn:uuid:" + file) ++ c.folders.map(folder => "urn:uuid:" + folder) var commentsByDataset = comments.findCommentsByDatasetId(c.datasets(0).id) curations.getCurationFiles(curations.getAllCurationFileIds(c.id)).map { file => @@ -106,7 +106,7 @@ class CurationObjects @Inject()(datasets: DatasetService, Json.toJson(Map( "comment_body" -> Json.toJson(comm.text), "comment_date" -> Json.toJson(format.format(comm.posted)), - "Identifier" -> Json.toJson("urn:uuid:"+comm.id), + "Identifier" -> Json.toJson("urn:uuid:" + comm.id), "comment_author" -> Json.toJson(userService.findById(comm.author.id).map ( usr => Json.toJson(usr.fullName + ": " + api.routes.Users.findById(usr.id).absoluteURL(https)))) )) } diff --git a/app/api/Datasets.scala b/app/api/Datasets.scala index ec29d2813..c020b7fb9 100644 --- a/app/api/Datasets.scala +++ b/app/api/Datasets.scala @@ -1110,8 +1110,8 @@ class Datasets @Inject()( BadRequest(toJson(s"The given id $id is not a valid ObjectId.")) } } - //End, Update Dataset Information code - + //End, Update Dataset Information code + def removeCreator(id: UUID, creator: String) = PermissionAction(Permission.EditDataset, Some(ResourceRef(ResourceRef.dataset, id))) { implicit request => implicit val user = request.user if (UUID.isValid(id.stringify)) { @@ -1132,12 +1132,12 @@ class Datasets @Inject()( BadRequest(toJson(s"The given id $id is not a valid ObjectId.")) } } - //End, removeCreator - + //End, removeCreator + def moveCreator(id: UUID, creator: String, newPos: Int) = PermissionAction(Permission.EditDataset, Some(ResourceRef(ResourceRef.dataset, id))) { implicit request => implicit val user = request.user if (UUID.isValid(id.stringify)) { - + Logger.debug(s"Move Creator for dataset with id $id. : $creator to $newPos") datasets.moveCreator(id, creator, newPos) datasets.get(id) match { @@ -1154,8 +1154,8 @@ class Datasets @Inject()( } } //End, move Creator - - + + //Update License code /** * REST endpoint: POST: update the license data associated with a specific Dataset @@ -2139,8 +2139,8 @@ class Datasets @Inject()( var is: Option[InputStream] = addDatasetInfoToZip(dataFolder,dataset,zip) //digest input stream val md5 = MessageDigest.getInstance("MD5") - md5Files.put(dataFolder+"_info.json",md5) - is = Some(new DigestInputStream(is.get,md5)) + md5Files.put(dataFolder + "_info.json", md5) + is = Some(new DigestInputStream(is.get, md5)) file_type = 1 //next is metadata @@ -2163,7 +2163,7 @@ class Datasets @Inject()( case (0,0) => { is = addDatasetInfoToZip(dataFolder,dataset,zip) val md5 = MessageDigest.getInstance("MD5") - md5Files.put("_info.json",md5) + md5Files.put("_info.json", md5) is = Some(new DigestInputStream(is.get, md5)) file_type = file_type + 1 } @@ -2171,7 +2171,7 @@ class Datasets @Inject()( case (0,1) => { is = addDatasetMetadataToZip(dataFolder,dataset,zip) val md5 = MessageDigest.getInstance("MD5") - md5Files.put("_metadata.json",md5) + md5Files.put("_metadata.json", md5) is = Some(new DigestInputStream(is.get, md5)) level = 1 file_type = 0 @@ -2180,10 +2180,10 @@ class Datasets @Inject()( case (1,0) =>{ is = addFileInfoToZip(filenameMap(inputFiles(count).id), inputFiles(count), zip) val md5 = MessageDigest.getInstance("MD5") - md5Files.put(filenameMap(inputFiles(count).id)+"_info.json",md5) + md5Files.put(filenameMap(inputFiles(count).id) + "_info.json",md5) is = Some(new DigestInputStream(is.get, md5)) - if (count+1 < inputFiles.size ){ - count +=1 + if (count + 1 < inputFiles.size){ + count += 1 } else { count = 0 file_type = 1 @@ -2193,10 +2193,10 @@ class Datasets @Inject()( case (1,1) =>{ is = addFileMetadataToZip(filenameMap(inputFiles(count).id), inputFiles(count), zip) val md5 = MessageDigest.getInstance("MD5") - md5Files.put(filenameMap(inputFiles(count).id)+"_metadata.json",md5) + md5Files.put(filenameMap(inputFiles(count).id) + "_metadata.json",md5) is = Some(new DigestInputStream(is.get, md5)) - if (count+1 < inputFiles.size ){ - count +=1 + if (count + 1 < inputFiles.size){ + count += 1 } else { count = 0 file_type = 2 @@ -2208,8 +2208,8 @@ class Datasets @Inject()( val md5 = MessageDigest.getInstance("MD5") md5Files.put(filenameMap(inputFiles(count).id),md5) is = Some(new DigestInputStream(is.get, md5)) - if (count+1 < inputFiles.size ){ - count +=1 + if (count + 1 < inputFiles.size ){ + count += 1 } else { if (bagit){ count = 0 @@ -2227,7 +2227,7 @@ class Datasets @Inject()( case (2,0) => { is = addBagItTextToZip(totalBytes,filenameMap.size,zip,dataset,user) val md5 = MessageDigest.getInstance("MD5") - md5Bag.put("bagit.txt",md5) + md5Bag.put("bagit.txt", md5) is = Some(new DigestInputStream(is.get, md5)) file_type = 1 } @@ -2235,7 +2235,7 @@ class Datasets @Inject()( case (2,1) => { is = addBagInfoToZip(zip) val md5 = MessageDigest.getInstance("MD5") - md5Bag.put("bag-info.txt",md5) + md5Bag.put("bag-info.txt", md5) is = Some(new DigestInputStream(is.get, md5)) file_type = 2 } @@ -2243,7 +2243,7 @@ class Datasets @Inject()( case (2,2) => { is = addManifestMD5ToZip(md5Files.toMap[String,MessageDigest],zip) val md5 = MessageDigest.getInstance("MD5") - md5Bag.put("manifest-md5.txt",md5) + md5Bag.put("manifest-md5.txt", md5) is = Some(new DigestInputStream(is.get, md5)) file_type = 3 } @@ -2251,7 +2251,7 @@ class Datasets @Inject()( case (2,3) => { is = addTagManifestMD5ToZip(md5Bag.toMap[String,MessageDigest],zip) val md5 = MessageDigest.getInstance("MD5") - md5Bag.put("tagmanifest-md5.txt",md5) + md5Bag.put("tagmanifest-md5.txt", md5) is = Some(new DigestInputStream(is.get, md5)) level = -1 file_type = -1 @@ -2370,19 +2370,19 @@ class Datasets @Inject()( private def addBagItTextToZip(totalbytes: Long, totalFiles: Long, zip: ZipOutputStream, dataset: models.Dataset, user: Option[models.User]) = { zip.putNextEntry(new ZipEntry("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" + 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: " + _root_.util.Formatters.humanReadableByteCount(totalbytes) + "\n" - val payLoadOxum = "Payload-Oxum: "+ totalbytes + "." + totalFiles +"\n" - val senderIdentifier="Internal-Sender-Identifier: "+dataset.id+"\n" - val senderDescription = "Internal-Sender-Description: "+dataset.description+"\n" + val payLoadOxum = "Payload-Oxum: " + totalbytes + "." + totalFiles + "\n" + val senderIdentifier="Internal-Sender-Identifier: " + dataset.id + "\n" + val senderDescription = "Internal-Sender-Description: " + dataset.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"))) @@ -2390,7 +2390,7 @@ class Datasets @Inject()( private def addBagInfoToZip(zip : ZipOutputStream) : Option[InputStream] = { zip.putNextEntry(new ZipEntry("bag-info.txt")) - val s : String = "BagIt-Version: 0.97\n"+"Tag-File-Character-Encoding: UTF-8\n" + val s : String = "BagIt-Version: 0.97\n" + "Tag-File-Character-Encoding: UTF-8\n" Some(new ByteArrayInputStream(s.getBytes("UTF-8"))) } @@ -2399,7 +2399,7 @@ class Datasets @Inject()( 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 } } @@ -2411,7 +2411,7 @@ class Datasets @Inject()( 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 } } @@ -2432,7 +2432,7 @@ class Datasets @Inject()( // Use a 1MB in memory byte array Ok.chunked(enumeratorFromDataset(dataset,1024*1024, compression,bagit,user)).withHeaders( CONTENT_TYPE -> "application/zip", - CONTENT_DISPOSITION -> (FileUtils.encodeAttachment(dataset.name+ ".zip", request.headers.get("user-agent").getOrElse(""))) + CONTENT_DISPOSITION -> (FileUtils.encodeAttachment(dataset.name + ".zip", request.headers.get("user-agent").getOrElse(""))) ) } // If the dataset wasn't found by ID @@ -2520,13 +2520,13 @@ class Datasets @Inject()( case None => BadRequest(s"Unable to copy the dataset with id $datasetId to space with id: $spaceId") } } - case None => BadRequest(s"No space found with id: + $spaceId.") + case None => BadRequest(s"No space found with id: $spaceId.") } } else { BadRequest("You don't have permission to copy the dataset.") } } - case None => BadRequest(s"No dataset found with id: $datasetId") + case None => BadRequest(s"No dataset found with id: $datasetId") } } case None => BadRequest("You need to be logged in to copy a dataset to a space.") diff --git a/app/api/Events.scala b/app/api/Events.scala index cbd693ee5..0c711f588 100644 --- a/app/api/Events.scala +++ b/app/api/Events.scala @@ -31,10 +31,11 @@ class Events @Inject() (events: EventService, val ex = (request.body \ "exceptions").asOpt[String].getOrElse("Non-tracked exceptions") val subject: String = "Exception from " + AppConfiguration.getDisplayName val body = Html("
URL: " + Utils.baseUrl(request) + "
\n" + - "Version: " + sys.props.getOrElse("build.version", default = "0.0.0") + "#"+sys.props.getOrElse("build.bamboo", default = "development") + - " branch:" + sys.props.getOrElse("build.branch", default = "unknown") +" sha1:"+sys.props.getOrElse("build.gitsha1", default = "unknown")+"
\n" + - "Request: "+re+"
\n" + - "Error: "+ex+"
") + "Version: " + sys.props.getOrElse("build.version", default = "0.0.0") + "#" + sys.props.getOrElse("build.bamboo", default = "development") + + " branch:" + sys.props.getOrElse("build.branch", default = "unknown") +" sha1:" + sys.props.getOrElse("build.gitsha1", default = "unknown") + "
\n" + + "Request: " + re + "
\n" + + "Error: " + ex + "
") + // FIXME: hardcoded email val recipient: String = "opensource+clowder@ncsa.illinois.edu" Mail.sendEmail(subject, request.user, recipient, body) Ok(toJson("Send Email success")) diff --git a/app/api/Extractions.scala b/app/api/Extractions.scala index bb417f4c4..3f133a074 100644 --- a/app/api/Extractions.scala +++ b/app/api/Extractions.scala @@ -155,11 +155,11 @@ class Extractions @Inject()( else { BadRequest("Not valid id") } - } //case plugin + } //case plugin case None => { BadRequest("No Service") } - } //plugin match + } //plugin match } /** @@ -174,7 +174,7 @@ class Extractions @Inject()( case Some(plugin) => { files.get(id) match { case Some(file) => { - //Get the list of extractors processing the file + //Get the list of extractors processing the file val l = extractions.getExtractorList(file.id) map { elist => (elist._1, elist._2) @@ -387,7 +387,7 @@ class Extractions @Inject()( val listNamesJson = toJson(listNames) Ok(toJson(Map("Extractors" -> listNamesJson))) } - + /** * Temporary fix for BD-289: Get Details of Extractors' Servers IP, Names and Count */ @@ -646,7 +646,7 @@ class Extractions @Inject()( _.fileSetAddedToDataset(ds, filelist.toList, Utils.baseUrl(request), request.apiKey) } } - case None => BadRequest(toJson("Dataset "+datasetid+" not found")) + case None => BadRequest(toJson("Dataset " + datasetid + " not found")) } Ok(toJson("added new event")) diff --git a/app/api/Folders.scala b/app/api/Folders.scala index 7c0d43e69..3631f38e2 100644 --- a/app/api/Folders.scala +++ b/app/api/Folders.scala @@ -333,7 +333,7 @@ class Folders @Inject() ( } } - case None => BadRequest("Failed to copy the file. The destination folder doesn't exist. New folder Id: "+ newFolderId) + case None => BadRequest("Failed to copy the file. The destination folder doesn't exist. New folder Id: " + newFolderId) } } diff --git a/app/api/Geometry.scala b/app/api/Geometry.scala index 5cdd54bf1..8ebf5b6b0 100644 --- a/app/api/Geometry.scala +++ b/app/api/Geometry.scala @@ -12,7 +12,7 @@ class Geometry @Inject()(threeD: ThreeDService) extends Controller with ApiContr /** * Upload a 3D binary geometry file. - */ + */ def uploadGeometry() = PermissionAction(Permission.AddFile)(parse.multipartFormData) { implicit request => request.body.file("File").map { f => Logger.debug("Uploading binary geometry file " + f.filename) @@ -27,4 +27,4 @@ class Geometry @Inject()(threeD: ThreeDService) extends Controller with ApiContr BadRequest(toJson("File not attached.")) } } -} \ No newline at end of file +} diff --git a/app/api/Geostreams.scala b/app/api/Geostreams.scala index 75d66898c..3d129d36e 100644 --- a/app/api/Geostreams.scala +++ b/app/api/Geostreams.scala @@ -229,34 +229,34 @@ object Geostreams extends ApiController { def updateStatisticsSensor(id: String) = PermissionAction(Permission.AddGeoStream) { implicit request => Logger.debug("update sensor statistics for " + id) current.plugin[PostgresPlugin] match { - case Some(plugin) if plugin.isEnabled => { - plugin.updateSensorStats(Some(id)) - jsonp("""{"status":"updated"}""", request) - } + case Some(plugin) if plugin.isEnabled => { + plugin.updateSensorStats(Some(id)) + jsonp("""{"status":"updated"}""", request) + } case _ => pluginNotEnabled - } + } } def updateStatisticsStream(id: String) = PermissionAction(Permission.AddGeoStream) { implicit request => Logger.debug("update stream statistics for " + id) - current.plugin[PostgresPlugin] match { - case Some(plugin) if plugin.isEnabled => { - plugin.updateStreamStats(Some(id)) - jsonp("""{"status":"updated"}""", request) - } + current.plugin[PostgresPlugin] match { + case Some(plugin) if plugin.isEnabled => { + plugin.updateStreamStats(Some(id)) + jsonp("""{"status":"updated"}""", request) + } case _ => pluginNotEnabled - } + } } def updateStatisticsStreamSensor() = PermissionAction(Permission.AddGeoStream) { implicit request => Logger.debug("update all sensor/stream statistics") - current.plugin[PostgresPlugin] match { - case Some(plugin) if plugin.isEnabled => { - plugin.updateSensorStats(None) - jsonp("""{"status":"updated"}""", request) - } + current.plugin[PostgresPlugin] match { + case Some(plugin) if plugin.isEnabled => { + plugin.updateSensorStats(None) + jsonp("""{"status":"updated"}""", request) + } case _ => pluginNotEnabled - } + } } def getSensorStatistics(id: String) = PermissionAction(Permission.ViewGeoStream) { implicit request => @@ -402,8 +402,8 @@ object Geostreams extends ApiController { current.plugin[PostgresPlugin] match { case Some(plugin) if plugin.isEnabled => { plugin.counts() match { - case (sensors, streams, datapoints) => jsonp(Json.obj("sensors"->sensors,"streams"->streams,"datapoints"->datapoints), request) - case _ => jsonp("""{"status":"error"}""", request) + case (sensors, streams, datapoints) => jsonp(Json.obj("sensors"->sensors,"streams"->streams,"datapoints"->datapoints), request) + case _ => jsonp("""{"status":"error"}""", request) } } case _ => pluginNotEnabled @@ -676,7 +676,7 @@ object Geostreams extends ApiController { var counter = new DateTime((startTime.getYear / 10) * 10, 1, 1, 0, 0, 0) while (counter.isBefore(endTime) || counter.isEqual(endTime)) { val year = counter.getYear - val date = new DateTime(year+5,7,1,12,0,0) + val date = new DateTime(year + 5,7,1,12,0,0) result.put(year.toString, Json.obj("year" -> year, "date" -> iso.print(date))) counter = counter.plusYears(10) } @@ -685,7 +685,7 @@ object Geostreams extends ApiController { var counter = new DateTime((startTime.getYear / 5) * 5, 1, 1, 0, 0, 0) while (counter.isBefore(endTime) || counter.isEqual(endTime)) { val year = counter.getYear - val date = new DateTime(year+2,7,1,12,0,0) + val date = new DateTime(year + 2,7,1,12,0,0) result.put(year.toString, Json.obj("year" -> year, "date" -> iso.print(date))) counter = counter.plusYears(5) } @@ -731,9 +731,9 @@ object Geostreams extends ApiController { result.put(year + " fall", Json.obj("year" -> year, "date" -> iso.print(new DateTime(year, 11, 1, 12, 0, 0)))) } else { - result.put(year + " winter", Json.obj("year" -> year, + result.put(year + " winter", Json.obj("year" -> year, "date" -> iso.print(new DateTime(year, 2, 1, 12, 0, 0)))) - } + } counter = counter.plusMonths(3) } } @@ -1336,7 +1336,7 @@ object Geostreams extends ApiController { var index = 0 while (index < points.length - 1) { val lat = Parsers.parseDouble(points(index)) - val lon = Parsers.parseDouble(points(index+1)) + val lon = Parsers.parseDouble(points(index + 1)) if (lat.isDefined && lon.isDefined) { coordinates += Json.toJson(Array(lon.get, lat.get)) } diff --git a/app/api/Indexes.scala b/app/api/Indexes.scala index 86158328a..9ca97a7be 100644 --- a/app/api/Indexes.scala +++ b/app/api/Indexes.scala @@ -21,9 +21,9 @@ class Indexes @Inject() (multimediaSearch: MultimediaQueryService, previews: Pre */ def index() = PermissionAction(Permission.MultimediaIndexDocument)(parse.json) { implicit request => (request.body \ "section_id").asOpt[String].map { section_id => - (request.body \ "preview_id").asOpt[String].map { preview_id => + (request.body \ "preview_id").asOpt[String].map { preview_id => previews.get(UUID(preview_id)) match { - case Some(p) => + case Some(p) => current.plugin[RabbitmqPlugin].foreach{ _.submitSectionPreviewManually(p, new UUID(section_id), Utils.baseUrl(request), request.apiKey) } @@ -32,17 +32,17 @@ class Indexes @Inject() (multimediaSearch: MultimediaQueryService, previews: Pre _.indexPreview(p.id,fileType) } Ok(toJson("success")) - case None => + case None => BadRequest(toJson("Missing parameter [preview_id]")) } - }.getOrElse { - BadRequest(toJson("Missing parameter [preview_id]")) - } + }.getOrElse { + BadRequest(toJson("Missing parameter [preview_id]")) + } }.getOrElse { BadRequest(toJson("Missing parameter [section_id]")) } } - + /** * Add feature to index. */ @@ -59,7 +59,7 @@ class Indexes @Inject() (multimediaSearch: MultimediaQueryService, previews: Pre case None => { val jsFeatures = (request.body \ "features").as[List[JsObject]] val features = jsFeatures.map {f => - Feature((f \ "representation").as[String], (f \ "descriptor").as[List[Double]]) + Feature((f \ "representation").as[String], (f \ "descriptor").as[List[Double]]) } val doc = MultimediaFeatures(section_id = Some(sectionUUID), features = features) multimediaSearch.insert(doc) diff --git a/app/api/Permissions.scala b/app/api/Permissions.scala index c60d96dd7..813035c1f 100644 --- a/app/api/Permissions.scala +++ b/app/api/Permissions.scala @@ -13,8 +13,8 @@ import services._ object Permission extends Enumeration { type Permission = Value - // spaces - val ViewSpace, + // spaces + val ViewSpace, CreateSpace, DeleteSpace, EditSpace, @@ -77,10 +77,10 @@ object Permission extends Enumeration { CreateSensor, ViewSensor, DeleteSensor, - AddGeoStream, - ViewGeoStream, - DeleteGeoStream, - AddDatapoints, + AddGeoStream, + ViewGeoStream, + DeleteGeoStream, + AddDatapoints, // relations CreateRelation, @@ -139,9 +139,9 @@ object Permission extends Enumeration { lazy val vocabularyterms: VocabularyTermService = DI.injector.getInstance(classOf[VocabularyTermService]) /** Returns true if the user is listed as a server admin */ - def checkServerAdmin(user: Option[User]): Boolean = { - user.exists(u => u.status==UserStatus.Admin) - } + def checkServerAdmin(user: Option[User]): Boolean = { + user.exists(u => u.status==UserStatus.Admin) + } /** Returns true if the user is the owner of the resource, this function is used in the code for checkPermission as well. */ def checkOwner(user: Option[User], resourceRef: ResourceRef): Boolean = { diff --git a/app/api/Reporting.scala b/app/api/Reporting.scala index cbc266806..06601774c 100644 --- a/app/api/Reporting.scala +++ b/app/api/Reporting.scala @@ -160,13 +160,13 @@ class Reporting @Inject()(selections: SelectionService, } contents += "\"space\"," - contents += "\""+sp.id.toString+"\"," - contents += "\""+sp.name.replace("\"", "\"\"")+"\"," - contents += "\""+sp.description.replace("\"", "\"\"")+"\"," - contents += "\""+creator_id+"\"," - contents += dateFormat.format(sp.created)+"," - contents += sp.datasetCount.toString+"," - contents += sp.collectionCount.toString+"," + contents += "\"" + sp.id.toString + "\"," + contents += "\"" + sp.name.replace("\"", "\"\"") + "\"," + contents += "\"" + sp.description.replace("\"", "\"\"") + "\"," + contents += "\"" + creator_id + "\"," + contents += dateFormat.format(sp.created) + "," + contents += sp.datasetCount.toString + "," + contents += sp.collectionCount.toString + "," contents += sp.userCount.toString contents += "\n" }) @@ -197,22 +197,22 @@ class Reporting @Inject()(selections: SelectionService, }) contents += "\"user\"," - contents += "\""+u.id.toString+"\"," - contents += "\""+u.getMiniUser.fullName+"\"," - contents += "\""+u.email.getOrElse("")+"\"," - contents += "\""+u.identityId.providerId+"\"," + contents += "\"" + u.id.toString + "\"," + contents += "\"" + u.getMiniUser.fullName + "\"," + contents += "\"" + u.email.getOrElse("") + "\"," + contents += "\"" + u.identityId.providerId + "\"," u.lastLogin match { case Some(lastdate) => { - contents += dateFormat.format(lastdate)+"," + contents += dateFormat.format(lastdate) + "," val currdate = new Date val difference = (currdate.getTime()-currdate.getTime())/86400000 - contents += Math.abs(difference).toString+"," + contents += Math.abs(difference).toString + "," } case None => contents += ",," } - contents += (if (u.status==UserStatus.Inactive) "false" else "true")+"," - contents += (if (u.status==UserStatus.Admin) "true" else "false")+"," - contents += admin_spaces.toString+"," + contents += (if (u.status==UserStatus.Inactive) "false" else "true") + "," + contents += (if (u.status==UserStatus.Admin) "true" else "false") + "," + contents += admin_spaces.toString + "," contents += member_spaces.toString contents += "\n" }) @@ -268,20 +268,20 @@ class Reporting @Inject()(selections: SelectionService, } contents += "\"file\"," - contents += "\""+f.id.toString+"\"," - contents += "\""+f.filename+"\"," - contents += "\""+f.author.fullName+"\"," - contents += "\""+f.author.id+"\"," - contents += (f.length/1000).toInt.toString+"," - contents += dateFormat.format(f.uploadDate)+"," - contents += vwcount+"," - contents += dlcount+"," - contents += lvstr+"," - contents += ldstr+"," - contents += "\""+f.loader_id+"\"," - contents += "\""+ds_list+"\"," - contents += "\""+coll_list+"\"," - contents += "\""+space_list+"\"" + contents += "\"" + f.id.toString + "\"," + contents += "\"" + f.filename + "\"," + contents += "\"" + f.author.fullName + "\"," + contents += "\"" + f.author.id + "\"," + contents += (f.length/1000).toInt.toString + "," + contents += dateFormat.format(f.uploadDate) + "," + contents += vwcount + "," + contents += dlcount + "," + contents += lvstr + "," + contents += ldstr + "," + contents += "\"" + f.loader_id + "\"," + contents += "\"" + ds_list + "\"," + contents += "\"" + coll_list + "\"," + contents += "\"" + space_list + "\"" contents += "\n" return contents @@ -322,20 +322,20 @@ class Reporting @Inject()(selections: SelectionService, } contents += "\"dataset\"," - contents += "\""+ds.id.toString+"\"," - contents += "\""+ds.name.replace("\"", "\"\"")+"\"," - contents += "\""+ds.author.fullName+"\"," - contents += "\""+ds.author.id+"\"," + contents += "\"" + ds.id.toString + "\"," + contents += "\"" + ds.name.replace("\"", "\"\"") + "\"," + contents += "\"" + ds.author.fullName + "\"," + contents += "\"" + ds.author.id + "\"," if (returnAllColums) contents += "," // datasets do not have size - contents += dateFormat.format(ds.created)+"," - contents += vwcount+"," - contents += dlcount+"," - contents += lvstr+"," - contents += ldstr+"," + contents += dateFormat.format(ds.created) + "," + contents += vwcount + "," + contents += dlcount + "," + contents += lvstr + "," + contents += ldstr + "," if (returnAllColums) contents += "," // datasets do not have location if (returnAllColums) contents += "," // datasets do not have parent_datasets - contents += "\""+coll_list+"\"," - contents += "\""+space_list+"\"" + contents += "\"" + coll_list + "\"," + contents += "\"" + space_list + "\"" contents += "\n" return contents @@ -370,20 +370,20 @@ class Reporting @Inject()(selections: SelectionService, } contents += "\"collection\"," - contents += "\""+coll.id.toString+"\"," - contents += "\""+coll.name.replace("\"", "\"\"")+"\"," - contents += "\""+coll.author.fullName+"\"," - contents += "\""+coll.author.id+"\"," + contents += "\"" + coll.id.toString + "\"," + contents += "\"" + coll.name.replace("\"", "\"\"") + "\"," + contents += "\"" + coll.author.fullName + "\"," + contents += "\"" + coll.author.id + "\"," if (returnAllColums) contents += "," // collections do not have size - contents += dateFormat.format(coll.created)+"," - contents += vwcount+"," + contents += dateFormat.format(coll.created) + "," + contents += vwcount + "," if (returnAllColums) contents += "," // collections do not have downloads - contents += lvstr+"," + contents += lvstr + "," if (returnAllColums) contents += "," // collections do not have last_downloaded if (returnAllColums) contents += "," // collections do not have location if (returnAllColums) contents += "," // collections do not have parent_datasets - contents += "\""+coll_list+"\"," - contents += "\""+space_list+"\"" + contents += "\"" + coll_list + "\"," + contents += "\"" + space_list + "\"" contents += "\n" return contents diff --git a/app/api/Search.scala b/app/api/Search.scala index 7cfc86c6b..0c865b27e 100644 --- a/app/api/Search.scala +++ b/app/api/Search.scala @@ -127,7 +127,7 @@ class Search @Inject() ( queues map { case (key, queue) => val list = new ListBuffer[SearchResult] - for (element <- queue) { + for (element <- queue) { val previewsBySection = previews.findBySectionId(element.target_section) if (previewsBySection.size == 1) { Logger.trace("Appended search result " + key + " " + element.target_section + " " + element.distance + " " + previewsBySection(0).id.toString) @@ -141,7 +141,7 @@ class Search @Inject() ( val jsonResults = toJson(items.toMap) Ok(jsonResults) - + } case None => InternalServerError("feature not found") } diff --git a/app/api/Sections.scala b/app/api/Sections.scala index 192de0d8e..a2ffb0a37 100644 --- a/app/api/Sections.scala +++ b/app/api/Sections.scala @@ -170,25 +170,25 @@ class Sections @Inject()( case None => BadRequest } } - + def description(id: UUID) = PermissionAction(Permission.EditSection, Some(ResourceRef(ResourceRef.section, id)))(parse.json) { implicit request => - request.user match { - case Some(identity) => { - request.body.\("description").asOpt[String] match { - case Some(descr) => { - sections.setDescription(id, descr) - Ok(toJson(Map("status"->"success"))) - } - case None => { - Logger.error("no section description specified.") - BadRequest(toJson("no section description specified.")) - } - } - } - case None => - Logger.error(("No user identity found in the request, request body: " + request.body)) - BadRequest(toJson("No user identity found in the request, request body: " + request.body)) - } + request.user match { + case Some(identity) => { + request.body.\("description").asOpt[String] match { + case Some(descr) => { + sections.setDescription(id, descr) + Ok(toJson(Map("status"->"success"))) + } + case None => { + Logger.error("no section description specified.") + BadRequest(toJson("no section description specified.")) + } + } + } + case None => + Logger.error(("No user identity found in the request, request body: " + request.body)) + BadRequest(toJson("No user identity found in the request, request body: " + request.body)) + } } /** @@ -199,7 +199,7 @@ class Sections @Inject()( case Some(section) => { thumbnails.get(thumbnail_id) match { case Some(thumbnail) => { - sections.updateThumbnail(section_id, thumbnail_id) + sections.updateThumbnail(section_id, thumbnail_id) Ok(toJson(Map("status" -> "success"))) } case None => BadRequest(toJson("Thumbnail not found")) @@ -208,5 +208,5 @@ class Sections @Inject()( case None => BadRequest(toJson("Section not found " + section_id)) } } - + } diff --git a/app/api/Selected.scala b/app/api/Selected.scala index 3f5b3996e..e51da2eca 100644 --- a/app/api/Selected.scala +++ b/app/api/Selected.scala @@ -44,7 +44,7 @@ class Selected @Inject()(selections: SelectionService, def add() = AuthenticatedAction(parse.json) { implicit request => Logger.debug("Requesting Selected.add" + request.body) request.body.\("dataset").asOpt[String] match { - case Some(dataset) => { + case Some(dataset) => { request.user match { case Some(user) => { selections.add(UUID(dataset), user.email.get) @@ -52,18 +52,18 @@ class Selected @Inject()(selections: SelectionService, } case None => Ok(toJson(Map("success"->"false", "msg"->"User not logged in"))) } - } - case None => { - Logger.error("no dataset specified") - BadRequest - } + } + case None => { + Logger.error("no dataset specified") + BadRequest + } } } - + def remove() = AuthenticatedAction(parse.json) { implicit request => Logger.debug("Requesting Selected.remove" + request.body) request.body.\("dataset").asOpt[String] match { - case Some(dataset) => { + case Some(dataset) => { request.user match { case Some(user) => { selections.remove(UUID(dataset), user.email.get) @@ -71,11 +71,11 @@ class Selected @Inject()(selections: SelectionService, } case None => Ok(toJson(Map("success"->"false", "msg"->"User not logged in"))) } - } - case None => { - Logger.error("no dataset specified") - BadRequest - } + } + case None => { + Logger.error("no dataset specified") + BadRequest + } } } @@ -87,7 +87,7 @@ class Selected @Inject()(selections: SelectionService, selections.get(user.email.get).map(d => { selections.remove(d.id, user.email.get) }) - Ok(toJson(Map("sucess"->"true"))) + Ok(toJson(Map("success"->"true"))) } } } @@ -100,7 +100,7 @@ class Selected @Inject()(selections: SelectionService, datasets.removeDataset(d.id, Utils.baseUrl(request), request.apiKey, request.user) selections.remove(d.id, user.email.get) }) - Ok(toJson(Map("sucess"->"true"))) + Ok(toJson(Map("success"->"true"))) } } } @@ -189,8 +189,8 @@ class Selected @Inject()(selections: SelectionService, events.addObjectEvent(request.user, d.id, d.name, EventType.ADD_TAGS_DATASET.toString) datasets.index(d.id) }) - Ok(toJson(Map("sucess"->"true"))) + Ok(toJson(Map("success"->"true"))) } } } -} \ No newline at end of file +} diff --git a/app/api/Sensors.scala b/app/api/Sensors.scala index 6a5b49eee..1970b5736 100644 --- a/app/api/Sensors.scala +++ b/app/api/Sensors.scala @@ -5,64 +5,63 @@ import play.api.Play.current import services.PostgresPlugin /** - * Metadata about sensors registered with the system. Datastreams can be associalted with sensors. + * Metadata about sensors registered with the system. Datastreams can be associated with sensors. */ object Sensors extends Controller with ApiController { def add() = PermissionAction(Permission.AddGeoStream)(parse.json) { implicit request => - current.plugin[PostgresPlugin] match { - case Some(plugin) => { - Ok("") - } - case None => { - Ok("") - } + current.plugin[PostgresPlugin] match { + case Some(plugin) => { + Ok("") } + case None => { + Ok("") + } + } } - + def get(id: String) = PermissionAction(Permission.ViewGeoStream)(parse.json) { implicit request => - current.plugin[PostgresPlugin] match { - case Some(plugin) => { - Ok("") - } - case None => { - Ok("") - } + current.plugin[PostgresPlugin] match { + case Some(plugin) => { + Ok("") + } + case None => { + Ok("") } + } } - + def list() = PermissionAction(Permission.ViewGeoStream)(parse.json) { implicit request => - current.plugin[PostgresPlugin] match { - case Some(plugin) => { - val sensors = plugin.listSensors() - Ok("") - } - case None => { - Ok("") - } + current.plugin[PostgresPlugin] match { + case Some(plugin) => { + val sensors = plugin.listSensors() + Ok("") + } + case None => { + Ok("") } + } } - + def search() = PermissionAction(Permission.ViewGeoStream)(parse.json) { implicit request => - current.plugin[PostgresPlugin] match { - case Some(plugin) => { - Ok("") - } - case None => { - Ok("") - } + current.plugin[PostgresPlugin] match { + case Some(plugin) => { + Ok("") + } + case None => { + Ok("") } + } } - + def delete(id: String) = PermissionAction(Permission.DeleteGeoStream)(parse.json) { implicit request => - current.plugin[PostgresPlugin] match { - case Some(plugin) => { - Ok("") - } - case None => { - Ok("") - } + current.plugin[PostgresPlugin] match { + case Some(plugin) => { + Ok("") + } + case None => { + Ok("") } + } } - -} \ No newline at end of file +} diff --git a/app/api/ThreeDTexture.scala b/app/api/ThreeDTexture.scala index 6cd4f1150..1874521bb 100644 --- a/app/api/ThreeDTexture.scala +++ b/app/api/ThreeDTexture.scala @@ -9,13 +9,12 @@ import play.api.mvc.Controller import services.ThreeDService class ThreeDTexture @Inject()(threeD: ThreeDService) extends Controller with ApiController { - /** * Upload a 3D texture file. - */ + */ def uploadTexture() = PermissionAction(Permission.CreatePreview)(parse.multipartFormData) { implicit request => - request.body.file("File").map { f => + request.body.file("File").map { f => Logger.debug("Uploading 3D texture file " + f.filename) // store file try { @@ -28,4 +27,4 @@ class ThreeDTexture @Inject()(threeD: ThreeDService) extends Controller with Api BadRequest(toJson("File not attached.")) } } -} \ No newline at end of file +} diff --git a/app/api/ZoomIt.scala b/app/api/ZoomIt.scala index 8835b9476..9c2250316 100644 --- a/app/api/ZoomIt.scala +++ b/app/api/ZoomIt.scala @@ -29,4 +29,4 @@ class ZoomIt @Inject()(tiles: TileService) extends Controller with ApiController BadRequest(toJson("File not attached.")) } } -} \ No newline at end of file +} diff --git a/app/assets/javascripts/select-bulk.js b/app/assets/javascripts/select-bulk.js index b2dd09111..30a4f68f9 100644 --- a/app/assets/javascripts/select-bulk.js +++ b/app/assets/javascripts/select-bulk.js @@ -20,7 +20,7 @@ $(function() { }); request.fail(function (jqXHR, textStatus, errorThrown){ - console.error("The following error occured: "+ textStatus, errorThrown); + console.error("The following error occurred: "+ textStatus, errorThrown); window.location = "../login"; // FIXME hardcoded }); diff --git a/app/assets/javascripts/select.js b/app/assets/javascripts/select.js index ba387aad7..137bc2be5 100644 --- a/app/assets/javascripts/select.js +++ b/app/assets/javascripts/select.js @@ -19,7 +19,7 @@ $(function() { }); request.fail(function (jqXHR, textStatus, errorThrown){ - console.error("The following error occured: "+ textStatus, errorThrown); + console.error("The following error occurred: "+ textStatus, errorThrown); window.location = "../login"; // FIXME hardcoded }); @@ -40,7 +40,7 @@ $(function() { }); request.fail(function (jqXHR, textStatus, errorThrown){ - console.error("The following error occured: "+ textStatus, errorThrown); + console.error("The following error occurred: "+ textStatus, errorThrown); window.location = "../login"; // FIXME hardcoded }); diff --git a/app/controllers/Admin.scala b/app/controllers/Admin.scala index cb91e0c2d..b80766a0a 100644 --- a/app/controllers/Admin.scala +++ b/app/controllers/Admin.scala @@ -275,7 +275,7 @@ class Admin @Inject() (sectionIndexInfo: SectionIndexInfoService, userService: U case None => { Future(Ok("No Versus Service")) } - } + } } /** @@ -340,8 +340,8 @@ class Admin @Inject() (sectionIndexInfo: SectionIndexInfoService, userService: U } def viewDumpers() = ServerAdminAction { implicit request => - implicit val user = request.user - Ok(views.html.viewDumpers()) + implicit val user = request.user + Ok(views.html.viewDumpers()) } def submitCreateRole() = ServerAdminAction { implicit request => diff --git a/app/controllers/Application.scala b/app/controllers/Application.scala index ab2e0aba5..9be847b9d 100644 --- a/app/controllers/Application.scala +++ b/app/controllers/Application.scala @@ -98,7 +98,7 @@ class Application @Inject() (files: FileService, collections: CollectionService, def index = UserAction(needActive = false) { implicit request => val appConfig: AppConfigurationService = DI.injector.getInstance(classOf[AppConfigurationService]) - implicit val user = request.user + implicit val user = request.user var newsfeedEvents = List.empty[Event] if (!play.Play.application().configuration().getBoolean("clowder.disable.events", false)) { @@ -528,7 +528,7 @@ class Application @Inject() (files: FileService, collections: CollectionService, controllers.routes.javascript.FileLinks.createLink, controllers.routes.javascript.Search.search ) - ).as(JSON) + ).as(JSON) } } diff --git a/app/controllers/Collections.scala b/app/controllers/Collections.scala index 788148837..02f3f45d5 100644 --- a/app/controllers/Collections.scala +++ b/app/controllers/Collections.scala @@ -376,7 +376,7 @@ class Collections @Inject() (datasets: DatasetService, collections: CollectionSe } // view the list of collection in a space that you should not access case Some(s) if !Permission.checkPermission(Permission.ViewSpace, ResourceRef(ResourceRef.space, UUID(s))) => { - BadRequest(views.html.notAuthorized("You are not authorized to access the " + spaceTitle+ ".", s, "space")) + BadRequest(views.html.notAuthorized("You are not authorized to access the " + spaceTitle + ".", s, "space")) } case _ => Ok(views.html.collectionList(decodedCollections.toList, prev, next, limit, viewMode, space, spaceName, title, owner, ownerName, when, date, showTrash)) } @@ -479,8 +479,8 @@ class Collections @Inject() (datasets: DatasetService, collections: CollectionSe } else { Redirect(routes.Collections.collection(collection.id)) } - } - case None => Redirect(routes.Collections.list()).flashing("error" -> "You are not authorized to create new collections.") + } + case None => Redirect(routes.Collections.list()).flashing("error" -> "You are not authorized to create new collections.") } } @@ -581,7 +581,7 @@ class Collections @Inject() (datasets: DatasetService, collections: CollectionSe case Some(collection) => { val datasetsInside = datasets.listCollection(id.stringify, user) - val datasetIdsToUse = datasetsInside.slice(index*limit, (index+1)*limit) + val datasetIdsToUse = datasetsInside.slice(index*limit, (index + 1) * limit) val decodedDatasetsInside = ListBuffer.empty[models.Dataset] for (aDataset <- datasetIdsToUse) { val dDataset = Utils.decodeDatasetElements(aDataset) @@ -589,7 +589,7 @@ class Collections @Inject() (datasets: DatasetService, collections: CollectionSe } val prev = index-1 - val next = if(datasetsInside.length > (index+1) * limit) { + val next = if(datasetsInside.length > (index + 1) * limit) { index + 1 } else { -1 @@ -604,7 +604,7 @@ class Collections @Inject() (datasets: DatasetService, collections: CollectionSe } - case None => Logger.error("Error getting "+ Messages("collection.title") + " " + id); BadRequest(Messages("collection.title") + " not found") + case None => Logger.error("Error getting " + Messages("collection.title") + " " + id); BadRequest(Messages("collection.title") + " not found") } } @@ -613,12 +613,12 @@ class Collections @Inject() (datasets: DatasetService, collections: CollectionSe collections.get(id) match { case Some(collection) => { val dCollection = Utils.decodeCollectionElements(collection) - val child_ids = dCollection.child_collection_ids.slice(index*limit, (index+1)*limit) + val child_ids = dCollection.child_collection_ids.slice(index * limit, (index + 1) * limit) val decodedChildCollections = collections.get(child_ids).found.map(Utils.decodeCollectionElements(_)) val prev = index-1 - val next = if (dCollection.child_collection_ids.length > (index+1)*limit) - index+1 + val next = if (dCollection.child_collection_ids.length > (index + 1) * limit) + index + 1 else -1 diff --git a/app/controllers/CurationObjects.scala b/app/controllers/CurationObjects.scala index d4c628fca..4f5a5e04c 100644 --- a/app/controllers/CurationObjects.scala +++ b/app/controllers/CurationObjects.scala @@ -914,6 +914,6 @@ class CurationObjects @Inject() ( } - + } diff --git a/app/controllers/Datasets.scala b/app/controllers/Datasets.scala index 2e8fa162e..3b29b561e 100644 --- a/app/controllers/Datasets.scala +++ b/app/controllers/Datasets.scala @@ -399,9 +399,9 @@ class Datasets @Inject() ( /** * Sorted List of datasets within a space - * Since this only works within a space right now, it just checks to see if the user has permission to view the space - * (which takes into account the public settings) and, if so, calls the method to list all datasets in the space, regardless - * of status/public view flags, etc. To generalize for sorting of other lists, the permission checks will need to be in + * Since this only works within a space right now, it just checks to see if the user has permission to view the space + * (which takes into account the public settings) and, if so, calls the method to list all datasets in the space, regardless + * of status/public view flags, etc. To generalize for sorting of other lists, the permission checks will need to be in * the dataset query (as in the list method). */ def sortedListInSpace(space: String, offset: Int, size: Int, showPublic: Boolean) = UserAction(needActive = false) { implicit request => @@ -415,7 +415,7 @@ class Datasets @Inject() ( val spaceName = datasetSpace match { case Some(s) => Some(s.name) case None => None - } + } var title: Option[String] = Some(Messages("resource.in.title", Messages("datasets.title"), spaceTitle, routes.Spaces.getSpace(datasetSpace.get.id), datasetSpace.get.name)) @@ -645,8 +645,8 @@ class Datasets @Inject() ( (SortingUtils.sortFolders(folder.folders.flatMap(f => folders.get(f)), sortOrder).slice(limit * filepageUpdate, limit * (filepageUpdate + 1)), SortingUtils.sortFiles(files.get(folder.files).found, sortOrder).slice(limit * filepageUpdate - folder.folders.length, limit * (filepageUpdate + 1) - folder.folders.length)) } else { - (folder.folders.reverse.slice(limit * filepageUpdate, limit * (filepageUpdate+1)).flatMap(f => folders.get(f)), - folder.files.reverse.slice(limit * filepageUpdate - folder.folders.length, limit * (filepageUpdate+1) - folder.folders.length).flatMap(f => files.get(f))) + (folder.folders.reverse.slice(limit * filepageUpdate, limit * (filepageUpdate + 1)).flatMap(f => folders.get(f)), + folder.files.reverse.slice(limit * filepageUpdate - folder.folders.length, limit * (filepageUpdate + 1) - folder.folders.length).flatMap(f => files.get(f))) } var folderHierarchy = new ListBuffer[Folder]() folderHierarchy += folder @@ -680,8 +680,8 @@ class Datasets @Inject() ( (SortingUtils.sortFolders(dataset.folders.flatMap(f => folders.get(f)), sortOrder).slice(limit * filepageUpdate, limit * (filepageUpdate + 1)), SortingUtils.sortFiles(files.get(dataset.files).found, sortOrder).slice(limit * filepageUpdate - dataset.folders.length, limit * (filepageUpdate + 1) - dataset.folders.length)) } else { - (dataset.folders.reverse.slice(limit * filepageUpdate, limit * (filepageUpdate+1)).flatMap(f => folders.get(f)), - dataset.files.reverse.slice(limit * filepageUpdate - dataset.folders.length, limit * (filepageUpdate+1) - dataset.folders.length).flatMap(f => files.get(f))) + (dataset.folders.reverse.slice(limit * filepageUpdate, limit * (filepageUpdate + 1)).flatMap(f => folders.get(f)), + dataset.files.reverse.slice(limit * filepageUpdate - dataset.folders.length, limit * (filepageUpdate + 1) - dataset.folders.length).flatMap(f => files.get(f))) } val fileComments = limitFileList.map { file => @@ -765,7 +765,7 @@ class Datasets @Inject() ( Map( "name" -> toJson("Missing " + Messages("dataset.title") + " ID."), "size" -> toJson(0), - "error" -> toJson("No "+ Messages("dataset.title")+"id found. Please try again.") + "error" -> toJson("No " + Messages("dataset.title") + "id found. Please try again.") ) ) ) @@ -835,4 +835,4 @@ class Datasets @Inject() ( implicit val user = request.user Ok(views.html.generalMetadataSearch()) } -} \ No newline at end of file +} diff --git a/app/controllers/Error.scala b/app/controllers/Error.scala index 7d55100bd..127b10b88 100644 --- a/app/controllers/Error.scala +++ b/app/controllers/Error.scala @@ -9,27 +9,27 @@ import securesocial.core.providers.utils.RoutesHelper /** * Utility controller to be called, typically as a redirect, from the client side when an AJAX error is received, * or when there are errors with authentication or permissions within the normal controller flow. - * + * */ class Error extends SecuredController { /** * Default method when the failure is due to not being logged in. - * + * * Requires no args, provides the generic message "You must be logged in to perform that action.". - * + * */ def authenticationRequired() = UserAction(needActive = false) { implicit request => Results.Redirect(RoutesHelper.login.absoluteURL(IdentityProvider.sslEnabled)).flashing("error" -> "You must be logged in to perform that action.") } - + /** - * Message specific method when the failure is due to not being logged in. Ideally, the original url + * Message specific method when the failure is due to not being logged in. Ideally, the original url * will be set as a cookie so that securesocial can redirect back to the user's original page. - * + * * Client should pass in their own message to be displayed. If the message is null or empty, it will default to * the generic message "You must be logged in to perform that action.". - * + * * @param msg A String that will be the specific error message passed to the login panel * @param url The originating window href for the failed authentication */ @@ -40,14 +40,14 @@ class Error extends SecuredController { if (msg != null && !msg.trim().equals("")) { errMsg = msg } - + Logger.trace("The specified url to redirect to is " + url) - + //If the url is present, set the session key if (url != null && !url.trim().equals("")) { origUrlPresent = true } - + if (origUrlPresent) { Results.Redirect(RoutesHelper.login.absoluteURL(IdentityProvider.sslEnabled)).flashing("error" -> errMsg).withSession("original-url" -> url) } @@ -55,13 +55,13 @@ class Error extends SecuredController { Results.Redirect(RoutesHelper.login.absoluteURL(IdentityProvider.sslEnabled)).flashing("error" -> errMsg) } } - + /** * Redirect request that comes in when a user is logged in but does not have the appropriate permissions for accessing a specific location. - * - * Client may pass in their own message to be displayed. If the message is null or empty, it will default to + * + * Client may pass in their own message to be displayed. If the message is null or empty, it will default to * the generic message "You do not have the permissions required to view that location." - * + * * @param msg A String that will be the specific error message passed to the view to display */ def incorrectPermissions(msg: String) = UserAction(needActive = false) { implicit request => @@ -69,9 +69,9 @@ class Error extends SecuredController { var errMsg = "You do not have the permissions required to view that location." if (msg != null && !msg.trim().equals("")) { errMsg = msg - } - - //Implicit user val necessary to the view in order to make sure that the system knows if there is a user logged in or + } + + //Implicit user val necessary to the view in order to make sure that the system knows if there is a user logged in or //not, for appropriate visual cues. implicit val user = request.user Results.Ok(views.html.noPermissions(errMsg)) @@ -93,4 +93,4 @@ class Error extends SecuredController { implicit val user = request.user Forbidden(views.html.notAuthorized(message, id, resourceType)) } -} \ No newline at end of file +} diff --git a/app/controllers/ExtractionInfo.scala b/app/controllers/ExtractionInfo.scala index 2107f2939..32b559c2c 100644 --- a/app/controllers/ExtractionInfo.scala +++ b/app/controllers/ExtractionInfo.scala @@ -39,7 +39,7 @@ class ExtractionInfo @Inject() (extractors: ExtractorService, dtsrequests: Extra } /** - * Directs currently running extractors information to the webpage + * Directs currently running extractors information to the webpage */ def getExtractorNames() = AuthenticatedAction { implicit request => @@ -47,7 +47,7 @@ class ExtractionInfo @Inject() (extractors: ExtractorService, dtsrequests: Extra Ok(views.html.extractors(list_names, list_names.size)) } - + /** * Directs input type supported by currently running extractors information to the webpage */ @@ -67,7 +67,7 @@ class ExtractionInfo @Inject() (extractors: ExtractorService, dtsrequests: Extra Ok(views.html.extractorsInputTypes(list_inputtypes1,list_inputtypes1.size)) } - + /** * Directs DTS extractions requests information to the webpage */ @@ -78,7 +78,7 @@ class ExtractionInfo @Inject() (extractors: ExtractorService, dtsrequests: Extra var currentTime = Calendar.getInstance().getTime() Ok(views.html.extractionRequests(list_requests, list_requests.size, startTime, currentTime)) } - + /** * DTS Bookmarklet page */ @@ -98,4 +98,4 @@ class ExtractionInfo @Inject() (extractors: ExtractorService, dtsrequests: Extra val extensionHostUrl = configuration.getString("dts.extension.host").getOrElse("") Ok(views.html.dtsExtension(Utils.baseUrl(request), hostname, extensionHostUrl)) } -} \ No newline at end of file +} diff --git a/app/controllers/Extractors.scala b/app/controllers/Extractors.scala index 96617186c..a10664d88 100644 --- a/app/controllers/Extractors.scala +++ b/app/controllers/Extractors.scala @@ -133,4 +133,4 @@ class Extractors @Inject() (extractions: ExtractionService, case None => InternalServerError("Dataset not found") } } -} \ No newline at end of file +} diff --git a/app/controllers/Files.scala b/app/controllers/Files.scala index 7fc5b644f..d76c6e43f 100644 --- a/app/controllers/Files.scala +++ b/app/controllers/Files.scala @@ -347,8 +347,8 @@ class Files @Inject() ( }.toMap //Code to read the cookie data. On default calls, without a specific value for the mode, the cookie value is used. - //Note that this cookie will, in the long run, pertain to all the major high-level views that have the similar - //modal behavior for viewing data. Currently the options are tile and list views. MMF - 12/14 + //Note that this cookie will, in the long run, pertain to all the major high-level views that have the similar + //modal behavior for viewing data. Currently the options are tile and list views. MMF - 12/14 val viewMode: Option[String] = if (mode == null || mode == "") { request.cookies.get("view-mode") match { @@ -488,7 +488,7 @@ class Files @Inject() ( } } /*def extraction(id: String) = SecuredAction(authorization = WithPermission(Permission.ShowFile)) { implicit request => - + }*/ @@ -504,27 +504,27 @@ class Files @Inject() ( Logger.debug("--------- in upload ------------ ") user match { case Some(identity) => { - request.body.file("files[]").map { f => - var nameOfFile = f.filename - var flags = "" - if(nameOfFile.toLowerCase().endsWith(".ptm")){ - val thirdSeparatorIndex = nameOfFile.indexOf("__") - if(thirdSeparatorIndex >= 0){ - val firstSeparatorIndex = nameOfFile.indexOf("_") - val secondSeparatorIndex = nameOfFile.indexOf("_", firstSeparatorIndex+1) - flags = flags + "+numberofIterations_" + nameOfFile.substring(0,firstSeparatorIndex) + "+heightFactor_" + nameOfFile.substring(firstSeparatorIndex+1,secondSeparatorIndex)+ "+ptm3dDetail_" + nameOfFile.substring(secondSeparatorIndex+1,thirdSeparatorIndex) - nameOfFile = nameOfFile.substring(thirdSeparatorIndex+2) - } - } - Logger.debug("Uploading file " + nameOfFile) - - val showPreviews = request.body.asFormUrlEncoded.get("datasetLevel").get(0) - - // store file - val file = files.save(new FileInputStream(f.ref.file), nameOfFile, f.contentType, identity, showPreviews) - val uploadedFile = f - file match { - case Some(f) => { + request.body.file("files[]").map { f => + var nameOfFile = f.filename + var flags = "" + if(nameOfFile.toLowerCase().endsWith(".ptm")){ + val thirdSeparatorIndex = nameOfFile.indexOf("__") + if(thirdSeparatorIndex >= 0){ + val firstSeparatorIndex = nameOfFile.indexOf("_") + val secondSeparatorIndex = nameOfFile.indexOf("_", firstSeparatorIndex + 1) + flags = flags + "+numberofIterations_" + nameOfFile.substring(0, firstSeparatorIndex) + "+heightFactor_" + nameOfFile.substring(firstSeparatorIndex + 1, secondSeparatorIndex) + "+ptm3dDetail_" + nameOfFile.substring(secondSeparatorIndex + 1, thirdSeparatorIndex) + nameOfFile = nameOfFile.substring(thirdSeparatorIndex + 2) + } + } + Logger.debug("Uploading file " + nameOfFile) + + val showPreviews = request.body.asFormUrlEncoded.get("datasetLevel").get(0) + + // store file + val file = files.save(new FileInputStream(f.ref.file), nameOfFile, f.contentType, identity, showPreviews) + val uploadedFile = f + file match { + case Some(f) => { // Add new file & byte count to appConfig appConfig.incrementCount('files, 1) appConfig.incrementCount('bytes, f.length) @@ -577,25 +577,25 @@ class Files @Inject() ( val extra = Map("filename" -> f.filename) dtsrequests.insertRequest(serverIP, clientIP, f.filename, f.id, fileType, f.length, f.uploadDate) /****************************/ - current.plugin[RabbitmqPlugin].foreach{ + current.plugin[RabbitmqPlugin].foreach{ // FIXME dataset not available? _.fileCreated(f, None, Utils.baseUrl(request), request.apiKey) } - - //for metadata files - if(fileType.equals("application/xml") || fileType.equals("text/xml")){ - val xmlToJSON = FilesUtils.readXMLgetJSON(uploadedFile.ref.file) - files.addXMLMetadata(f.id, xmlToJSON) - - current.plugin[ElasticsearchPlugin].foreach{ - _.index(SearchUtils.getElasticsearchObject(f)) + + //for metadata files + if(fileType.equals("application/xml") || fileType.equals("text/xml")){ + val xmlToJSON = FilesUtils.readXMLgetJSON(uploadedFile.ref.file) + files.addXMLMetadata(f.id, xmlToJSON) + + current.plugin[ElasticsearchPlugin].foreach{ + _.index(SearchUtils.getElasticsearchObject(f)) } - } - else{ - current.plugin[ElasticsearchPlugin].foreach{ - _.index(SearchUtils.getElasticsearchObject(f)) + } + else{ + current.plugin[ElasticsearchPlugin].foreach{ + _.index(SearchUtils.getElasticsearchObject(f)) } - } + } current.plugin[VersusPlugin].foreach { _.indexFile(f.id, fileType) } @@ -610,7 +610,7 @@ class Files @Inject() ( current.plugin[AdminsNotifierPlugin].foreach { _.sendAdminsNotification(Utils.baseUrl(request), "File","added",f.id.stringify, nameOfFile)} - //Correctly set the updated URLs and data that is needed for the interface to correctly + //Correctly set the updated URLs and data that is needed for the interface to correctly //update the display after a successful upload. val https = controllers.Utils.https(request) val retMap = Map("files" -> @@ -621,11 +621,11 @@ class Files @Inject() ( "size" -> toJson(uploadedFile.ref.file.length()), "url" -> toJson(routes.Files.file(f.id).absoluteURL(https)), "deleteUrl" -> toJson(api.routes.Files.removeFile(f.id).absoluteURL(https)), - "deleteType" -> toJson("POST") - ) - ) - ) - ) + "deleteType" -> toJson("POST") + ) + ) + ) + ) Ok(toJson(retMap)) } case None => { @@ -675,7 +675,7 @@ class Files @Inject() ( implicit val user = request.user if (UUID.isValid(id.stringify)) { - //Check the license type before doing anything. + //Check the license type before doing anything. files.get(id) match { case Some(file) => { if (file.licenseData.isDownloadAllowed(request.user)) { @@ -777,7 +777,7 @@ class Files @Inject() ( //prepare encoded file name for converted file val lastSeparatorIndex = file.filename.replace("_", ".").lastIndexOf(".") val outputFileName = file.filename.substring(0, lastSeparatorIndex) + "." + outputFormat - + //create local temp file to save polyglot output val tempFileName = "temp_converted_file." + outputFormat val tempFile: java.io.File = new java.io.File(tempFileName) @@ -851,7 +851,7 @@ class Files @Inject() ( case x if x.length == 1 => (x.head.toLong, contentLength - 1) case x => (x(0).toLong, x(1).toLong) } - range match { case (start,end) => + range match { case (start,end) => inputStream.skip(start) @@ -863,11 +863,11 @@ class Files @Inject() ( ACCEPT_RANGES -> "bytes", CONTENT_RANGE -> "bytes %d-%d/%d".format(start, end, contentLength), CONTENT_LENGTH -> (end - start + 1).toString, - CONTENT_TYPE -> contentType - ) - ), - body = Enumerator.fromStream(inputStream) - ) + CONTENT_TYPE -> contentType + ) + ), + body = Enumerator.fromStream(inputStream) + ) } } case None => { @@ -904,7 +904,7 @@ class Files @Inject() ( if (typeToSearch.equals("sectionsSome") && dataParts.contains("sections")) { sections = dataParts("sections").toList } - //END OF: processing searching within files or sections of files or both + //END OF: processing searching within files or sections of files or both request.body.file("File").map { f => try { var nameOfFile = f.filename @@ -921,7 +921,7 @@ class Files @Inject() ( } } Logger.debug("Controllers/Files Uploading file " + nameOfFile) - + // store file val file = queries.save(new FileInputStream(f.ref.file), nameOfFile, f.contentType) val uploadedFile = f @@ -1269,11 +1269,11 @@ class Files @Inject() ( // Logger.debug("Part: " + partName + " filename: " + filename + " contentType: " + contentType); // // TODO RK handle exception for instance if we switch to other DB // Logger.debug("myPartHandler") - // val files = current.plugin[MongoSalatPlugin] match { - // case None => throw new RuntimeException("No MongoSalatPlugin"); - // case Some(x) => x.gridFS("uploads") - // } - // + // val files = current.plugin[MongoSalatPlugin] match { + // case None => throw new RuntimeException("No MongoSalatPlugin"); + // case Some(x) => x.gridFS("uploads") + // } + // // //Set up the PipedOutputStream here, give the input stream to a worker thread // val pos:PipedOutputStream = new PipedOutputStream(); // val pis:PipedInputStream = new PipedInputStream(pos); @@ -1289,8 +1289,8 @@ class Files @Inject() ( //// mongoFile.save //// val id = mongoFile.getAs[ObjectId]("_id").get.toString //// Ok(views.html.file(mongoFile.asDBObject, id)) - // - // + // + // // //Read content to the POS // Iteratee.fold[Array[Byte], PipedOutputStream](pos) { (os, data) => // os.write(data) @@ -1301,26 +1301,26 @@ class Files @Inject() ( // } // } // } - // + // // /** // * Ajax upload. How do we pass in the file name?(parse.temporaryFile) // */ - // - // + // + // // def uploadAjax = Action(parse.temporaryFile) { implicit request => // // val f = request.body.file // val filename=f.getName() - // + // // // store file // // TODO is this still used? if so replace null with user. // Logger.debug("uploadAjax") // val file = files.save(new FileInputStream(f.getAbsoluteFile()), filename, None, null) - // + // // file match { // case Some(f) => { // var fileType = f.contentType - // + // // // TODO RK need to replace unknown with the server name // val key = "unknown." + "file."+ f.contentType.replace(".", "_").replace("/", ".") // // TODO RK : need figure out if we can use https @@ -1331,7 +1331,7 @@ class Files @Inject() ( // _.index("files", "file", id, List(("filename",f.filename), ("contentType", f.contentType))) // } // // redirect to file page - // Redirect(routes.Files.file(f.id.toString)) + // Redirect(routes.Files.file(f.id.toString)) // } // case None => { // Logger.error("Could not retrieve file that was just saved.") @@ -1352,14 +1352,14 @@ class Files @Inject() ( * * TODO Finish implementing. Right now it doesn't write to anything. */ - // case class SomeIteratee(state: Symbol = 'Cont, input: Input[Array[Byte]] = Empty, + // case class SomeIteratee(state: Symbol = 'Cont, input: Input[Array[Byte]] = Empty, // received: Int = 0) extends Iteratee[Array[Byte], Either[Result, Int]] { // Logger.debug(state + " " + input + " " + received) // //// val files = current.plugin[MongoSalatPlugin] match { - //// case None => throw new RuntimeException("No MongoSalatPlugin"); - //// case Some(x) => x.gridFS("uploads") - //// } + //// case None => throw new RuntimeException("No MongoSalatPlugin"); + //// case Some(x) => x.gridFS("uploads") + //// } //// //// val pos:PipedOutputStream = new PipedOutputStream(); //// val pis:PipedInputStream = new PipedInputStream(pos); @@ -1367,27 +1367,27 @@ class Files @Inject() ( //// fh.filename = "test-file.txt" //// fh.contentType = "text/plain" //// } - // - // + // + // // def fold[B]( // done: (Either[Result, Int], Input[Array[Byte]]) => Promise[B], // cont: (Input[Array[Byte]] => Iteratee[Array[Byte], Either[Result, Int]]) => Promise[B], // error: (String, Input[Array[Byte]]) => Promise[B] // ): Promise[B] = state match { - // case 'Done => { + // case 'Done => { // Logger.debug("Done with upload") //// pos.close() - // done(Right(received), Input.Empty) + // done(Right(received), Input.Empty) // } // case 'Cont => cont(in => in match { // case in: El[Array[Byte]] => { // Logger.debug("Getting ready to write " + in.e.length) - // try { + // try { //// pos.write(in.e) - // } catch { - // case error => Logger.error("Error writing to gridfs" + error.toString()) - // } - // Logger.debug("Calling recursive function") + // } catch { + // case error => Logger.error("Error writing to gridfs" + error.toString()) + // } + // Logger.debug("Calling recursive function") // copy(input = in, received = received + in.e.length) // } // case Empty => { diff --git a/app/controllers/Geostreams.scala b/app/controllers/Geostreams.scala index f6d0ecc6d..41fa85bf1 100644 --- a/app/controllers/Geostreams.scala +++ b/app/controllers/Geostreams.scala @@ -96,4 +96,4 @@ class Geostreams @Inject() ( } } -} \ No newline at end of file +} diff --git a/app/controllers/Login.scala b/app/controllers/Login.scala index b9c7d0388..53c3fba8c 100644 --- a/app/controllers/Login.scala +++ b/app/controllers/Login.scala @@ -96,4 +96,4 @@ class Login extends SecuredController { ldapConnection.close() } } -} \ No newline at end of file +} diff --git a/app/controllers/Search.scala b/app/controllers/Search.scala index cd9435b86..309a4f494 100644 --- a/app/controllers/Search.scala +++ b/app/controllers/Search.scala @@ -71,7 +71,7 @@ class Search @Inject() ( } /* - * GET the query file from a URL and compare within the database and show the result + * GET the query file from a URL and compare within the database and show the result * */ def searchbyURL(queryURL: String) = PermissionAction(Permission.ViewDataset).async { implicit request => implicit val user = request.user @@ -89,7 +89,7 @@ class Search @Inject() ( } //convert list of futures into a Future[list] scala.concurrent.Future.sequence(resultListOfFutures) - } //End yield- outer for + } //End yield- outer for for { futureListResults <- futureFutureListResults listOfResults <- futureListResults @@ -133,7 +133,7 @@ class Search @Inject() ( //convert list of futures into a Future[list] scala.concurrent.Future.sequence(resultListOfFutures) - } //End yield + } //End yield for { futureListResults <- futureFutureListResults @@ -144,12 +144,12 @@ class Search @Inject() ( val thumb_id: String = queries.getFile(fileID).flatMap(_.thumbnail_id).map(_.stringify).getOrElse("") Ok(views.html.multimediaSearchResults(filename, Some(fileID), Some(thumb_id), listOfResults)) } - } //end of case Some(plugin) + } //end of case Some(plugin) case None => { Future(Ok("No Versus Service")) } - } //current.plugin[VersusPlugin] match + } //current.plugin[VersusPlugin] match } //case Some((inputStream... case None => { @@ -181,7 +181,7 @@ class Search @Inject() ( } //convert list of futures into a Future[list] scala.concurrent.Future.sequence(resultListOfFutures) - } //End yield- outer for + } //End yield- outer for for { futureListResults <- futureFutureListResults @@ -191,12 +191,12 @@ class Search @Inject() ( val thumb_id = files.get(inputFileId).flatMap(_.thumbnail_id).getOrElse("") Ok(views.html.multimediaSearchResults(filename, Some(inputFileId), Some(thumb_id), listOfResults)) } - } //end of case Some(plugin) + } //end of case Some(plugin) case None => { Future(Ok("No Versus Service")) } - } //current.plugin[VersusPlugin] match + } //current.plugin[VersusPlugin] match } //case Some((inputStream... case None => { @@ -211,7 +211,7 @@ class Search @Inject() ( * Returns * boolean: true if errors are present * String: error message - * List[Double] : weights + * List[Double]: weights */ def validateInput(input: Map[String, Seq[String]]): (Boolean, String, List[Double]) = { var inputErrors = false @@ -221,7 +221,7 @@ class Search @Inject() ( inputErrors = true return (inputErrors, "Not all fields are present", List(0.0)) } - //now deal with weights + //now deal with weights try { weightsList = input("Weight").map(w => w.toDouble).toList } catch { @@ -235,7 +235,7 @@ class Search @Inject() ( } if (sum != 1) return (true, "sum of weights must be 1", List(0.0)) - //no errors, return list of weights + //no errors, return list of weights (false, "", weightsList) } @@ -258,7 +258,7 @@ class Search @Inject() ( val nonzeroWeights = nonzeroWeightsBuf.toList val nonzeroMaps = nonzeroMapsBuf.toList - //If after removing zero-weight maps we have just one map left - nothing to merge, return the map. + //If after removing zero-weight maps we have just one map left - nothing to merge, return the map. //Otherwise, merge maps. if (nonzeroMaps.length == 1) { nonzeroMaps(0) @@ -274,7 +274,7 @@ class Search @Inject() ( } /** * For two maps and two corresponding weights, will find linear combinations of corresponding values, - * using the weights provided + * using the weights provided */ def mergeTwoMaps(mapOne: collection.immutable.HashMap[String, Double], mapTwo: collection.immutable.HashMap[String, Double], @@ -305,7 +305,7 @@ class Search @Inject() ( val filename = fileInfo._2 current.plugin[VersusPlugin] match { case Some(plugin) => { - //get file and a list of indexes from request, query this file against each of these indexes + //get file and a list of indexes from request, query this file against each of these indexes val queryResults = indexIDs.map(indId => plugin.queryIndexSorted(fileId.stringify, indId.stringify)) //change a list of futures into a future list val futureListResults = scala.concurrent.Future.sequence(queryResults) @@ -334,19 +334,19 @@ class Search @Inject() ( //get an option of thumbnail id for this image and pass on to view val thumb_id = queries.getFile(fileId).flatMap(_.thumbnail_id) Ok(views.html.multimediaSearchResultsCombined(filename, thumb_id, sortedMergedResults)) - } //end of yield - } //end of case Some(plugin) + } //end of yield + } //end of case Some(plugin) case None => { Future(Ok("No Versus Service")) } - } //current.plugin[VersusPlugin] match + } //current.plugin[VersusPlugin] match } //case Some((inputStream... case None => { Logger.debug("File with id " + fileId + " not found") Future(Ok("File with id " + fileId + " not found")) } - } //end of queries.get(imageID) match + } //end of queries.get(imageID) match } //end of if no validation errors else { Future(Ok("Form validation errors: " + errorMessage)) } } diff --git a/app/controllers/Selected.scala b/app/controllers/Selected.scala index c494b568a..6c1014fca 100644 --- a/app/controllers/Selected.scala +++ b/app/controllers/Selected.scala @@ -15,10 +15,10 @@ class Selected @Inject()(selections: SelectionService, files: FileService) exten request.user match { case Some(identity) => { implicit val user = request.user - val datasets = selections.get(request.user.get.email.get) // TODO handle edge cases - Ok(views.html.selected(datasets.to[scala.collection.mutable.ListBuffer])) + val datasets = selections.get(request.user.get.email.get) // TODO handle edge cases + Ok(views.html.selected(datasets.to[scala.collection.mutable.ListBuffer])) } case None => Logger.error("Error get user from request"); InternalServerError } } -} \ No newline at end of file +} diff --git a/app/controllers/Spaces.scala b/app/controllers/Spaces.scala index ca4cd1832..11876441a 100644 --- a/app/controllers/Spaces.scala +++ b/app/controllers/Spaces.scala @@ -194,7 +194,7 @@ class Spaces @Inject() (spaces: SpaceService, users: UserService, events: EventS if (user.isDefined) selections.get(user.get.identityId.userId).map(_.id.stringify) else List.empty[String] Logger.debug("User selection " + userSelections) - + val rs = play.api.Play.current.plugin[services.StagingAreaPlugin] match { case Some(plugin) => Publications.getPublications(s.id.toString, spaces) case None => List.empty diff --git a/app/controllers/ToolManager.scala b/app/controllers/ToolManager.scala index 3dcd5586a..7bb022527 100644 --- a/app/controllers/ToolManager.scala +++ b/app/controllers/ToolManager.scala @@ -147,4 +147,4 @@ class ToolManager extends SecuredController { case None => BadRequest("No ToolManagerPlugin found.") } } -} \ No newline at end of file +} diff --git a/app/controllers/Users.scala b/app/controllers/Users.scala index acd0a2cf1..68f3e743f 100644 --- a/app/controllers/Users.scala +++ b/app/controllers/Users.scala @@ -38,9 +38,9 @@ class Users @Inject() (users: UserService, appConfig: AppConfigurationService) e val onHandleStartSignUpGoTo = securesocial.controllers.Registration.onHandleStartSignUpGoTo val Success = securesocial.controllers.Registration.Success val ThankYouCheckEmail = securesocial.core.providers.utils.Mailer.SignUpEmailSubject - + val SignUpEmailSubject = "mails.sendSignUpEmail.subject" - + val Email = "email" val startForm = Form ( Email -> email.verifying(Constraint[String] { @@ -76,9 +76,9 @@ class Users @Inject() (users: UserService, appConfig: AppConfigurationService) e case Some(clowderUser) => { var followedUsers: List[(models.UUID, String, String, String)] = List.empty val userIds = clowderUser.followedEntities.filter(_.objectType == "user") - val userIdsToUse = userIds.slice(index*limit, (index+1)*limit) - val prev = index -1 - val next = if(userIds.length > (index+1) * limit) { + val userIdsToUse = userIds.slice(index*limit, (index + 1) * limit) + val prev = index - 1 + val next = if(userIds.length > (index + 1) * limit) { index + 1 } else { -1 @@ -152,9 +152,9 @@ class Users @Inject() (users: UserService, appConfig: AppConfigurationService) e user match { case Some(clowderUser) => { var followers: List[(models.UUID, String, String, String)] = List.empty - val followersToUse = clowderUser.followers.slice(index*limit, (index+1)*limit) - val prev = index-1 - val next = if(clowderUser.followers.length > (index+1) * limit) { + val followersToUse = clowderUser.followers.slice(index*limit, (index + 1) * limit) + val prev = index - 1 + val next = if(clowderUser.followers.length > (index + 1) * limit) { index + 1 } else { -1 @@ -190,6 +190,6 @@ class Users @Inject() (users: UserService, appConfig: AppConfigurationService) e def sendEmail(subject: String, from: String, recipient: String, body: String) = AuthenticatedAction { implicit request => util.Mail.sendEmail(subject, from, List(recipient), Html(body)) - Ok("Successfully emailed "+recipient) + Ok("Successfully emailed " + recipient) } } diff --git a/app/controllers/Utils.scala b/app/controllers/Utils.scala index f759e97d0..df8ae85d8 100644 --- a/app/controllers/Utils.scala +++ b/app/controllers/Utils.scala @@ -106,12 +106,12 @@ object Utils { /** * Utility method to modify the elements in a collection that are encoded when submitted and stored. These elements * are decoded when a view requests the objects, so that they can be human readable. - * + * * Currently, the following collection elements are encoded: - * + * * name * description - * + * */ def decodeCollectionElements(collection: Collection) : Collection = { val updatedName = updateEncodedTextNewlines(collection.name) @@ -167,4 +167,4 @@ object Utils { decodedReplies.toList } } -} \ No newline at end of file +} diff --git a/app/filters/CORSFilter.scala b/app/filters/CORSFilter.scala index cddbaa4bd..e6a77eec4 100644 --- a/app/filters/CORSFilter.scala +++ b/app/filters/CORSFilter.scala @@ -41,4 +41,4 @@ case class CORSFilter() extends Filter{ )} } } -} \ No newline at end of file +} diff --git a/app/models/ContextLD.scala b/app/models/ContextLD.scala index de4ceda25..042586a1b 100644 --- a/app/models/ContextLD.scala +++ b/app/models/ContextLD.scala @@ -12,9 +12,5 @@ import play.api.libs.json.JsString case class ContextLD( id: UUID = UUID.generate, contextName: JsString, //e.g. ncsa.cv.face.jsonld or some user id .jsonld - context: JsValue) - - - - - + context: JsValue +) diff --git a/app/models/CurationObject.scala b/app/models/CurationObject.scala index a2851ae1d..cb36970ac 100644 --- a/app/models/CurationObject.scala +++ b/app/models/CurationObject.scala @@ -164,4 +164,4 @@ case class CurationFolder( folders: List[UUID] = List.empty, parentId: UUID, parentType: String, - parentCurationObjectId: UUID) \ No newline at end of file + parentCurationObjectId: UUID) diff --git a/app/models/DBCounts.scala b/app/models/DBCounts.scala index 22a7d98f3..a6f2d730e 100644 --- a/app/models/DBCounts.scala +++ b/app/models/DBCounts.scala @@ -14,4 +14,4 @@ case class DBCounts(numDatasets: Long=0, numFiles: Long=0, numBytes: Long=0, num "users"->numUsers ) } -} \ No newline at end of file +} diff --git a/app/models/Dataset.scala b/app/models/Dataset.scala index 11953197c..25b36ae5a 100644 --- a/app/models/Dataset.scala +++ b/app/models/Dataset.scala @@ -72,4 +72,4 @@ case class DatasetAccess( showAccess: Boolean = false, access: String = "N/A", accessOptions: List[String] = List.empty -) \ No newline at end of file +) diff --git a/app/models/Event.scala b/app/models/Event.scala index 65dfd479b..e8807023c 100644 --- a/app/models/Event.scala +++ b/app/models/Event.scala @@ -15,14 +15,14 @@ import services.DI */ case class Event( - user: MiniUser, + user: MiniUser, targetuser : Option[MiniUser] = None, - object_id: Option[UUID] = None, - object_name: Option[String] = None, - source_id: Option[UUID] = None, - source_name: Option[String] = None, - event_type: String, - created: Date = new Date() + object_id: Option[UUID] = None, + object_name: Option[String] = None, + source_id: Option[UUID] = None, + source_name: Option[String] = None, + event_type: String, + created: Date = new Date() ) @@ -51,9 +51,9 @@ import services.DI * * addMetadata_dataset => "user added metadata to dataset: object_name" * addMetadata_file => "user added metadata to file: object_name" - * - * update_dataset_information => "user updated dataset infomration for object_name" - * + * + * update_dataset_information => "user updated dataset information for object_name" + * * (when working with comments object_name holds comment text, object_id has UUID of comment) * comment_file => "user commented object_name on file: source_name" * add_comment_dataset => "user commented object_name on dataset: source_name" @@ -61,7 +61,7 @@ import services.DI * * set_note_file => "user set the note on object_name" * - * download_file => "user downladed object_name" (not working) + * download_file => "user downloaded object_name" (not working) * * tos_update => "Terms of Service were updated" * @@ -76,8 +76,8 @@ import services.DI */ object Events { - val scheduler: SchedulerService = DI.injector.getInstance(classOf[SchedulerService]) - val users: UserService = DI.injector.getInstance(classOf[UserService]) + val scheduler: SchedulerService = DI.injector.getInstance(classOf[SchedulerService]) + val users: UserService = DI.injector.getInstance(classOf[UserService]) val events: EventService = DI.injector.getInstance(classOf[EventService]) /** @@ -164,4 +164,4 @@ object EventType extends Enumeration { val SET_NOTE_FILE = Value("set_note_file") val DOWNLOAD_FILE = Value("download_file") val TOS_UPDATE = Value("tos_update") -} \ No newline at end of file +} diff --git a/app/models/ExtractionInfoSetUp.scala b/app/models/ExtractionInfoSetUp.scala index 13b648a96..46c48a53c 100644 --- a/app/models/ExtractionInfoSetUp.scala +++ b/app/models/ExtractionInfoSetUp.scala @@ -22,10 +22,10 @@ val dtsrequests:ExtractionRequestsService=DI.injector.getInstance(classOf[Extrac /* * Updates DTS extraction request - * + * */ def updateDTSRequests(file_id:UUID,extractor_id:String)={ - + dtsrequests.updateRequest(file_id,extractor_id) } @@ -91,10 +91,10 @@ def updateDTSRequests(file_id:UUID,extractor_id:String)={ } //end of outer yield qDetails Future status }//end of updateAndGetStatus method - + /** * Obtains the queues' names attached to an exchange where source is the exchange and destination is the queue - */ + */ def getQDetailsFutures(plugin: services.RabbitmqPlugin, exchange: String) = { for { qNamesResponse <- plugin.getQueuesNamesForAnExchange(exchange) @@ -119,9 +119,9 @@ def updateDTSRequests(file_id:UUID,extractor_id:String)={ qdetailsFutureList } //end of yield qNamesResponse } - + /** - * updates : extractors details + * updates : extractors details * currently running extractors list * servers IPs where extractors are running */ @@ -170,7 +170,7 @@ def updateDTSRequests(file_id:UUID,extractor_id:String)={ else { "" } - } //end of for + } //end of for extractors.insertServerIPs(ipsList) extractors.insertExtractorDetail(exDetails) qlistResult @@ -195,9 +195,9 @@ def updateDTSRequests(file_id:UUID,extractor_id:String)={ routingKeysList } } - + /** - * Get all exchanges for a given virtual host + * Get all exchanges for a given virtual host * TODO : It will be used for multiple exchanges attached to a virtual host in Future */ def getExchangesFutureList(plugin: services.RabbitmqPlugin): Future[List[String]] = { @@ -208,7 +208,7 @@ def updateDTSRequests(file_id:UUID,extractor_id:String)={ var exlist = List[String]() exjsonlist.map { ex => - Logger.trace("internal: " +(ex \"internal")+" name:"+(ex \"name").as[String]) + Logger.trace("internal: " + (ex \"internal") + " name:" + (ex \"name").as[String]) if ((ex \ "internal").as[Boolean] == false) { var name = (ex \ "name").as[String] exlist = name :: exlist diff --git a/app/models/ExtractionRequests.scala b/app/models/ExtractionRequests.scala index 3f729c27f..70090428f 100644 --- a/app/models/ExtractionRequests.scala +++ b/app/models/ExtractionRequests.scala @@ -17,6 +17,4 @@ case class ExtractionRequests( extractors:Option[List[String]], startTime:Option[Date], endTime:Option[Date] - ) - - +) diff --git a/app/models/ExtractorsForInstance.scala b/app/models/ExtractorsForInstance.scala index 2eff31725..bda98a80a 100644 --- a/app/models/ExtractorsForInstance.scala +++ b/app/models/ExtractorsForInstance.scala @@ -5,5 +5,4 @@ package models */ case class ExtractorsForInstance( extractors: List[String] - ) - \ No newline at end of file +) diff --git a/app/models/FileOP.scala b/app/models/FileOP.scala index 5e4ec2f17..20ccf70be 100644 --- a/app/models/FileOP.scala +++ b/app/models/FileOP.scala @@ -9,12 +9,12 @@ import play.api.Logger object FileOP { /** * Returns extracted lists of tags for a file - * + * */ - + val previews: PreviewService=DI.injector.getInstance(classOf[PreviewService]) val files:FileService=DI.injector.getInstance(classOf[FileService]) - + def extractTags(file: models.File) = { val tags = file.tags // Transform the tag list into a list of ["extractor_id" or "userId", "values"] items, @@ -42,11 +42,11 @@ object FileOP { val jtags = jtagsE ++ jtagsU jtags } - - + + /** * Returns Previews extracted so far for a file - * + * */ def extractPreviews(id: UUID) = { val previews1 =previews.findByFileId(id); @@ -54,7 +54,7 @@ object FileOP { // where "values" are the preview properties, such as "preview_id", "url", and "contentType". var previewRes = Map[String, MutableList[JsValue]]() previews1.filter(_.extractor_id.isDefined).foreach(p => { - + val ename = p.extractor_id.get val jitem = Json.obj("preview_id" -> p.id.stringify, "contentType" -> p.contentType, "url" -> api.routes.Previews.download(p.id).toString) @@ -67,5 +67,4 @@ object FileOP { val jpreviews = previewRes.map { case (k, v) => Json.obj("extractor_id" -> k, "values" -> Json.toJson(v)) } jpreviews } - - } \ No newline at end of file +} diff --git a/app/models/IncrementCounter.scala b/app/models/IncrementCounter.scala index cfd5f2cde..8bdb581cb 100644 --- a/app/models/IncrementCounter.scala +++ b/app/models/IncrementCounter.scala @@ -2,4 +2,4 @@ package models class IncrementCounter { var count = 0 -} \ No newline at end of file +} diff --git a/app/models/JobsScheduler.scala b/app/models/JobsScheduler.scala index 8f7bd4eae..bdd0c64a9 100644 --- a/app/models/JobsScheduler.scala +++ b/app/models/JobsScheduler.scala @@ -6,8 +6,8 @@ import services.SchedulerService import services.DI /** - * Schedules Jobs - * + * Schedules Jobs + * */ /** diff --git a/app/models/LicenseData.scala b/app/models/LicenseData.scala index 6434b868c..b96de46e9 100644 --- a/app/models/LicenseData.scala +++ b/app/models/LicenseData.scala @@ -3,7 +3,7 @@ package models import api.Permission /** - * case class to handle specific license information. Currently attached to individual Datasets and Files. + * case class to handle specific license information. Currently attached to individual Datasets and Files. */ case class LicenseData ( id: UUID = UUID.generate(), @@ -19,9 +19,9 @@ case class LicenseData ( /** * Utility method to check if the license allows the file to be downloaded. Currently, if the license type is NOT * "license1", or if it is "license1" and the "allowDownload" flag is set, the file can be downloaded. - * + * * @return A boolean, true if the license type allows the file to be downloaded, false otherwise. - * + * */ def isDownloadAllowed(user: Option[User]) = { (m_licenseType != "license1") || m_allowDownload || Permission.checkPermission(user, Permission.DownloadFiles) || (user match { @@ -32,11 +32,11 @@ case class LicenseData ( /** * Utility method to check if a name matches the rights holder of the license. - * + * * @param aName A String that represents the name of a user to compare to the current rights holder. - * + * * @return A boolean, true if the parameter matches the owner, false otherwise. - * + * */ def isRightsOwner(aName: String) = { m_rightsHolder == aName diff --git a/app/models/Metadata.scala b/app/models/Metadata.scala index 6ce0a393b..f774d192b 100644 --- a/app/models/Metadata.scala +++ b/app/models/Metadata.scala @@ -71,9 +71,9 @@ object Agent { val userService: UserService = DI.injector.getInstance(classOf[UserService]) def reads(json: JsValue) = { - //creator(agent) may be User or Extractor depending on the json + //creator(agent) may be User or Extractor depending on the json var creator: Option[models.Agent] = None - + //parse json input for type of agent val typeOfAgent = (json \ "agent" \ "@type").as[String] @@ -128,7 +128,7 @@ object Metadata { "extractor_id" -> extractor_id_string) } } - + implicit object UserAgentWrites extends Writes[UserAgent] { def writes(user: UserAgent): JsObject = { val user_id_string = user.userId.map(_.toString).getOrElse("") @@ -138,16 +138,16 @@ object Metadata { "user_id" -> user_id_string) } } - + implicit object MetadataWrites extends Writes[Metadata] { - def writes(metadata: Metadata) = Json.obj( - "created_at" -> metadata.createdAt.toString, - //if (i == 1) x else y - //switch based on type of creator/agent and call appropriate class' implicit writes - "agent"-> (if (metadata.creator.isInstanceOf[UserAgent]) metadata.creator.asInstanceOf[UserAgent] else metadata.creator.asInstanceOf[ExtractorAgent]) , - "content" -> metadata.content - ) - } + def writes(metadata: Metadata) = Json.obj( + "created_at" -> metadata.createdAt.toString, + //if (i == 1) x else y + //switch based on type of creator/agent and call appropriate class' implicit writes + "agent"-> (if (metadata.creator.isInstanceOf[UserAgent]) metadata.creator.asInstanceOf[UserAgent] else metadata.creator.asInstanceOf[ExtractorAgent]) , + "content" -> metadata.content + ) + } } @@ -158,7 +158,7 @@ object RDFModel { def reads(json: JsValue) = { var model: Option[models.RDFModel] = None var in: java.io.InputStream = new java.io.ByteArrayInputStream( Json.stringify(json).getBytes ) - + // Parse JSON-LD var m: Model = ModelFactory.createDefaultModel() var error: String = null @@ -175,6 +175,6 @@ object RDFModel { case None => JsError(ValidationError("Parse succeeded, but JSON-LD RDF model was empty. Try setting a default @vocab in your @context node.")) } } - + } -} \ No newline at end of file +} diff --git a/app/models/PreviewFilesSearchResult.scala b/app/models/PreviewFilesSearchResult.scala index 649749810..eb1e7f646 100644 --- a/app/models/PreviewFilesSearchResult.scala +++ b/app/models/PreviewFilesSearchResult.scala @@ -2,9 +2,9 @@ * Previewers and Files Search Resutls. * Used by multimedia search to pass information * between controller and viewer. - * + * * Specifically, used by VersusPlugin, Search, ContentBasedSearchResultsVideo3 - * + * * Searching through files (born as still images) and video previews * (first shot of each frame of the video) * @@ -14,8 +14,7 @@ package models case class PreviewFilesSearchResult( - fileOrPreview:String, + fileOrPreview:String, searchResultFile: SearchResultFile, - searchResultPreview: SearchResultPreview + searchResultPreview: SearchResultPreview ) - diff --git a/app/models/RequestResource.scala b/app/models/RequestResource.scala index c5950247c..a13bce4a4 100644 --- a/app/models/RequestResource.scala +++ b/app/models/RequestResource.scala @@ -13,4 +13,4 @@ comment: String = "N/A"){ case that: RequestResource => that.id.equals(this.id) case _ => false } -} \ No newline at end of file +} diff --git a/app/models/Role.scala b/app/models/Role.scala index 52df9136d..93c4b83b6 100644 --- a/app/models/Role.scala +++ b/app/models/Role.scala @@ -24,4 +24,4 @@ object Role { // viewer role val viewerPerm = Permission.READONLY val Viewer = new Role(name="Viewer", description="Viewer Role", permissions = viewerPerm.map(_.toString)) -} \ No newline at end of file +} diff --git a/app/models/Section.scala b/app/models/Section.scala index c1793a1ed..141eb5c68 100644 --- a/app/models/Section.scala +++ b/app/models/Section.scala @@ -25,4 +25,4 @@ case class Rectangle( w: Double, h: Double) { override def toString() = f"x: $x%.2f, y: $y%.2f, width: $w%.2f, height: $h%.2f" -} \ No newline at end of file +} diff --git a/app/models/SectionIndexInfo.scala b/app/models/SectionIndexInfo.scala index 3829d781e..4e7bdb54e 100644 --- a/app/models/SectionIndexInfo.scala +++ b/app/models/SectionIndexInfo.scala @@ -6,7 +6,7 @@ package models * */ case class SectionIndexInfo( - indexId:String, + indexId:String, indexName:Option[String] = None, indexType: Option[String] = None - ) \ No newline at end of file + ) diff --git a/app/models/Selected.scala b/app/models/Selected.scala index 59d5560ac..e5d143125 100644 --- a/app/models/Selected.scala +++ b/app/models/Selected.scala @@ -18,5 +18,4 @@ case class Selected ( id: ObjectId = new ObjectId, user: String, datasets: List[String] = List.empty - ) - +) diff --git a/app/models/ServerStartTime.scala b/app/models/ServerStartTime.scala index 15d02a0d9..cd6e3fb76 100644 --- a/app/models/ServerStartTime.scala +++ b/app/models/ServerStartTime.scala @@ -10,4 +10,4 @@ import java.util.Date object ServerStartTime { var startTime: Date=null -} \ No newline at end of file +} diff --git a/app/models/Space.scala b/app/models/Space.scala index 0e0df7079..fe71807a9 100644 --- a/app/models/Space.scala +++ b/app/models/Space.scala @@ -62,7 +62,7 @@ case class SpaceInvite( role: String, creationTime: java.util.Date, expirationTime: java.util.Date) - + // New way to manage metadata. Will eventually be merged with space metadata. case class SpaceMetadata ( created: Date, diff --git a/app/models/StandardVocab.scala b/app/models/StandardVocab.scala index cad582197..c9d9b1a6b 100644 --- a/app/models/StandardVocab.scala +++ b/app/models/StandardVocab.scala @@ -22,4 +22,4 @@ object StandardVocab{ "terms" -> vocabulary.terms.toList) } } -} \ No newline at end of file +} diff --git a/app/models/TempFile.scala b/app/models/TempFile.scala index b8a7b8c4c..867efbf10 100644 --- a/app/models/TempFile.scala +++ b/app/models/TempFile.scala @@ -17,4 +17,4 @@ case class TempFile( contentType: String, length: Long = 0, thumbnail_id: Option[UUID] = None - ) \ No newline at end of file + ) diff --git a/app/models/User.scala b/app/models/User.scala index 3564e5253..e31c3cd73 100644 --- a/app/models/User.scala +++ b/app/models/User.scala @@ -10,10 +10,9 @@ import securesocial.core._ import services.AppConfiguration object UserStatus extends Enumeration { - type UserStatus = Value - val Inactive, Active, Admin = Value - } - + type UserStatus = Value + val Inactive, Active, Admin = Value + } /** * Simple class to capture basic User Information. This is similar to Identity in securesocial * @@ -127,7 +126,7 @@ case class ClowderUser( // should user be active status: UserStatus.Value = UserStatus.Inactive, - + // has the user escalated privileges, this is never saved to the database @transient superAdminMode: Boolean = false, @@ -152,7 +151,7 @@ case class ClowderUser( termsOfServices: Option[UserTermsOfServices] = None, lastLogin: Option[Date] = None - + ) extends User case class Profile( diff --git a/app/models/UserSpaceAndRole.scala b/app/models/UserSpaceAndRole.scala index 76d254c59..edc5249ca 100644 --- a/app/models/UserSpaceAndRole.scala +++ b/app/models/UserSpaceAndRole.scala @@ -1,10 +1,10 @@ package models /** - * Elements here are initialized to null since they should always be defined, and if they are not, + * Elements here are initialized to null since they should always be defined, and if they are not, * then it is an exception case. */ case class UserSpaceAndRole ( spaceId: UUID = null, role: Role = null // TODO replace with UUID -) \ No newline at end of file +) diff --git a/app/models/VersusExtraction.scala b/app/models/VersusExtraction.scala index 60f198246..0bd2dadab 100644 --- a/app/models/VersusExtraction.scala +++ b/app/models/VersusExtraction.scala @@ -9,24 +9,14 @@ import play.api.libs.json.JsResult * */ object VersusExtraction { - case class VersusExtraction(val extraction_id: String, val adapter_name:String, val extractor_name:String, val descriptor:String ) - - implicit object VersusExtraction extends Reads[VersusExtraction] { def reads(json: JsValue) ={ - val ex_id:String = (json \"extractor_id").as[String] val a_name:String=(json \"adapter_name").as[String] val ex_name:String=(json \"extractor_name").as[String] val des:String=(json \"descriptor").as[String] - JsSuccess(VersusExtraction(ex_id,a_name,ex_name,des)) - } - - } - - - -} \ No newline at end of file + } +} diff --git a/app/models/VersusIndex.scala b/app/models/VersusIndex.scala index ae92b2518..2fba4f043 100644 --- a/app/models/VersusIndex.scala +++ b/app/models/VersusIndex.scala @@ -8,39 +8,38 @@ import play.api.libs.json.Reads import play.api.libs.json.JsSuccess import play.api.libs.json.JsResult -case class VersusIndex( - val id :String, - val MIMEtype :String, - val extractorID:String, - val measureID:String, +case class VersusIndex( + val id :String, + val MIMEtype :String, + val extractorID:String, + val measureID:String, val indexerType:String - ) - -object VersusIndex { +) +object VersusIndex { /** * Serializer for VersusIndex type. - */ - implicit object VersusIndexWrites extends Writes[VersusIndex] { - def writes(index: VersusIndex) = Json.obj( - "id" -> index.id, - "mimetype" -> index.MIMEtype, - "extr"->index.extractorID, - "measure"->index.measureID, - "typeOfIndexer"->index.indexerType - ) - } - - /** - * Deserializer for VersusIndex type. - */ - implicit object VersusIndexReads extends Reads[VersusIndex] { - def reads(json: JsValue) ={ - val maybeID:String = (json \"indexID").as[String] - val maybeMimeType:String=(json\"MIMEtype").as[String] - val exType:String=(json\"Extractor").as[String] - val meType:String=(json\"Measure").as[String] - val indxrType:String=(json\"Indexer").as[String] - JsSuccess(VersusIndex(maybeID,maybeMimeType,exType,meType,indxrType)) - } - } -} \ No newline at end of file + */ + implicit object VersusIndexWrites extends Writes[VersusIndex] { + def writes(index: VersusIndex) = Json.obj( + "id" -> index.id, + "mimetype" -> index.MIMEtype, + "extr"->index.extractorID, + "measure"->index.measureID, + "typeOfIndexer"->index.indexerType + ) + } + + /** + * Deserializer for VersusIndex type. + */ + implicit object VersusIndexReads extends Reads[VersusIndex] { + def reads(json: JsValue) ={ + val maybeID:String = (json \"indexID").as[String] + val maybeMimeType:String=(json\"MIMEtype").as[String] + val exType:String=(json\"Extractor").as[String] + val meType:String=(json\"Measure").as[String] + val indxrType:String=(json\"Indexer").as[String] + JsSuccess(VersusIndex(maybeID,maybeMimeType,exType,meType,indxrType)) + } + } +} diff --git a/app/models/VersusIndexTypeName.scala b/app/models/VersusIndexTypeName.scala index af753d39d..9ccff6cb5 100644 --- a/app/models/VersusIndexTypeName.scala +++ b/app/models/VersusIndexTypeName.scala @@ -9,14 +9,14 @@ import play.api.libs.json.Json //names of the variables here MUST be the same as in versus IndexResource.listJSON, where the Json is created. case class VersusIndexTypeName( - indexID: String, - MIMEtype:String, - Extractor: String, - Measure:String, - Indexer:String, - indexName: Option[String], + indexID: String, + MIMEtype:String, + Extractor: String, + Measure:String, + Indexer:String, + indexName: Option[String], indexType:Option[String] - ) +) object VersusIndexTypeName { implicit val format: Format[VersusIndexTypeName] = Json.format[VersusIndexTypeName] @@ -24,12 +24,12 @@ object VersusIndexTypeName { def addName(index: VersusIndexTypeName, indName:String): VersusIndexTypeName = { index.copy(indexName = Some(indName)) } - + def addType(index: VersusIndexTypeName, indType:String): VersusIndexTypeName = { index.copy(indexType = Some(indType)) } - + def addTypeAndName(index: VersusIndexTypeName, indType:String, indName:String): VersusIndexTypeName = { index.copy(indexType = Some(indType), indexName = Some(indName)) } -} \ No newline at end of file +} diff --git a/app/models/WebPageResource.scala b/app/models/WebPageResource.scala index f28b1d332..2e4cf6ee4 100644 --- a/app/models/WebPageResource.scala +++ b/app/models/WebPageResource.scala @@ -4,10 +4,10 @@ package models * Web page URL and (file URLs in that specific web page, UUIDs for those file saved in database) * This is used for DTS service * - * + * */ case class WebPageResource( id: UUID, webPageURL:String, URLs: Map[String,String] -) \ No newline at end of file +) diff --git a/app/services/AdminsNotifierPlugin.scala b/app/services/AdminsNotifierPlugin.scala index 223aa9a7d..0014b4738 100644 --- a/app/services/AdminsNotifierPlugin.scala +++ b/app/services/AdminsNotifierPlugin.scala @@ -19,7 +19,7 @@ class AdminsNotifierPlugin @Inject()(userService: UserService) (application:Appl override lazy val enabled = { !application.configuration.getString("adminnotifierservice").filter(_ == "disabled").isDefined } - + def sendAdminsNotification(baseURL: String, resourceType: String = "Dataset", eventType: String = "added", resourceId: String, resourceName: String) = { @@ -31,7 +31,7 @@ class AdminsNotifierPlugin @Inject()(userService: UserService) (application:Appl } else if(resourceType.equals("Collection")){ baseURL + controllers.routes.Collections.collection(UUID(resourceId)) } - + resourceUrl match{ case "" => { Logger.error("Unknown resource type.") @@ -45,12 +45,12 @@ class AdminsNotifierPlugin @Inject()(userService: UserService) (application:Appl mailHTML match { case "" => { - Logger.error("Unknown event type.") + Logger.error("Unknown event type.") } case _=> { Mail.sendEmailAdmins(mailSubject, None, Html(mailHTML)) } - } + } } } } diff --git a/app/services/CollectionService.scala b/app/services/CollectionService.scala index 8eef9991e..d3b79b391 100644 --- a/app/services/CollectionService.scala +++ b/app/services/CollectionService.scala @@ -104,12 +104,12 @@ trait CollectionService { */ def listUser(date: String, nextPage: Boolean, limit: Integer, title: String, user: Option[User], showAll: Boolean, owner: User, exact: Boolean): List[Collection] - + /** * Return a list of collections the user has access to starting at a specific date with matching title. */ def listSpaceAccess(limit: Integer, space: String, permissions: Set[Permission], user: Option[User], showAll: Boolean, showPublic: Boolean): List[Collection] - + /** * List All Collections (Including childs) a user can view. */ diff --git a/app/services/CommentService.scala b/app/services/CommentService.scala index 67cbbdcb7..3cec8f806 100644 --- a/app/services/CommentService.scala +++ b/app/services/CommentService.scala @@ -22,23 +22,23 @@ trait CommentService { def findCommentsBySectionId(id: UUID): List[Comment] def removeComment(c: Comment) - + /** * Service provided to actually edit a specific comment by id. - * + * * id: The identifier of the comment to edit, as a UUID. * commentText: The data to replace the comment text with, as a String. */ def editComment(id: UUID, commentText: String) - + /** * Remove a comment by its identifier. - * + * * id: The identifier of the comment to remove, as a UUID. */ def removeComment(id: UUID) def updateAuthorFullName(userId: UUID, fullName: String) - + } diff --git a/app/services/ContextLDService.scala b/app/services/ContextLDService.scala index ca6e8dabb..d56005b0f 100644 --- a/app/services/ContextLDService.scala +++ b/app/services/ContextLDService.scala @@ -26,5 +26,4 @@ trait ContextLDService { /** Update context **/ def updateContext(context: ContextLD) - -} \ No newline at end of file +} diff --git a/app/services/CrowdProvider.scala b/app/services/CrowdProvider.scala index a1797d965..3be0deedd 100644 --- a/app/services/CrowdProvider.scala +++ b/app/services/CrowdProvider.scala @@ -79,4 +79,4 @@ object CrowdProvider { private val CrowdServerURL = "securesocial.crowd.url" // time token is alive for private val CrowdServerTimeOut = "securesocial.crowd.timeout" -} \ No newline at end of file +} diff --git a/app/services/DatasetService.scala b/app/services/DatasetService.scala index ac7498ff4..0ba31a68f 100644 --- a/app/services/DatasetService.scala +++ b/app/services/DatasetService.scala @@ -203,7 +203,7 @@ trait DatasetService { def modifyRDFOfMetadataChangedDatasets() def dumpAllDatasetGroupings(): List[String] - + def dumpAllDatasetMetadata(): List[String] def modifyRDFUserMetadata(id: UUID, mappingNumber: String="1") @@ -365,17 +365,17 @@ trait DatasetService { * Remove follower from a dataset. */ def removeFollower(id: UUID, userId: UUID) - + /** * Add a creator to the end of the dataset's list of creators */ def addCreator(id: UUID, creator: String) - + /** * Remove a creator from the dataset's list of creators */ def removeCreator(id: UUID, creator: String) - + /** * Move a creator to a new position in the dataset's list of creators */ diff --git a/app/services/DatasetsAutodumpService.scala b/app/services/DatasetsAutodumpService.scala index 66fb1efb5..d9f6c71a3 100644 --- a/app/services/DatasetsAutodumpService.scala +++ b/app/services/DatasetsAutodumpService.scala @@ -11,16 +11,16 @@ import play.api.libs.concurrent.Execution.Implicits._ class DatasetsAutodumpService (application: Application) extends Plugin { val datasets: DatasetService = DI.injector.getInstance(classOf[DatasetService]) - + override def onStart() { Logger.debug("Starting dataset file groupings autodumper Plugin") //Dump dataset file groupings periodically - val timeInterval = play.Play.application().configuration().getInt("datasetdump.dumpEvery") - Akka.system().scheduler.schedule(0.days, timeInterval.intValue().days){ - dumpDatasetGroupings - } + val timeInterval = play.Play.application().configuration().getInt("datasetdump.dumpEvery") + Akka.system().scheduler.schedule(0.days, timeInterval.intValue().days){ + dumpDatasetGroupings + } } - + override def onStop() { Logger.debug("Shutting down dataset file groupings autodumper Plugin") } @@ -28,9 +28,9 @@ class DatasetsAutodumpService (application: Application) extends Plugin { override lazy val enabled = { !application.configuration.getString("datasetsdumpservice").filter(_ == "disabled").isDefined } - + def dumpDatasetGroupings() = { - + val unsuccessfulDumps = datasets.dumpAllDatasetGroupings if(unsuccessfulDumps.size == 0) Logger.debug("Dumping of dataset file groupings was successful for all datasets.") @@ -41,7 +41,6 @@ class DatasetsAutodumpService (application: Application) extends Plugin { } unsuccessfulMessage = unsuccessfulMessage.substring(0, unsuccessfulMessage.length()-2) + "." Logger.debug(unsuccessfulMessage) - } + } } - -} \ No newline at end of file +} diff --git a/app/services/DatasetsMetadataAutodumpService.scala b/app/services/DatasetsMetadataAutodumpService.scala index 26d9052ab..9cb2654b4 100644 --- a/app/services/DatasetsMetadataAutodumpService.scala +++ b/app/services/DatasetsMetadataAutodumpService.scala @@ -12,16 +12,16 @@ import play.api.libs.concurrent.Execution.Implicits._ class DatasetsMetadataAutodumpService (application: Application) extends Plugin { val datasets: DatasetService = DI.injector.getInstance(classOf[DatasetService]) - + override def onStart() { Logger.debug("Starting dataset metadata autodumper Plugin") //Dump metadata of all datasets periodically - val timeInterval = play.Play.application().configuration().getInt("datasetmetadatadump.dumpEvery") - Akka.system().scheduler.schedule(0.days, timeInterval.intValue().days){ - dumpAllDatasetMetadata - } + val timeInterval = play.Play.application().configuration().getInt("datasetmetadatadump.dumpEvery") + Akka.system().scheduler.schedule(0.days, timeInterval.intValue().days){ + dumpAllDatasetMetadata + } } - + override def onStop() { Logger.debug("Shutting down dataset metadata autodumper Plugin") } @@ -29,7 +29,7 @@ class DatasetsMetadataAutodumpService (application: Application) extends Plugin override lazy val enabled = { !application.configuration.getString("datasetmetadatadumpservice").filter(_ == "disabled").isDefined } - + def dumpAllDatasetMetadata() = { val unsuccessfulDumps = datasets.dumpAllDatasetMetadata if(unsuccessfulDumps.size == 0) @@ -41,8 +41,7 @@ class DatasetsMetadataAutodumpService (application: Application) extends Plugin } unsuccessfulMessage = unsuccessfulMessage.substring(0, unsuccessfulMessage.length()-2) + "." Logger.debug(unsuccessfulMessage) - } - + } + } - -} \ No newline at end of file +} diff --git a/app/services/ElasticsearchPlugin.scala b/app/services/ElasticsearchPlugin.scala index 62358d9fb..582fa08eb 100644 --- a/app/services/ElasticsearchPlugin.scala +++ b/app/services/ElasticsearchPlugin.scala @@ -138,41 +138,41 @@ class ElasticsearchPlugin(application: Application) extends Plugin { // whether to restrict to a particular metadata field, or search all fields (including tags, name, etc.) val mdfield = field match { - case Some(k) => expanded_query = " "+k+":\""+expanded_query+"\"" + case Some(k) => expanded_query = " " + k + ":\"" + expanded_query + "\"" case None => {} } // Restrict to a particular tag - currently requires exact match tag match { - case Some(t) => expanded_query += " tag:"+t + case Some(t) => expanded_query += " tag:" + t case None => {} } // Restrict to particular resource_type if requested resource_type match { - case Some(restype) => expanded_query += " resource_type:"+restype + case Some(restype) => expanded_query += " resource_type:" + restype case None => {} } // Restrict to particular dataset ID (only return files) datasetid match { - case Some(dsid) => expanded_query += " in:"+dsid+" resource_type:file" + case Some(dsid) => expanded_query += " in:" + dsid + " resource_type:file" case None => {} } // Restrict to particular collection ID collectionid match { - case Some(cid) => expanded_query += " in:"+cid + case Some(cid) => expanded_query += " in:" + cid case None => {} } spaceid match { - case Some(spid) => expanded_query += " in:"+spid + case Some(spid) => expanded_query += " in:" + spid case None => {} } folderid match { - case Some(fid) => expanded_query += " in:"+fid + case Some(fid) => expanded_query += " in:" + fid case None => {} } @@ -200,7 +200,7 @@ class ElasticsearchPlugin(application: Application) extends Plugin { Logger.debug(s"Only have ${total_results.length} total results; searching for ${size*2} more from ${new_from}") val (results, total_size) = _search(queryObj, index, Some(new_from), Some(size*2)) Logger.debug(s"Found ${results.length} results with ${total_size} total") - if (results.length == 0 || new_from+results.length == total_size) exhausted = true // No more results to find + if (results.length == 0 || new_from + results.length == total_size) exhausted = true // No more results to find val filtered = checkResultPermissions(results, user) Logger.debug(s"Permission to see ${filtered.length} results") var still_scanning = true @@ -266,7 +266,7 @@ class ElasticsearchPlugin(application: Application) extends Plugin { connect() val response = client match { case Some(x) => { - Logger.info("Searching Elasticsearch: "+queryObj.string()) + Logger.info("Searching Elasticsearch: " + queryObj.string()) var responsePrep = x.prepareSearch(index) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setQuery(queryObj) @@ -290,7 +290,7 @@ class ElasticsearchPlugin(application: Application) extends Plugin { } - /** Create a new index with preconfigured mappgin */ + /** Create a new index with pre-configured mapping */ def createIndex(index: String = nameOfIndex): Unit = { val indexSettings = Settings.settingsBuilder().loadFromSource(jsonBuilder() .startObject() @@ -310,7 +310,7 @@ class ElasticsearchPlugin(application: Application) extends Plugin { client match { case Some(x) => { - Logger.debug("Index \""+index+"\" does not exist; creating now ---") + Logger.debug("Index \"" + index + "\" does not exist; creating now ---") try { x.admin().indices().prepareCreate(index) .setSettings(indexSettings) @@ -533,7 +533,7 @@ class ElasticsearchPlugin(application: Application) extends Plugin { .setSize(0) // Filter to tags on a particular type of resource if given if (resourceType != "") - searcher.setQuery(prepareElasticJsonQuery("resource_type:"+resourceType+"", List.empty)) + searcher.setQuery(prepareElasticJsonQuery("resource_type:" + resourceType + "", List.empty)) else { // Exclude Section tags to avoid double-counting since those are duplicated in File document searcher.setQuery(prepareElasticJsonQuery("resource_type:file|dataset|collection", List.empty)) @@ -641,7 +641,7 @@ class ElasticsearchPlugin(application: Application) extends Plugin { var longKey = (parentKey match { case Some(pk) => { if (pk contains "metadata") - pk+'.'+k + pk + '.' + k else k } case None => k @@ -649,10 +649,10 @@ class ElasticsearchPlugin(application: Application) extends Plugin { // Remove ignored fields ignoredFields.foreach(ig => { - if (longKey.indexOf("."+ig+".") > -1) - longKey = longKey.replace("."+ig+".", ".") - if (longKey.endsWith("."+ig)) - longKey = longKey.stripSuffix("."+ig) + if (longKey.indexOf("." + ig + ".") > -1) + longKey = longKey.replace("." + ig + ".", ".") + if (longKey.endsWith("." + ig)) + longKey = longKey.stripSuffix("." + ig) } ) @@ -847,7 +847,7 @@ class ElasticsearchPlugin(application: Application) extends Plugin { var currterm = "" matches.foreach(mt => { // Determine if the string was a key or value - if (query.contains(mt+":") || query.contains("\""+mt+"\":")) { + if (query.contains(mt + ":") || query.contains("\"" + mt + "\":")) { // Do some user-friendly replacement if (mt == "tag") currterm += "tags:" @@ -856,15 +856,15 @@ class ElasticsearchPlugin(application: Application) extends Plugin { else if (mt == "contains") currterm += "parent_of:" else if (!official_terms.contains(mt)) - currterm += "metadata."+mt+":" + currterm += "metadata." + mt + ":" else - currterm += mt+":" - } else if (query.contains(":"+mt) || query.contains(":\""+mt+"\"")) { + currterm += mt + ":" + } else if (query.contains(":" + mt) || query.contains(":\"" + mt + "\"")) { currterm += mt.toLowerCase() terms += currterm currterm = "" } else { - terms += "_all:"+mt.toLowerCase() + terms += "_all:" + mt.toLowerCase() } }) @@ -876,7 +876,7 @@ class ElasticsearchPlugin(application: Application) extends Plugin { for (operator <- mustOperators) { if (term.contains(operator)) { val key = term.substring(0, term.indexOf(operator)) - val value = term.substring(term.indexOf(operator)+1, term.length) + val value = term.substring(term.indexOf(operator) + 1, term.length) // Only add a MUST object if we have terms to populate it; empty objects break Elasticsearch if (mustOperators.contains(operator) && !populatedMust) { @@ -958,4 +958,4 @@ class ElasticsearchPlugin(application: Application) extends Plugin { Logger.info("ElasticsearchPlugin has stopped") } -} \ No newline at end of file +} diff --git a/app/services/EventService.scala b/app/services/EventService.scala index bd4d474ff..aae1f39c6 100644 --- a/app/services/EventService.scala +++ b/app/services/EventService.scala @@ -10,92 +10,92 @@ import com.novus.salat.dao.SalatMongoCursor * Service definition to interact with Events database. * */ - + trait EventService { - - /** - * Lists all the events - */ - - def listEvents(): List[Event] - - /** - * Adds a general event - */ - - def addEvent(event: Event) - - /** - * Event where only the user is involved - */ - def addUserEvent(user: Option[User], action_type: String) - - /** - * Event where user interacts with one object - */ - def addObjectEvent(user: Option[User], object_id: UUID, object_name: String, action_type: String) - - /** - * Event where the user interacts with 2 objects, etc moving a dataset to a collection - */ - def addSourceEvent(user: Option[User], object_id: UUID, object_name: String, source_id: UUID, source_name: String, action_type: String) - - /** - * Event where 2 user interacts with 1 object, etc request event - */ - def addRequestEvent(user: Option[User], targetuser: User, object_id: UUID, object_name: String, action_type: String) - - /** - * Gets limit number of events from users, collections, datasets, and files and compliles them into 1 list - */ - def getEvents(followedEntities:List[TypedID], limit: Option[Integer]): List[Event] - - /** - * Gets all users for a specific list and specific type: object or source - */ - - def getEventsOfType(following: List[UUID], id_type: String, limit: Option[Integer]): List[Event] - - /** - * Gets all events for one UUID - */ - def getEvents(id: String, id_type: String, limit: Option[Integer]): SalatMongoCursor[Event] - - /** - * Get limit number of events which come after a specificied time - */ - - def getEventsByTime(followedEntities:List[TypedID], time: Date, limit: Option[Integer]): List[Event] - - /** - * Get the latest N events - */ - def getLatestNEventsOfType(n: Int, event_type: Option[String]): List[Event] - - /** - * Get the request event and loginuser is targetuser - */ - def getRequestEvents( targetuser: Option[User], limit: Option[Integer]): List[Event] - - /** - * Get the events by creator - */ - def getEventsByUser( user: User, limit: Option[Integer]): List[Event] - - /** - * Get the comment events - */ - def getCommentEvent( user: User, limit: Option[Integer]): List[Event] - - /** - * Update the object name - */ - def updateObjectName(id:UUID, name:String) - - /** - * Update user fullname + + /** + * Lists all the events + */ + + def listEvents(): List[Event] + + /** + * Adds a general event + */ + + def addEvent(event: Event) + + /** + * Event where only the user is involved + */ + def addUserEvent(user: Option[User], action_type: String) + + /** + * Event where user interacts with one object + */ + def addObjectEvent(user: Option[User], object_id: UUID, object_name: String, action_type: String) + + /** + * Event where the user interacts with 2 objects, etc moving a dataset to a collection + */ + def addSourceEvent(user: Option[User], object_id: UUID, object_name: String, source_id: UUID, source_name: String, action_type: String) + + /** + * Event where 2 user interacts with 1 object, etc request event + */ + def addRequestEvent(user: Option[User], targetuser: User, object_id: UUID, object_name: String, action_type: String) + + /** + * Gets limit number of events from users, collections, datasets, and files and compliles them into 1 list + */ + def getEvents(followedEntities:List[TypedID], limit: Option[Integer]): List[Event] + + /** + * Gets all users for a specific list and specific type: object or source + */ + + def getEventsOfType(following: List[UUID], id_type: String, limit: Option[Integer]): List[Event] + + /** + * Gets all events for one UUID + */ + def getEvents(id: String, id_type: String, limit: Option[Integer]): SalatMongoCursor[Event] + + /** + * Get limit number of events which come after a specificied time + */ + + def getEventsByTime(followedEntities:List[TypedID], time: Date, limit: Option[Integer]): List[Event] + + /** + * Get the latest N events + */ + def getLatestNEventsOfType(n: Int, event_type: Option[String]): List[Event] + + /** + * Get the request event and loginuser is targetuser + */ + def getRequestEvents( targetuser: Option[User], limit: Option[Integer]): List[Event] + + /** + * Get the events by creator + */ + def getEventsByUser( user: User, limit: Option[Integer]): List[Event] + + /** + * Get the comment events + */ + def getCommentEvent( user: User, limit: Option[Integer]): List[Event] + + /** + * Update the object name + */ + def updateObjectName(id:UUID, name:String) + + /** + * Update user fullname */ - def updateAuthorFullName(userId: UUID, fullName: String) + def updateAuthorFullName(userId: UUID, fullName: String) } diff --git a/app/services/ExtractionRequestsService.scala b/app/services/ExtractionRequestsService.scala index 880eb1dd3..740e2975d 100644 --- a/app/services/ExtractionRequestsService.scala +++ b/app/services/ExtractionRequestsService.scala @@ -6,10 +6,10 @@ import models._ * */ trait ExtractionRequestsService { - - def insertRequest(serverIP:String,clientIP:String,filename:String,fileid:UUID,fileType:String,filesize:Long, uploadDate:Date) - + + def insertRequest(serverIP:String,clientIP:String,filename:String,fileid:UUID,fileType:String,filesize:Long, uploadDate:Date) + def updateRequest(file_id:UUID,extractor_id:String) - + def getDTSRequests():List[ExtractionRequests] -} \ No newline at end of file +} diff --git a/app/services/ExtractionService.scala b/app/services/ExtractionService.scala index 03a2b6ec9..f10151d9e 100644 --- a/app/services/ExtractionService.scala +++ b/app/services/ExtractionService.scala @@ -19,13 +19,13 @@ trait ExtractionService { def findById(resource: ResourceRef): List[Extraction] def insert(extraction: Extraction): Option[ObjectId] - + def getExtractorList(fileId:UUID): collection.mutable.Map[String,String] - + def getExtractionTime(fileId:UUID): List[Date] - + def save(webpr: WebPageResource): UUID - + def getWebPageResource(id: UUID): Map[String,String] def groupByType(extraction_list: List[Extraction]): Map[String, ExtractionGroup] diff --git a/app/services/ExtractorService.scala b/app/services/ExtractorService.scala index 7bc1a0436..c511c74f1 100644 --- a/app/services/ExtractorService.scala +++ b/app/services/ExtractorService.scala @@ -8,7 +8,7 @@ import play.api.libs.json.JsValue */ trait ExtractorService { - + def getExtractorServerIPList(): List[String] def disableAllExtractors(): Boolean @@ -18,21 +18,21 @@ trait ExtractorService { def enableExtractor(extractor: String) def getExtractorNames(categories: List[String]): List[String] - + def getExtractorInputTypes(): List[String] - + def insertServerIPs(l: List[String]) - + def insertExtractorNames(names: List[String]) - + def insertInputTypes(inputTypes: List[String]) - + //---Temporary fix for BD-289 def insertExtractorDetail(extractorTuple: List[ExtractorDetail]) - + def getExtractorDetail(): Option[JsValue] //--End of Temporary fix BD-289 - + def dropAllExtractorStatusCollection() def listExtractorsInfo(categories: List[String]): List[ExtractorInfo] @@ -40,4 +40,4 @@ trait ExtractorService { def getExtractorInfo(extractorName: String): Option[ExtractorInfo] def updateExtractorInfo(e: ExtractorInfo): Option[ExtractorInfo] -} \ No newline at end of file +} diff --git a/app/services/FileDumpService.scala b/app/services/FileDumpService.scala index 81a028136..58869a62e 100644 --- a/app/services/FileDumpService.scala +++ b/app/services/FileDumpService.scala @@ -18,18 +18,18 @@ class FileDumpService(application: Application) extends Plugin { Logger.debug("Starting file dumper Plugin") val fileSep = System.getProperty("file.separator") var fileDumpDir = play.api.Play.configuration.getString("filedump.dir").getOrElse("") - if(!fileDumpDir.equals("")){ - if (!fileDumpDir.endsWith(fileSep)) - fileDumpDir = fileDumpDir + fileSep - this.fileDumpDir = Some(fileDumpDir) - - var fileDumpMoveDir = play.api.Play.configuration.getString("filedumpmove.dir").getOrElse("") - if(!fileDumpMoveDir.equals("")){ - if(!fileDumpMoveDir.endsWith(fileSep)) - fileDumpMoveDir = fileDumpMoveDir + fileSep - this.fileDumpMoveDir = Some(fileDumpMoveDir) - } - } + if(!fileDumpDir.equals("")){ + if (!fileDumpDir.endsWith(fileSep)) + fileDumpDir = fileDumpDir + fileSep + this.fileDumpDir = Some(fileDumpDir) + + var fileDumpMoveDir = play.api.Play.configuration.getString("filedumpmove.dir").getOrElse("") + if(!fileDumpMoveDir.equals("")){ + if(!fileDumpMoveDir.endsWith(fileSep)) + fileDumpMoveDir = fileDumpMoveDir + fileSep + this.fileDumpMoveDir = Some(fileDumpMoveDir) + } + } } override def onStop() { @@ -45,25 +45,25 @@ class FileDumpService(application: Application) extends Plugin { fileDumpDir match { case Some(dumpDir) => { val fileSep = System.getProperty("file.separator") - val filePathInDirs = fileDump.fileId.charAt(fileDump.fileId.length()-3)+ fileSep + fileDump.fileId.charAt(fileDump.fileId.length()-2)+fileDump.fileId.charAt(fileDump.fileId.length()-1)+ fileSep + fileDump.fileId + fileSep + fileDump.fileName + val filePathInDirs = fileDump.fileId.charAt(fileDump.fileId.length() - 3) + fileSep + fileDump.fileId.charAt(fileDump.fileId.length() - 2) + fileDump.fileId.charAt(fileDump.fileId.length() - 1) + fileSep + fileDump.fileId + fileSep + fileDump.fileName val fileDumpingDir = dumpDir + filePathInDirs val copiedFile = new File(fileDumpingDir) FileUtils.copyFile(fileDump.fileToDump, copiedFile) - + fileDumpMoveDir match { case Some(dumpMoveDir) => { val fileDumpingMoveDir = dumpMoveDir + filePathInDirs val movedFile = new File(fileDumpingMoveDir) movedFile.getParentFile().mkdirs() - + if(copiedFile.renameTo(movedFile)){ - Logger.debug("File dumped and moved to staging directory successfully.") + Logger.debug("File dumped and moved to staging directory successfully.") }else{ - Logger.warn("Could not move dumped file to staging directory.") - } + Logger.warn("Could not move dumped file to staging directory.") + } } case None => Logger.warn("Could not move dumped file to staging directory. No staging directory set.") - } + } } case None => Logger.warn("Could not dump file. No file dumping directory set.") } @@ -75,4 +75,4 @@ case class DumpOfFile( fileToDump: File, fileId: String, fileName: String -) \ No newline at end of file +) diff --git a/app/services/FileMetadataAutodumpService.scala b/app/services/FileMetadataAutodumpService.scala index 4f7c6f515..d9da81c8d 100644 --- a/app/services/FileMetadataAutodumpService.scala +++ b/app/services/FileMetadataAutodumpService.scala @@ -12,16 +12,16 @@ import play.api.libs.concurrent.Execution.Implicits._ class FileMetadataAutodumpService (application: Application) extends Plugin { val files: FileService = DI.injector.getInstance(classOf[FileService]) - + override def onStart() { Logger.debug("Starting file metadata autodumper Plugin") //Dump metadata of all files periodically - val timeInterval = play.Play.application().configuration().getInt("filemetadatadump.dumpEvery") - Akka.system().scheduler.schedule(0.days, timeInterval.intValue().days){ - dumpAllFileMetadata - } + val timeInterval = play.Play.application().configuration().getInt("filemetadatadump.dumpEvery") + Akka.system().scheduler.schedule(0.days, timeInterval.intValue().days){ + dumpAllFileMetadata + } } - + override def onStop() { Logger.debug("Shutting down file metadata autodumper Plugin") } @@ -29,7 +29,7 @@ class FileMetadataAutodumpService (application: Application) extends Plugin { override lazy val enabled = { !application.configuration.getString("filemetadatadumpservice").filter(_ == "disabled").isDefined } - + def dumpAllFileMetadata() = { val unsuccessfulDumps = files.dumpAllFileMetadata if(unsuccessfulDumps.size == 0) @@ -41,8 +41,7 @@ class FileMetadataAutodumpService (application: Application) extends Plugin { } unsuccessfulMessage = unsuccessfulMessage.substring(0, unsuccessfulMessage.length()-2) + "." Logger.debug(unsuccessfulMessage) - } - + } + } - -} \ No newline at end of file +} diff --git a/app/services/FileService.scala b/app/services/FileService.scala index 2bd852fa6..28e66222e 100644 --- a/app/services/FileService.scala +++ b/app/services/FileService.scala @@ -60,27 +60,27 @@ trait FileService { * List all files in the system. */ def listFiles(): List[File] - + /** * List all files in the system that are not intermediate result files generated by the extractors. */ def listFilesNotIntermediate(): List[File] - + /** * List files after a specified date. */ def listFilesAfter(date: String, limit: Int): List[File] - + /** * List files before a specified date. */ def listFilesBefore(date: String, limit: Int): List[File] - + /** * List files for a specific user after a specified date. */ def listUserFilesAfter(date: String, limit: Int, email: String): List[File] - + /** * List files for a specific user before a specified date. */ @@ -124,7 +124,7 @@ trait FileService { def first(): Option[File] def indexAll() - + def index(id: UUID) /** @@ -144,9 +144,9 @@ trait FileService { // TODO return JsValue def getXMLMetadataJSON(id: UUID): String - + def modifyRDFOfMetadataChangedFiles() - + def modifyRDFUserMetadata(id: UUID, mappingNumber: String="1") def dumpAllFileMetadata(): List[String] @@ -177,7 +177,7 @@ trait FileService { def addUserMetadata(id: UUID, json: String) - def addXMLMetadata(id: UUID, json: String) + def addXMLMetadata(id: UUID, json: String) def findByTag(tag: String, user: Option[User]): List[File] @@ -210,10 +210,10 @@ trait FileService { def searchMetadataFormulateQuery(requestedMap: java.util.LinkedHashMap[String, Any], root: String): MongoDBObject def removeOldIntermediates(apiKey: Option[String], user: Option[User]) - + /** * Update the license data that is currently associated with the file. - * + * * id: The id of the file * licenseType: A String representing the type of license * rightsHolder: A String that is the free-text describing the owner of the license. Only required for certain license types diff --git a/app/services/LdapProvider.scala b/app/services/LdapProvider.scala index 2e5b87fca..dbacfce98 100644 --- a/app/services/LdapProvider.scala +++ b/app/services/LdapProvider.scala @@ -83,4 +83,4 @@ object LdapProvider { lazy val objectClass = conf.getString("securesocial.ldap.objectClass").getOrElse("inetorgperson") lazy val ldapServerURL = conf.getString("securesocial.ldap.url").getOrElse("http://localhost/ldap") lazy val ldapServerTimeOut = conf.getInt("securesocial.ldap.timeout").getOrElse(5) -} \ No newline at end of file +} diff --git a/app/services/MailerPlugin.scala b/app/services/MailerPlugin.scala index 787499d53..8e9b50b9a 100644 --- a/app/services/MailerPlugin.scala +++ b/app/services/MailerPlugin.scala @@ -8,33 +8,33 @@ import javax.activation._ class MailerPlugin (application: Application) extends Plugin { - val from = play.Play.application().configuration().getString("smtp.from") + val from = play.Play.application().configuration().getString("smtp.from") val host = play.Play.application().configuration().getString("smtp.host") val properties = System.getProperties() properties.setProperty("mail.smtp.host", host) - + //SSL or regular SMTP var port = play.api.Play.configuration.getInt("smtp.port").getOrElse(0) if(play.api.Play.configuration.getBoolean("smtp.ssl").getOrElse(false)){ if(port == 0) port = 465 - + properties.setProperty("mail.smtp.socketFactory.port", port.toString) - properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory") + properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory") } else{ if(port == 0) port = 25 } properties.setProperty("mail.smtp.port", port.toString) - - val user = play.api.Play.configuration.getString("smtp.user").getOrElse("") - + + val user = play.api.Play.configuration.getString("smtp.user").getOrElse("") + if(!user.equals("")){ properties.setProperty("mail.smtp.auth", "true") } - - + + override def onStart() { Logger.debug("Starting Mailer Plugin") @@ -46,22 +46,22 @@ class MailerPlugin (application: Application) extends Plugin { override lazy val enabled = { !application.configuration.getString("mailservice").filter(_ == "disabled").isDefined } - + def sendMail(subscriberMail : String, html: String, subject: String): Boolean = { - - Logger.debug("Sending mail to " + subscriberMail) - + + Logger.debug("Sending mail to " + subscriberMail) + //Authenticate if needed - var session = Session.getDefaultInstance(properties) + var session = Session.getDefaultInstance(properties) if(!user.equals("")){ session = Session.getInstance(properties, - new javax.mail.Authenticator() { - override def getPasswordAuthentication(): PasswordAuthentication = { - return new PasswordAuthentication(user, play.api.Play.configuration.getString("smtp.password").getOrElse("")) - } - }) + new javax.mail.Authenticator() { + override def getPasswordAuthentication(): PasswordAuthentication = { + return new PasswordAuthentication(user, play.api.Play.configuration.getString("smtp.password").getOrElse("")) + } + }) } - + try{ val message = new MimeMessage(session) message.setFrom(new InternetAddress(from)) @@ -70,16 +70,16 @@ class MailerPlugin (application: Application) extends Plugin { message.setSubject(subject) message.setContent(html, "text/html") Transport.send(message) - + Logger.debug("Sent message successfully.") }catch { case msgex: MessagingException =>{ - Logger.error(msgex.toString()) - return false - } + Logger.error(msgex.toString()) + return false + } } return true } - -} \ No newline at end of file + +} diff --git a/app/services/MetadataService.scala b/app/services/MetadataService.scala index fa80a0abe..0ccb50ad6 100644 --- a/app/services/MetadataService.scala +++ b/app/services/MetadataService.scala @@ -10,13 +10,13 @@ import play.api.mvc.MultipartFormData * MetadataService for add and query metadata */ trait MetadataService { - + /** Add metadata to the metadata collection and attach to a section /file/dataset/collection */ def addMetadata(metadata: Metadata) : UUID - + /** Get Metadata By Id*/ def getMetadataById(id : UUID) : Option[Metadata] - + /** Get Metadata based on Id of an element (section/file/dataset/collection) */ def getMetadataByAttachTo(resourceRef: ResourceRef): List[Metadata] @@ -35,7 +35,7 @@ trait MetadataService { /** Remove metadata by attachTo from a specific extractor */ def removeMetadataByAttachToAndExtractor(resourceRef: ResourceRef, extractorName: String, host: String, apiKey: Option[String], user: Option[User]): List[UUID] - + /** Get metadata context if available */ def getMetadataContext(metadataId: UUID): Option[JsValue] diff --git a/app/services/MultimediaQueryService.scala b/app/services/MultimediaQueryService.scala index 49c2bda18..e1df62c8c 100644 --- a/app/services/MultimediaQueryService.scala +++ b/app/services/MultimediaQueryService.scala @@ -13,34 +13,34 @@ import play.api.libs.json.JsObject * Generic file service to store blobs of files and metadata about them. */ abstract class MultimediaQueryService { - + /** * Update thumbnail used to represent this query. */ - def updateThumbnail(queryId: UUID, thumbnailId: UUID) - + def updateThumbnail(queryId: UUID, thumbnailId: UUID) + /** * Save a file from an input stream. */ def save(inputStream: InputStream, filename: String, contentType: Option[String]): Option[TempFile] - + /** * Get the input stream of a file given a file id. * Returns input stream, file name, content type, content length. */ def get(id: UUID): Option[(InputStream, String, String, Long)] - + /** * List all files in the system. */ def listFiles(): List[TempFile] - - + + /** * Get file metadata. */ def getFile(id: UUID): Option[TempFile] - + /** * Store file metadata. */ @@ -61,4 +61,4 @@ abstract class MultimediaQueryService { def recomputeAllDistances() def computeDistances(source: MultimediaFeatures) -} \ No newline at end of file +} diff --git a/app/services/PolyglotPlugin.scala b/app/services/PolyglotPlugin.scala index 110c0c27e..a9612ece1 100644 --- a/app/services/PolyglotPlugin.scala +++ b/app/services/PolyglotPlugin.scala @@ -59,23 +59,23 @@ class PolyglotPlugin(application: Application) extends Plugin { */ def checkForFileAndDownload(triesLeft: Int, url: String, outputStream: OutputStream): Future[Unit] = { - //check that credentials are set in config file + //check that credentials are set in config file if ( !polyglotUser.isDefined || !polyglotPassword.isDefined) { throw new RuntimeException("Polyglot credentials not defined.") } - + if (triesLeft == 0) Future.failed(throw new RuntimeException("Converted file not found.")) - + else WS.url(url).withAuth(polyglotUser.get, polyglotPassword.get, AuthScheme.BASIC).get flatMap { res => if (res.status == 200) { //this is the callback, runs after file exists is TRUE Logger.debug("File exists on polyglot. Will download now.") //file exists on Polyglot, begin download using iteratee - //following example in https://www.playframework.com/documentation/2.2.x/ScalaWS Processing large responses + //following example in https://www.playframework.com/documentation/2.2.x/ScalaWS Processing large responses val result = WS.url(url) .withAuth(polyglotUser.get, polyglotPassword.get, AuthScheme.BASIC) .get { xx => fromStream(outputStream) } - .flatMap(_.run) + .flatMap(_.run) //Returning result. When it is mapped in the controller, the successful future is AFTER file has been downloaded on the Clowder server. result } else { @@ -85,7 +85,7 @@ class PolyglotPlugin(application: Application) extends Plugin { } } - /** + /** * Uploads to Polyglot the file to be converted. Returns url of the converted file. */ def getConvertedFileURL(filename: String, inputStream: java.io.InputStream, outputFormat: String): Future[String] = { @@ -96,8 +96,8 @@ class PolyglotPlugin(application: Application) extends Plugin { //post a multipart form data to Polyglot. //based on the code from https://github.com/playframework/playframework/issues/902 - //comment dated Dec 5, 2014 - // Build up the Multiparts - consists of just one file part + //comment dated Dec 5, 2014 + // Build up the Multiparts - consists of just one file part val filePart: FilePart = new FilePart(filename, new ByteArrayPartSource(filename, IOUtils.toByteArray(inputStream))) val parts = Array[Part](filePart) val reqEntity = new MultipartRequestEntity(parts, new FluentCaseInsensitiveStringsMap) @@ -106,19 +106,19 @@ class PolyglotPlugin(application: Application) extends Plugin { val bytes = baos.toByteArray val reqContentType = reqEntity.getContentType - // Now just send the data to the WS API + // Now just send the data to the WS API val response = WS.url(polyglotConvertURL.get + outputFormat) .withAuth(polyglotUser.get, polyglotPassword.get, AuthScheme.BASIC) .post(bytes)(Writeable.wBytes, ContentTypeOf(Some(reqContentType))) - //get the url for the converted file on Polyglot + //get the url for the converted file on Polyglot val fileURLFut = response.map { res => if (res.status != 200) { Logger.debug("Could not get url of converted file - status = " + res.status + " " + res.statusText) throw new RuntimeException("Could not connect to Polyglot. " + res.statusText) } - //TODO: Find an easier way to get rid of html markup + //TODO: Find an easier way to get rid of html markup //result is an html link //http://the_url_string val fileURL = res.body.substring(res.body.indexOf("http"), res.body.indexOf(">")) @@ -127,9 +127,9 @@ class PolyglotPlugin(application: Application) extends Plugin { fileURLFut.map { url => Logger.debug("Converted file url = " + url) } fileURLFut } - + /** - * Gets all output formats for the given input format. + * Gets all output formats for the given input format. * If outputs are stored in memory, returns them. Otherwise, calls another method to fetch outputs from Polyglot. */ def getOutputFormats(inputType: String): Future[Option[List[String]]] = { @@ -143,20 +143,20 @@ class PolyglotPlugin(application: Application) extends Plugin { getOutputFormatsPolyglot(inputType) } } - + /** * Goes to Polyglot and fetches all output formats for the input format given. */ - def getOutputFormatsPolyglot(inputType: String): Future[Option[List[String]]] = { + def getOutputFormatsPolyglot(inputType: String): Future[Option[List[String]]] = { //proceed only if received all the config params if (polyglotInputsURL.isDefined && polyglotUser.isDefined && polyglotPassword.isDefined) { - //call polyglot server with authentication + //call polyglot server with authentication WS.url(polyglotInputsURL.get + inputType) .withAuth(polyglotUser.get, polyglotPassword.get, AuthScheme.BASIC) .get .map { case response => - //If reponse was successful, get a list of output formats. Otherwise return None. + //If response was successful, get a list of output formats. Otherwise return None. val outputFormats = { if (response.status == 200) { Logger.debug("success getting response from Polyglot") @@ -176,4 +176,4 @@ class PolyglotPlugin(application: Application) extends Plugin { Future(None) } } -} \ No newline at end of file +} diff --git a/app/services/PostgresPlugin.scala b/app/services/PostgresPlugin.scala index f3ff6d18a..de00e3805 100644 --- a/app/services/PostgresPlugin.scala +++ b/app/services/PostgresPlugin.scala @@ -160,14 +160,14 @@ class PostgresPlugin(application: Application) extends Plugin { val data = Json.stringify(f._4) val geojson = f._5 - ps.setTimestamp(index+1, new Timestamp(start.getTime)) + ps.setTimestamp(index + 1, new Timestamp(start.getTime)) if (end.isDefined) - ps.setTimestamp(index+2, new Timestamp(end.get.getTime)) + ps.setTimestamp(index + 2, new Timestamp(end.get.getTime)) else - ps.setDate(index+2, null) - ps.setInt(index+3, stream_id.toInt) - ps.setString(index+4, data) - ps.setString(index+5, Json.stringify(geojson)) + ps.setDate(index + 2, null) + ps.setInt(index + 3, stream_id.toInt) + ps.setString(index + 4, data) + ps.setString(index + 5, Json.stringify(geojson)) index += 5 }) @@ -240,7 +240,7 @@ class PostgresPlugin(application: Application) extends Plugin { if (sensor_name.isDefined) st.setString(i + 4, sensor_name.getOrElse("")) } else if ((parts.length >= 6) && (parts.length % 2 == 0)) { while (i < parts.length) { - st.setDouble(i + 1, parts(i+1).toDouble) + st.setDouble(i + 1, parts(i + 1).toDouble) st.setDouble(i + 2, parts(i).toDouble) i += 2 } @@ -455,7 +455,7 @@ class PostgresPlugin(application: Application) extends Plugin { (name, base + "#detail/location/" + name + "/") } } - + def getSensorStreams(id: String): Option[String] = { var data = "" val query = "SELECT array_to_json(array_agg(t),true) As my_places FROM " + @@ -476,14 +476,14 @@ class PostgresPlugin(application: Application) extends Plugin { None } else Some(data) } - + def getSensorStats(id: String): Option[String] = { val query = "WITH stream_info AS (" + - "SELECT sensor_id, start_time, end_time, unnest(params) AS param FROM streams WHERE sensor_id=?" + - ") " + - "SELECT row_to_json(t, true) AS my_sensor FROM (" + - "SELECT to_char(min(start_time) AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SSZ') As min_start_time, to_char(max(end_time) AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SSZ') As max_end_time, array_agg(distinct param) AS parameters FROM stream_info" + - ") As t;" + "SELECT sensor_id, start_time, end_time, unnest(params) AS param FROM streams WHERE sensor_id=?" + + ") " + + "SELECT row_to_json(t, true) AS my_sensor FROM (" + + "SELECT to_char(min(start_time) AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SSZ') As min_start_time, to_char(max(end_time) AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SSZ') As max_end_time, array_agg(distinct param) AS parameters FROM stream_info" + + ") As t;" val st = conn.prepareStatement(query) st.setInt(1, id.toInt) Logger.debug("Get streams by sensor statement: " + st) @@ -567,7 +567,7 @@ class PostgresPlugin(application: Application) extends Plugin { } } else if ((parts.length >= 6) && (parts.length % 2 == 0)) { while (i < parts.length) { - st.setDouble(i + 1, parts(i+1).toDouble) + st.setDouble(i + 1, parts(i + 1).toDouble) st.setDouble(i + 2, parts(i).toDouble) i += 2 } @@ -665,7 +665,7 @@ class PostgresPlugin(application: Application) extends Plugin { } def deleteStream(id: Integer): Boolean = { - val deleteStream = "DELETE from streams where gid = ?" + val deleteStream = "DELETE from streams where gid = ?" val st = conn.prepareStatement(deleteStream) st.setInt(1, id) st.execute() @@ -702,8 +702,8 @@ class PostgresPlugin(application: Application) extends Plugin { st.execute() st.close true - } - + } + def dropAll(): Boolean = { val deleteSensors = "DELETE from sensors" val st = conn.prepareStatement(deleteSensors) @@ -719,7 +719,7 @@ class PostgresPlugin(application: Application) extends Plugin { st3.close() true } - + def counts(): (Int, Int, Int) = { var counts = (0, 0, 0) val countQuery = "SELECT (SELECT COUNT(DISTINCT gid) FROM sensors) AS sensors,(SELECT COUNT(DISTINCT gid) FROM streams) AS streams,(SELECT COUNT(DISTINCT gid) FROM datapoints) AS datapoints" @@ -808,7 +808,7 @@ class PostgresPlugin(application: Application) extends Plugin { } else if ((parts.length >= 6) && (parts.length % 2 == 0)) { var j = 0 while (j < parts.length) { - st.setDouble(i + 1, parts(j+1).toDouble) + st.setDouble(i + 1, parts(j + 1).toDouble) st.setDouble(i + 2, parts(j).toDouble) i += 2 j += 2 @@ -986,22 +986,22 @@ class PostgresPlugin(application: Application) extends Plugin { } } } - + def filterProperties(obj: JsObject, attributes: List[String]) = { var props = JsObject(Seq.empty) (obj \ "properties").asOpt[JsObject] match { - case Some(x) => { - for (f <- x.fieldSet) { - if (("source" == f._1) || attributes.contains(f._1)) { - props = props + f - } - } - (obj - ("properties") + ("properties", props)) - } - case None => obj + case Some(x) => { + for (f <- x.fieldSet) { + if (("source" == f._1) || attributes.contains(f._1)) { + props = props + f + } + } + (obj - ("properties") + ("properties", props)) + } + case None => obj } } - + def getDatapoint(id: String): Option[String] = { var data = "" val query = "SELECT row_to_json(t,true) As my_datapoint FROM " + diff --git a/app/services/PreviewService.scala b/app/services/PreviewService.scala index d29cd17b2..eab35cf34 100644 --- a/app/services/PreviewService.scala +++ b/app/services/PreviewService.scala @@ -71,7 +71,7 @@ trait PreviewService { def setTitle(previewId: UUID, title: String) def getMetadata(id: UUID): scala.collection.immutable.Map[String,Any] - + def getExtractorId(id: UUID): String - + } diff --git a/app/services/RDFExportService.scala b/app/services/RDFExportService.scala index a938ef3c0..fba92515f 100644 --- a/app/services/RDFExportService.scala +++ b/app/services/RDFExportService.scala @@ -22,15 +22,15 @@ import models.UUID * */ class RDFExportService (application: Application) extends Plugin { - + val files: FileService = DI.injector.getInstance(classOf[FileService]) val datasets: DatasetService = DI.injector.getInstance(classOf[DatasetService]) val previews: PreviewService = DI.injector.getInstance(classOf[PreviewService]) - + val resultsDir = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + "clowder__rdfdumptemporaryfiles" + System.getProperty("file.separator") val filesMappingsQuantity = Integer.parseInt(play.api.Play.configuration.getString("filesxmltordfmapping.dircount").getOrElse("1")) val datasetsMappingsQuantity = Integer.parseInt(play.api.Play.configuration.getString("datasetsxmltordfmapping.dircount").getOrElse("1")) - + val hostUrl = "http://" + play.Play.application().configuration().getString("hostIp").replaceAll("/$", "") + ":" + play.Play.application().configuration().getString("http.port") override def onStart() { @@ -38,10 +38,10 @@ class RDFExportService (application: Application) extends Plugin { //Clean temporary RDF files var timeInterval = play.Play.application().configuration().getInt("rdfTempCleanup.checkEvery") Akka.system().scheduler.schedule(0.minutes, timeInterval.intValue().minutes){ - files.removeTemporaries() + files.removeTemporaries() } } - + override def onStop() { Logger.debug("Shutting down RDF exporter Plugin") } @@ -49,162 +49,162 @@ class RDFExportService (application: Application) extends Plugin { override lazy val enabled = { !application.configuration.getString("rdfexportservice").filter(_ == "disabled").isDefined } - + def getRDFUserMetadataFile(id: String, mappingNumber: String="1"): Option[java.io.File] = { - - val uuId = UUID(id) - files.get(uuId) match { - case Some(file) => { - val theJSON = files.getUserMetadataJSON(uuId) - val fileSep = System.getProperty("file.separator") - - //for Unix we need an extra \ in the directory path of the LidoToCidocConvertion output file due to Windows-based behavior of LidoToCidocConvertion - var extraChar = "" - val OS = System.getProperty("os.name").toLowerCase() - if(OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") >= 0) - extraChar = "\\" - - var resultDir = resultsDir + new ObjectId().toString - new java.io.File(resultDir).mkdirs() - - if(!theJSON.replaceAll(" ","").equals("{}")){ - val xmlFile = jsonToXML(theJSON) - new LidoToCidocConvertion(play.api.Play.configuration.getString("filesxmltordfmapping.dir_"+mappingNumber).getOrElse(""), xmlFile.getAbsolutePath(), resultDir) - xmlFile.delete() - } - else{ - new java.io.File(resultDir + fileSep + extraChar + "Results.rdf").createNewFile() - } - val resultFile = new java.io.File(resultDir + fileSep + extraChar + "Results.rdf") - Some(resultFile) - } - case None => None - } + + val uuId = UUID(id) + files.get(uuId) match { + case Some(file) => { + val theJSON = files.getUserMetadataJSON(uuId) + val fileSep = System.getProperty("file.separator") + + //for Unix we need an extra \ in the directory path of the LidoToCidocConvertion output file due to Windows-based behavior of LidoToCidocConvertion + var extraChar = "" + val OS = System.getProperty("os.name").toLowerCase() + if(OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") >= 0) + extraChar = "\\" + + var resultDir = resultsDir + new ObjectId().toString + new java.io.File(resultDir).mkdirs() + + if(!theJSON.replaceAll(" ","").equals("{}")){ + val xmlFile = jsonToXML(theJSON) + new LidoToCidocConvertion(play.api.Play.configuration.getString("filesxmltordfmapping.dir_" + mappingNumber).getOrElse(""), xmlFile.getAbsolutePath(), resultDir) + xmlFile.delete() + } + else{ + new java.io.File(resultDir + fileSep + extraChar + "Results.rdf").createNewFile() + } + val resultFile = new java.io.File(resultDir + fileSep + extraChar + "Results.rdf") + Some(resultFile) + } + case None => None + } } - + def getRDFURLsForFile(id: String): Option[JsValue] = { - val uuId = UUID(id) + val uuId = UUID(id) files.get(uuId) match { - case Some(file) => { - - //RDF from XML of the file itself (for XML metadata-only files) - val previewsList = previews.findByFileId(uuId) - var rdfPreviewList = List.empty[models.Preview] - for(currPreview <- previewsList){ - if(currPreview.contentType.equals("application/rdf+xml")){ - rdfPreviewList = rdfPreviewList :+ currPreview - } - } - var list = for (currPreview <- rdfPreviewList) yield Json.toJson(hostUrl + api.routes.Previews.download(currPreview.id)) - - //RDF from export of file community-generated metadata to RDF - for(i <- 1 to filesMappingsQuantity){ - var currHostString = hostUrl + api.routes.Files.getRDFUserMetadata(uuId,i.toString) - list = list :+ Json.toJson(currHostString) - } - - val listJson = Json.toJson(list.toList) - Some(listJson) - } - case None => None - } + case Some(file) => { + + //RDF from XML of the file itself (for XML metadata-only files) + val previewsList = previews.findByFileId(uuId) + var rdfPreviewList = List.empty[models.Preview] + for(currPreview <- previewsList){ + if(currPreview.contentType.equals("application/rdf+xml")){ + rdfPreviewList = rdfPreviewList :+ currPreview + } + } + var list = for (currPreview <- rdfPreviewList) yield Json.toJson(hostUrl + api.routes.Previews.download(currPreview.id)) + + //RDF from export of file community-generated metadata to RDF + for(i <- 1 to filesMappingsQuantity){ + var currHostString = hostUrl + api.routes.Files.getRDFUserMetadata(uuId,i.toString) + list = list :+ Json.toJson(currHostString) + } + + val listJson = Json.toJson(list.toList) + Some(listJson) + } + case None => None + } } - + def getRDFUserMetadataDataset(id: String, mappingNumber: String="1"): Option[java.io.File] = { - val uuId = UUID(id) - datasets.get(uuId) match { - case Some(dataset) => { - val theJSON = datasets.getUserMetadataJSON(uuId) - val fileSep = System.getProperty("file.separator") - - //for Unix we need an extra \ in the directory path of the LidoToCidocConvertion output file due to Windows-based behavior of LidoToCidocConvertion - var extraChar = "" - val OS = System.getProperty("os.name").toLowerCase() - if(OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") >= 0) - extraChar = "\\" - - var resultDir = resultsDir + new ObjectId().toString - new java.io.File(resultDir).mkdirs() - - if(!theJSON.replaceAll(" ","").equals("{}")){ - val xmlFile = jsonToXML(theJSON) - new LidoToCidocConvertion(play.api.Play.configuration.getString("datasetsxmltordfmapping.dir_"+mappingNumber).getOrElse(""), xmlFile.getAbsolutePath(), resultDir) - xmlFile.delete() - } - else{ - new java.io.File(resultDir + fileSep + extraChar + "Results.rdf").createNewFile() - } - val resultFile = new java.io.File(resultDir + fileSep + extraChar + "Results.rdf") - Some(resultFile) - } - case None => None - } + val uuId = UUID(id) + datasets.get(uuId) match { + case Some(dataset) => { + val theJSON = datasets.getUserMetadataJSON(uuId) + val fileSep = System.getProperty("file.separator") + + //for Unix we need an extra \ in the directory path of the LidoToCidocConvertion output file due to Windows-based behavior of LidoToCidocConvertion + var extraChar = "" + val OS = System.getProperty("os.name").toLowerCase() + if(OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") >= 0) + extraChar = "\\" + + var resultDir = resultsDir + new ObjectId().toString + new java.io.File(resultDir).mkdirs() + + if(!theJSON.replaceAll(" ","").equals("{}")){ + val xmlFile = jsonToXML(theJSON) + new LidoToCidocConvertion(play.api.Play.configuration.getString("datasetsxmltordfmapping.dir_" + mappingNumber).getOrElse(""), xmlFile.getAbsolutePath(), resultDir) + xmlFile.delete() + } + else{ + new java.io.File(resultDir + fileSep + extraChar + "Results.rdf").createNewFile() + } + val resultFile = new java.io.File(resultDir + fileSep + extraChar + "Results.rdf") + Some(resultFile) + } + case None => None + } } - + def getRDFURLsForDataset(id: String): Option[JsValue] = { - val uuId = UUID(id) + val uuId = UUID(id) datasets.get(uuId) match { - case Some(dataset) => { - - //RDF from XML files in the dataset itself (for XML metadata-only files) - val previewsList = previews.findByDatasetId(uuId) - var rdfPreviewList = List.empty[models.Preview] - for(currPreview <- previewsList){ - if(currPreview.contentType.equals("application/rdf+xml")){ - rdfPreviewList = rdfPreviewList :+ currPreview - } - } - var list = for (currPreview <- rdfPreviewList) yield Json.toJson(hostUrl + api.routes.Previews.download(currPreview.id)) - - for(file <- dataset.files){ - val filePreviewsList = previews.findByFileId(file) - var fileRdfPreviewList = List.empty[models.Preview] - for(currPreview <- filePreviewsList){ - if(currPreview.contentType.equals("application/rdf+xml")){ - fileRdfPreviewList = fileRdfPreviewList :+ currPreview - } - } - val filesList = for (currPreview <- fileRdfPreviewList) yield Json.toJson(hostUrl + api.routes.Previews.download(currPreview.id)) - list = list ++ filesList - } - - //RDF from export of file community-generated metadata to RDF - for(i <- 1 to filesMappingsQuantity){ - var currHostString = hostUrl + api.routes.Datasets.getRDFUserMetadata(uuId,i.toString) - list = list :+ Json.toJson(currHostString) - } - - val listJson = Json.toJson(list.toList) - Some(listJson) - } - case None => None - } + case Some(dataset) => { + + //RDF from XML files in the dataset itself (for XML metadata-only files) + val previewsList = previews.findByDatasetId(uuId) + var rdfPreviewList = List.empty[models.Preview] + for(currPreview <- previewsList){ + if(currPreview.contentType.equals("application/rdf+xml")){ + rdfPreviewList = rdfPreviewList :+ currPreview + } + } + var list = for (currPreview <- rdfPreviewList) yield Json.toJson(hostUrl + api.routes.Previews.download(currPreview.id)) + + for(file <- dataset.files){ + val filePreviewsList = previews.findByFileId(file) + var fileRdfPreviewList = List.empty[models.Preview] + for(currPreview <- filePreviewsList){ + if(currPreview.contentType.equals("application/rdf+xml")){ + fileRdfPreviewList = fileRdfPreviewList :+ currPreview + } + } + val filesList = for (currPreview <- fileRdfPreviewList) yield Json.toJson(hostUrl + api.routes.Previews.download(currPreview.id)) + list = list ++ filesList + } + + //RDF from export of file community-generated metadata to RDF + for(i <- 1 to filesMappingsQuantity){ + var currHostString = hostUrl + api.routes.Datasets.getRDFUserMetadata(uuId,i.toString) + list = list :+ Json.toJson(currHostString) + } + + val listJson = Json.toJson(list.toList) + Some(listJson) + } + case None => None + } } - + def jsonToXML(theJSON: String): java.io.File = { - - val jsonObject = new JSONObject(theJSON) + + val jsonObject = new JSONObject(theJSON) var xml = org.json.XML.toString(jsonObject) - + //Remove spaces from XML tags var currStart = xml.indexOf("<") var currEnd = -1 var xmlNoSpaces = "" while(currStart != -1){ - xmlNoSpaces = xmlNoSpaces + xml.substring(currEnd+1,currStart) - currEnd = xml.indexOf(">", currStart+1) - xmlNoSpaces = xmlNoSpaces + xml.substring(currStart,currEnd+1).replaceAll(" ", "_") - currStart = xml.indexOf("<", currEnd+1) + xmlNoSpaces = xmlNoSpaces + xml.substring(currEnd + 1,currStart) + currEnd = xml.indexOf(">", currStart + 1) + xmlNoSpaces = xmlNoSpaces + xml.substring(currStart,currEnd + 1).replaceAll(" ", "_") + currStart = xml.indexOf("<", currEnd + 1) } - xmlNoSpaces = xmlNoSpaces + xml.substring(currEnd+1) - - val xmlFile = java.io.File.createTempFile("xml",".xml") + xmlNoSpaces = xmlNoSpaces + xml.substring(currEnd + 1) + + val xmlFile = java.io.File.createTempFile("xml", ".xml") val fileWriter = new BufferedWriter(new FileWriter(xmlFile)) fileWriter.write(xmlNoSpaces) fileWriter.close() - - return xmlFile + + return xmlFile } - - -} \ No newline at end of file + + +} diff --git a/app/services/RDFUpdateService.scala b/app/services/RDFUpdateService.scala index c2a2384db..9c1d6e91a 100644 --- a/app/services/RDFUpdateService.scala +++ b/app/services/RDFUpdateService.scala @@ -66,199 +66,199 @@ class RDFUpdateService(application: Application) extends Plugin { def modifyRDFUserMetadataFiles(id: UUID, mappingNumber: String="1") = { sparql.removeFileFromGraphs(id, "rdfCommunityGraphName") - files.get(id) match { - case Some(file) => { - val theJSON = files.getUserMetadataJSON(id) - val fileSep = System.getProperty("file.separator") - - //for Unix we need an extra \ in the directory path of the LidoToCidocConvertion output file due to Windows-based behavior of LidoToCidocConvertion - var extraChar = "" - val OS = System.getProperty("os.name").toLowerCase() - if(OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") >= 0) - extraChar = "\\" - - val tmpDir = System.getProperty("java.io.tmpdir") - var resultDir = tmpDir + fileSep + "clowder__rdfuploadtemporaryfiles" + fileSep + new ObjectId().toString - val resultDirFile = new java.io.File(resultDir) - resultDirFile.mkdirs() - - if(!theJSON.replaceAll(" ","").equals("{}")){ - val xmlFile = jsonToXML(theJSON) - new LidoToCidocConvertion(play.api.Play.configuration.getString("filesxmltordfmapping.dir_"+mappingNumber).getOrElse(""), xmlFile.getAbsolutePath(), resultDir) - xmlFile.delete() - } - else{ - new java.io.File(resultDir + fileSep + extraChar + "Results.rdf").createNewFile() - } - val resultFile = new java.io.File(resultDir + fileSep + extraChar + "Results.rdf") - - //Connecting RDF metadata with the entity describing the original file - val rootNodes = new ArrayList[String]() - val rootNodesFile = play.api.Play.configuration.getString("rootNodesFile").getOrElse("") - Logger.debug(rootNodesFile) - if(!rootNodesFile.equals("*")){ - val rootNodesReader = new BufferedReader(new FileReader(new java.io.File(rootNodesFile))) - var line = rootNodesReader.readLine() - while (line != null){ - Logger.debug((line == null).toString() ) - rootNodes.add(line.trim()) - line = rootNodesReader.readLine() - } - rootNodesReader.close() - } - - val resultFileConnected = java.io.File.createTempFile("ResultsConnected", ".rdf") - - val fileWriter = new BufferedWriter(new FileWriter(resultFileConnected)) - val fis = new FileInputStream(resultFile) - val data = new Array[Byte] (resultFile.length().asInstanceOf[Int]) - fis.read(data) - fis.close() - resultFile.delete() - FileUtils.deleteDirectory(resultDirFile) - // - val s = new String(data, "UTF-8") - val rdfDescriptions = s.split("Powered by Clowder +
Powered by Clowder (@sys.props.getOrElse("build.version", default = "0.0.0")#@sys.props.getOrElse("build.bamboo", default = "development") branch:@sys.props.getOrElse("build.branch", default = "unknown") sha1:@sys.props.getOrElse("build.gitsha1", default = "unknown")).