Skip to content

Commit 15bd2e7

Browse files
LDeakinlmarini
andauthored
Add some missing sections endpoints (#410)
* Add some missing sections endpoints * rename getSections endpoint to sections * Fix name clash in 61f451d --------- Co-authored-by: Luigi Marini <[email protected]>
1 parent 1e94e14 commit 15bd2e7

File tree

7 files changed

+64
-2
lines changed

7 files changed

+64
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ registration or heartbeat to Clowder that will restrict use of that extractor to
2525
- Documentation on how to do easy testing of pull requests
2626
- Previewer source URL in the documentation to point to the Clowder GitHub repo. [#395](https://github.com/clowder-framework/clowder/issues/395)
2727
- Added a citation.cff file
28+
- Add sections endpoint to file API and fix missing section routes in javascriptRoutes [#410](https://github.com/clowder-framework/clowder/pull/410)
2829
- Added Google's model viewer within viewer_three.js previewer
2930

3031
### Fixed

app/api/Files.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Files @Inject()(
3232
collections: CollectionService,
3333
queries: MultimediaQueryService,
3434
tags: TagService,
35+
sections_service: SectionService,
3536
comments: CommentService,
3637
extractions: ExtractionService,
3738
dtsrequests:ExtractionRequestsService,
@@ -207,6 +208,18 @@ class Files @Inject()(
207208
}
208209
}
209210

211+
def sections(id: UUID) = PermissionAction(Permission.ViewFile, Some(ResourceRef(ResourceRef.file, id))) { implicit request =>
212+
implicit val user = request.user
213+
files.get(id) match {
214+
case Some(file) => {
215+
val sectionList = sections_service.findByFileId(id)
216+
val sectionIds = sectionList.map { section => section.id }
217+
Ok(toJson(sectionIds))
218+
}
219+
case None => NotFound(toJson("The requested file does not exist"))
220+
}
221+
}
222+
210223
def getMetadataDefinitions(id: UUID, space: Option[String]) = PermissionAction(Permission.AddMetadata, Some(ResourceRef(ResourceRef.file, id))) { implicit request =>
211224
implicit val user = request.user
212225
files.get(id) match {

app/api/Sections.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ class Sections @Inject()(
6767
Logger.debug("Getting info for section with id " + id)
6868
sections.get(id) match {
6969
case Some(section) =>
70-
Ok(Json.obj("id" -> section.id.toString, "file_id" -> section.file_id.toString,
71-
"startTime" -> section.startTime.getOrElse(-1).toString, "tags" -> Json.toJson(section.tags.map(_.name))))
70+
Ok(Json.obj(
71+
"id" -> section.id.toString,
72+
"file_id" -> section.file_id.toString,
73+
"startTime" -> section.startTime.getOrElse(-1).toString,
74+
"tags" -> Json.toJson(section.tags.map(_.name)),
75+
"area" -> Json.toJson(section.area.getOrElse(null)),
76+
"description" -> Json.toJson(section.description.getOrElse(""))
77+
))
7278
case None => Logger.error("Section not found " + id); NotFound(toJson("Section not found, id: " + id))
7379
}
7480
}

app/controllers/Application.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ class Application @Inject()(files: FileService, collections: CollectionService,
369369
api.routes.javascript.Files.unfollow,
370370
api.routes.javascript.Files.getTechnicalMetadataJSON,
371371
api.routes.javascript.Files.filePreviewsList,
372+
api.routes.javascript.Files.sections,
372373
api.routes.javascript.Files.updateMetadata,
373374
api.routes.javascript.Files.addMetadata,
374375
api.routes.javascript.Files.getMetadataDefinitions,
@@ -382,7 +383,9 @@ class Application @Inject()(files: FileService, collections: CollectionService,
382383
api.routes.javascript.Search.search,
383384
api.routes.javascript.Search.searchJson,
384385
api.routes.javascript.Sections.add,
386+
api.routes.javascript.Sections.get,
385387
api.routes.javascript.Sections.delete,
388+
api.routes.javascript.Sections.description,
386389
api.routes.javascript.Sections.comment,
387390
api.routes.javascript.Sections.getTags,
388391
api.routes.javascript.Sections.addTags,

app/models/Section.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,15 @@ case class Rectangle(
3333
h: Double) {
3434
override def toString() = f"x: $x%.2f, y: $y%.2f, width: $w%.2f, height: $h%.2f"
3535
}
36+
37+
object Rectangle {
38+
implicit object RectangleWrites extends Writes[Rectangle] {
39+
def writes(rectangle: Rectangle): JsObject = {
40+
Json.obj(
41+
"x" -> rectangle.x,
42+
"y" -> rectangle.y,
43+
"w" -> rectangle.w,
44+
"h" -> rectangle.h)
45+
}
46+
}
47+
}

conf/routes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ GET /api/files/:id/blob
390390
POST /api/files/:id/remove @api.Files.removeFile(id: UUID)
391391
POST /api/files/bulkRemove @api.Files.bulkDeleteFiles()
392392
GET /api/files/:id/metadata @api.Files.get(id: UUID)
393+
GET /api/files/:id/sections @api.Files.sections(id: UUID)
393394
POST /api/files/:id/metadata @api.Files.addMetadata(id: UUID)
394395
GET /api/files/:id/metadataDefinitions @api.Files.getMetadataDefinitions(id: UUID, space: Option[String] ?= None)
395396
POST /api/files/:id/updateMetadata @api.Files.updateMetadata(id: UUID, extractor_id: String)

public/swagger.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,32 @@ paths:
351351
404:
352352
$ref: '#/components/responses/NotFound'
353353

354+
/files/{id}/sections:
355+
get:
356+
tags:
357+
- files
358+
summary: Get the sections of a file
359+
description: |
360+
Get the sections of a file.
361+
parameters:
362+
- name: id
363+
in: path
364+
required: true
365+
schema:
366+
type: string
367+
responses:
368+
200:
369+
description: OK
370+
content:
371+
application/json:
372+
schema:
373+
type: array
374+
items:
375+
$ref: '#/components/schemas/UUID'
376+
404:
377+
$ref: '#/components/responses/NotFound'
378+
379+
354380
/files/{id}/paths:
355381
get:
356382
tags:

0 commit comments

Comments
 (0)