Skip to content

Commit 4c97cd1

Browse files
max-zillalmarini
andauthored
Make space ID optional on storage reports (#152)
* Make space ID optional on storage reports * Change paramenters definition to `query` for `/reports/storage/spaces` * Fixed CHANGELOG.md Co-authored-by: Luigi Marini <[email protected]>
1 parent 4f92b61 commit 4c97cd1

File tree

8 files changed

+23
-16
lines changed

8 files changed

+23
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
### Added
1010
- Added a new `/api/reports/metrics/extractors` report for summarizing extractor usage by user.
1111

12+
### Changed
13+
- api/reports/storage/spaces endpoint now accepts a space parameter for ID rather than requiring a space filter.
14+
1215
## 1.13.0 - 2020-12-02
1316

1417
### Added

app/api/Reporting.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ class Reporting @Inject()(selections: SelectionService,
396396
return contents
397397
}
398398

399-
def spaceStorage(id: UUID, since: Option[String], until: Option[String]) = ServerAdminAction { implicit request =>
399+
def spaceStorage(space: Option[String], since: Option[String], until: Option[String]) = ServerAdminAction { implicit request =>
400400
// Iterate over the files of every dataset in the space
401-
val results = datasets.getIterator(Some(id), None, None) // TODO: Can't use time filters here if user intends files
401+
val results = datasets.getIterator(space, None, None) // TODO: Can't use time filters here if user intends files
402402

403403
var headerRow = true
404404
val enum = Enumerator.generateM({
@@ -497,9 +497,13 @@ class Reporting @Inject()(selections: SelectionService,
497497
Future(chunk)
498498
})
499499

500+
val filename = space match {
501+
case Some(spid) => "SpaceStorage_"+spid+".csv"
502+
case None => "SpaceStorage.csv"
503+
}
500504
Ok.chunked(enum.andThen(Enumerator.eof)).withHeaders(
501505
"Content-Type" -> "text/csv",
502-
"Content-Disposition" -> ("attachment; filename=SpaceStorage"+id.stringify+".csv")
506+
"Content-Disposition" -> ("attachment; filename="+filename)
503507
)
504508
}
505509

app/services/DatasetService.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,6 @@ trait DatasetService {
383383

384384
def incrementDownloads(id: UUID, user: Option[User])
385385

386-
def getIterator(space: Option[UUID], since: Option[String], until: Option[String]): Iterator[Dataset]
386+
def getIterator(space: Option[String], since: Option[String], until: Option[String]): Iterator[Dataset]
387387

388388
}

app/services/FileService.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,6 @@ trait FileService {
246246

247247
def incrementDownloads(id: UUID, user: Option[User])
248248

249-
def getIterator(space: Option[UUID], since: Option[String], until: Option[String]): Iterator[File]
249+
def getIterator(space: Option[String], since: Option[String], until: Option[String]): Iterator[File]
250250

251251
}

app/services/mongodb/MongoDBDatasetService.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,9 +1641,9 @@ class MongoDBDatasetService @Inject() (
16411641
* @param since - include only datasets created after a certain date
16421642
* @param until - include only datasets created before a certain date
16431643
*/
1644-
def getIterator(space: Option[UUID], since: Option[String], until: Option[String]): Iterator[Dataset] = {
1644+
def getIterator(space: Option[String], since: Option[String], until: Option[String]): Iterator[Dataset] = {
16451645
var query = MongoDBObject("trash" -> false)
1646-
space.foreach(spid => query += ("spaces" -> new ObjectId(spid.stringify)))
1646+
space.foreach(spid => query += ("spaces" -> new ObjectId(spid)))
16471647
since.foreach(t => query = query ++ ("created" $gte Parsers.fromISO8601(t)))
16481648
until.foreach(t => query = query ++ ("created" $lte Parsers.fromISO8601(t)))
16491649
Dataset.find(query)

app/services/mongodb/MongoDBFileService.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ class MongoDBFileService @Inject() (
12151215
}
12161216
}
12171217

1218-
def getIterator(space: Option[UUID], since: Option[String], until: Option[String]): Iterator[File] = {
1218+
def getIterator(space: Option[String], since: Option[String], until: Option[String]): Iterator[File] = {
12191219
var query = MongoDBObject()
12201220
space.foreach(spid => {
12211221
// If space is specified, we have to get that association from datasets for now

conf/routes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ GET /api/reports/metrics/datasets
756756
GET /api/reports/metrics/collections @api.Reporting.collectionMetrics()
757757
GET /api/reports/metrics/spaces @api.Reporting.spaceMetrics()
758758
GET /api/reports/metrics/users @api.Reporting.userMetrics()
759-
GET /api/reports/storage/spaces/:id @api.Reporting.spaceStorage(id: UUID, since: Option[String] ?= None, until: Option[String] ?= None)
759+
GET /api/reports/storage/spaces @api.Reporting.spaceStorage(space: Option[String] ?= None, since: Option[String] ?= None, until: Option[String] ?= None)
760760
GET /api/reports/metrics/extractors @api.Reporting.extractorUsage(since: Option[String] ?= None, until: Option[String] ?= None)
761761

762762

public/swagger.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4995,27 +4995,27 @@ paths:
49954995
description: Not authorized
49964996
content: {}
49974997

4998-
/reports/storage/spaces/{id}:
4998+
/reports/storage/spaces:
49994999
get:
50005000
tags:
50015001
- reporting
50025002
summary: Download storage metrics report for spaces as CSV.
50035003
description: |
5004-
Download storage metrics report for files in a space as a CSV file.
5004+
Download storage metrics report for files in a space as a CSV file. Space id is optional parameter.
50055005
Must be a server admin to access the report. Supports ISO8601 date range filters.
50065006
parameters:
5007-
- name: id
5008-
in: path
5009-
required: true
5007+
- name: space
5008+
in: query
5009+
required: false
50105010
schema:
50115011
type: string
50125012
- name: since
5013-
in: path
5013+
in: query
50145014
required: false
50155015
schema:
50165016
type: string
50175017
- name: until
5018-
in: path
5018+
in: query
50195019
required: false
50205020
schema:
50215021
type: string

0 commit comments

Comments
 (0)