@@ -168,17 +168,6 @@ class Datasets @Inject() (
168168 }
169169 }
170170
171- val commentMap = datasetList.map { dataset =>
172- var allComments = comments.findCommentsByDatasetId(dataset.id)
173- dataset.files.map { file =>
174- allComments ++= comments.findCommentsByFileId(file)
175- sections.findByFileId(file).map { section =>
176- allComments ++= comments.findCommentsBySectionId(section.id)
177- }
178- }
179- dataset.id -> allComments.size
180- }.toMap
181-
182171 // Modifications to decode HTML entities that were stored in an encoded fashion as part
183172 // of the datasets names or descriptions
184173 val decodedDatasetList = ListBuffer .empty[models.Dataset ]
@@ -206,7 +195,7 @@ class Datasets @Inject() (
206195 Logger .debug(" User selection " + userSelections)
207196
208197 // Pass the viewMode into the view
209- Ok (views.html.users.followingDatasets(decodedDatasetList.toList, commentMap, prev, next, limit, viewMode, None , title, None , userSelections))
198+ Ok (views.html.users.followingDatasets(decodedDatasetList.toList, prev, next, limit, viewMode, None , title, None , userSelections))
210199 }
211200 case None => InternalServerError (" No User found" )
212201 }
@@ -356,17 +345,6 @@ class Datasets @Inject() (
356345 " "
357346 }
358347
359- val commentMap = datasetList.map { dataset =>
360- var allComments = comments.findCommentsByDatasetId(dataset.id)
361- dataset.files.map { file =>
362- allComments ++= comments.findCommentsByFileId(file)
363- sections.findByFileId(file).map { section =>
364- allComments ++= comments.findCommentsBySectionId(section.id)
365- }
366- }
367- dataset.id -> allComments.size
368- }.toMap
369-
370348 // Modifications to decode HTML entities that were stored in an encoded fashion as part
371349 // of the datasets names or descriptions
372350 val decodedDatasetList = ListBuffer .empty[models.Dataset ]
@@ -397,7 +375,9 @@ class Datasets @Inject() (
397375 case Some (s) if ! Permission .checkPermission(Permission .ViewSpace , ResourceRef (ResourceRef .space, UUID (s))) => {
398376 BadRequest (views.html.notAuthorized(" You are not authorized to access the " + spaceTitle + " ." , s, " space" ))
399377 }
400- case _ => Ok (views.html.datasetList(decodedDatasetList.toList, commentMap, prev, next, limit, viewMode, space, spaceName, status, title, owner, ownerName, when, date, userSelections, showTrash))
378+ case _ =>
379+ Ok (views.html.datasetList(decodedDatasetList.toList, prev, next, limit, viewMode, space, spaceName,
380+ status, title, owner, ownerName, when, date, userSelections, showTrash))
401381 }
402382 }
403383
@@ -512,7 +492,7 @@ class Datasets @Inject() (
512492 " "
513493 }
514494 val date = " "
515- Ok (views.html.datasetList(decodedDatasetList.toList, commentMap, prev, next, limit, viewMode, Some (space), spaceName, None , title, None , None , " a" , date, userSelections))
495+ Ok (views.html.datasetList(decodedDatasetList.toList, prev, next, limit, viewMode, Some (space), spaceName, None , title, None , None , " a" , date, userSelections))
516496 }
517497 }
518498 }
@@ -526,54 +506,30 @@ class Datasets @Inject() (
526506 Previewers .findDatasetPreviewers().foreach(p => Logger .debug(" Previewer found " + p.id))
527507 datasets.get(id) match {
528508 case Some (dataset) => {
529-
530- // get files info sorted by date
531- val filesInDataset = dataset.files.flatMap(f => files.get(f) match {
532- case Some (file) => Some (file)
533- case None => Logger .debug(s " Unable to find file $f" ); None
534- }).asInstanceOf [List [File ]].sortBy(_.uploadDate)
535-
536- var datasetWithFiles = dataset.copy(files = filesInDataset.map(_.id))
537- datasetWithFiles = Utils .decodeDatasetElements(datasetWithFiles)
538-
509+ // previewers
539510 val filteredPreviewers = Previewers .findDatasetPreviewers
540511
512+ // metadata
541513 val m = metadata.getMetadataByAttachTo(ResourceRef (ResourceRef .dataset, dataset.id))
542514
515+ // collections
543516 val collectionsInside = collections.listInsideDataset(id, request.user, request.user.fold(false )(_.superAdminMode)).sortBy(_.name)
544517 var decodedCollectionsInside = new ListBuffer [models.Collection ]()
545- var filesTags = TreeSet .empty[String ]
546-
547518 for (aCollection <- collectionsInside) {
548519 val dCollection = Utils .decodeCollectionElements(aCollection)
549520 decodedCollectionsInside += dCollection
550521 }
551522
552- var commentsByDataset = comments.findCommentsByDatasetId(id)
553- filesInDataset.map {
554- file =>
555-
556- commentsByDataset ++= comments.findCommentsByFileId(file.id)
557- sections.findByFileId(UUID (file.id.toString)).map { section =>
558- commentsByDataset ++= comments.findCommentsBySectionId(section.id)
559- }
560- }
561- commentsByDataset = commentsByDataset.sortBy(_.posted)
562-
563- // Decode the comments so that their free text will display correctly in the view
523+ // comments
524+ var commentsByDataset = comments.findCommentsByDatasetId(id).sortBy(_.posted)
525+ // decode the comments so that their free text will display correctly in the view
564526 var decodedCommentsByDataset = ListBuffer .empty[Comment ]
565527 for (aComment <- commentsByDataset) {
566528 val dComment = Utils .decodeCommentElements(aComment)
567529 decodedCommentsByDataset += dComment
568530 }
569531
570- filesInDataset.map { file =>
571- file.tags.map {
572- tag => filesTags += tag.name
573- }
574- }
575-
576- // associated sensors
532+ // sensors
577533 val sensors : List [(String , String , String )] = current.plugin[PostgresPlugin ] match {
578534 case Some (db) if db.isEnabled => {
579535 // findRelationships will return a "Relation" model with all information about the relationship
@@ -591,8 +547,8 @@ class Datasets @Inject() (
591547 case _ => List .empty[(String , String , String )]
592548 }
593549
550+ // spaces
594551 var datasetSpaces : List [ProjectSpace ] = List .empty[ProjectSpace ]
595-
596552 var decodedSpaces_canRemove : Map [ProjectSpace , Boolean ] = Map .empty
597553 var isInPublicSpace = false
598554 dataset.spaces.map {
@@ -607,26 +563,27 @@ class Datasets @Inject() (
607563 case None => Logger .error(s " space with id $sp on $Messages('dataset.title') $id doesn't exist. " )
608564 }
609565 }
610-
611- val fileList : List [File ] = dataset.files.reverse.map(f => files.get(f)).flatten
612-
613- // dataset is in at least one space with editstagingarea permission, or if the user is the owner of dataset.
614- val stagingarea = datasetSpaces filter (space => Permission .checkPermission(Permission .EditStagingArea , ResourceRef (ResourceRef .space, space.id)))
566+ // dataset is in at least one space with editstagingarea permission, or if the user is the owner of dataset
567+ val stagingarea = datasetSpaces filter (space => Permission .checkPermission(Permission .EditStagingArea ,
568+ ResourceRef (ResourceRef .space, space.id)))
615569 val toPublish = ! stagingarea.isEmpty
616-
617- val curObjectsPublished : List [CurationObject ] = curationService.getCurationObjectByDatasetId(dataset.id).filter(_.status == ' Published )
618- val curObjectsPermission : List [CurationObject ] = curationService.getCurationObjectByDatasetId(dataset.id).filter(curation => Permission .checkPermission(Permission .EditStagingArea , ResourceRef (ResourceRef .curationObject, curation.id)))
570+ val curObjectsPublished : List [CurationObject ] = curationService.getCurationObjectByDatasetId(dataset.id).filter(
571+ _.status == ' Published )
572+ val curObjectsPermission : List [CurationObject ] = curationService.getCurationObjectByDatasetId(dataset.id).filter(curation =>
573+ Permission .checkPermission(Permission .EditStagingArea , ResourceRef (ResourceRef .curationObject, curation.id)))
619574 val curPubObjects : List [CurationObject ] = curObjectsPublished ::: curObjectsPermission
620575
576+ // download button
621577 var showDownload : Boolean = dataset.files.length > 0
622578 if (! showDownload) {
623579 val foldersList = folders.findByParentDatasetId(dataset.id)
624580 foldersList.map { folder =>
625581 if (folder.files.length > 0 ) { showDownload = true }
626582 }
627583 }
628- var showAccess = false
629584
585+ // access control based on config flags `verifySpaces`, `enablePublic`
586+ var showAccess = false
630587 if (play.Play .application().configuration().getBoolean(" verifySpaces" )) {
631588 showAccess = ! dataset.isTRIAL
632589 } else {
@@ -649,11 +606,13 @@ class Datasets @Inject() (
649606 } else {
650607 accessOptions.append(spaceTitle + " Default (Private)" )
651608 }
652- accessOptions.append(DatasetStatus .PRIVATE .toString.substring(0 , 1 ).toUpperCase() + DatasetStatus .PRIVATE .toString.substring(1 ).toLowerCase())
653- accessOptions.append(DatasetStatus .PUBLIC .toString.substring(0 , 1 ).toUpperCase() + DatasetStatus .PUBLIC .toString.substring(1 ).toLowerCase())
654-
609+ accessOptions.append(DatasetStatus .PRIVATE .toString.substring(0 , 1 ).toUpperCase() +
610+ DatasetStatus .PRIVATE .toString.substring(1 ).toLowerCase())
611+ accessOptions.append(DatasetStatus .PUBLIC .toString.substring(0 , 1 ).toUpperCase() +
612+ DatasetStatus .PUBLIC .toString.substring(1 ).toLowerCase())
655613 val accessData = new models.DatasetAccess (showAccess, access, accessOptions.toList)
656614
615+ // add to collection permissions
657616 var canAddDatasetToCollection = Permission .checkOwner(user, ResourceRef (ResourceRef .dataset, dataset.id))
658617 if (! canAddDatasetToCollection) {
659618 datasetSpaces.map(space =>
@@ -662,18 +621,21 @@ class Datasets @Inject() (
662621 }
663622 )
664623 }
624+
625+ // staging area
665626 val stagingAreaDefined = play.api.Play .current.plugin[services.StagingAreaPlugin ].isDefined
666627
628+ // extraction logs
667629 val extractionsByDataset = extractions.findById(new ResourceRef (' dataset , id))
668630 val extractionGroups = extractions.groupByType(extractionsByDataset)
669631
670- // Increment view count for dataset
632+ // increment view count for dataset
671633 val view_data = datasets.incrementViews(id, user)
672634
673635 // view_data is passed as tuple in dataset case only, because template is at limit of 22 parameters
674- Ok (views.html.dataset(datasetWithFiles , commentsByDataset, filteredPreviewers.toList, m,
675- decodedCollectionsInside.toList, sensors, Some (decodedSpaces_canRemove), fileList ,
676- filesTags, toPublish, curPubObjects, currentSpace, limit, showDownload, accessData, canAddDatasetToCollection,
636+ Ok (views.html.dataset(dataset , commentsByDataset, filteredPreviewers.toList, m,
637+ decodedCollectionsInside.toList, sensors, Some (decodedSpaces_canRemove), toPublish, curPubObjects ,
638+ currentSpace, limit, showDownload, accessData, canAddDatasetToCollection,
677639 stagingAreaDefined, view_data, extractionGroups))
678640 }
679641 case None => {
@@ -698,14 +660,14 @@ class Datasets @Inject() (
698660 case Some (fId) => {
699661 folders.get(UUID (fId)) match {
700662 case Some (folder) => {
701- val (foldersList : List [Folder ], limitFileList : List [File ]) = if (play. Play .application().configuration().getBoolean( " sortInMemory " )) {
702- ( SortingUtils .sortFolders(folder.folders.flatMap(f => folders.get(f)), sortOrder).slice(limit * filepageUpdate, limit * (filepageUpdate + 1 )),
703- SortingUtils .sortFiles (folder.files .flatMap(f => files .get(f)), sortOrder).slice(limit * filepageUpdate - folder.folders.length , limit * (filepageUpdate + 1 ) - folder.folders.length))
704- } else {
705- (folder.folders.reverse.slice(limit * filepageUpdate, limit * (filepageUpdate + 1 )).flatMap(f => folders.get(f)),
706- folder.files .reverse.slice(limit * filepageUpdate - folder.folders.length , limit * (filepageUpdate+ 1 ) - folder.folders.length ).flatMap(f => files .get(f)))
707- }
708-
663+ val (foldersList : List [Folder ], limitFileList : List [File ]) =
664+ if (play. Play .application().configuration().getBoolean( " sortInMemory " )) {
665+ ( SortingUtils .sortFolders (folder.folders .flatMap(f => folders .get(f)), sortOrder).slice(limit * filepageUpdate, limit * (filepageUpdate + 1 )),
666+ SortingUtils .sortFiles(folder.files.flatMap(f => files.get(f)), sortOrder).slice(limit * filepageUpdate - folder.folders.length, limit * (filepageUpdate + 1 ) - folder.folders.length))
667+ } else {
668+ ( folder.folders .reverse.slice(limit * filepageUpdate, limit * (filepageUpdate+ 1 )).flatMap(f => folders .get(f)),
669+ folder.files.reverse.slice(limit * filepageUpdate - folder.folders.length, limit * (filepageUpdate + 1 ) - folder.folders.length).flatMap(f => files.get(f)))
670+ }
709671 var folderHierarchy = new ListBuffer [Folder ]()
710672 folderHierarchy += folder
711673 var f1 : Folder = folder
0 commit comments