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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ registration or heartbeat to Clowder that will restrict use of that extractor to
- Documentation on how to do easy testing of pull requests
- Previewer source URL in the documentation to point to the Clowder GitHub repo. [#395](https://github.com/clowder-framework/clowder/issues/395)
- Added a citation.cff file
- Add sections endpoint to file API and fix missing section routes in javascriptRoutes [#410](https://github.com/clowder-framework/clowder/pull/410)
- Added Google's model viewer within viewer_three.js previewer

### Fixed
Expand Down
13 changes: 13 additions & 0 deletions app/api/Files.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Files @Inject()(
collections: CollectionService,
queries: MultimediaQueryService,
tags: TagService,
sections_service: SectionService,
comments: CommentService,
extractions: ExtractionService,
dtsrequests:ExtractionRequestsService,
Expand Down Expand Up @@ -207,6 +208,18 @@ class Files @Inject()(
}
}

def sections(id: UUID) = PermissionAction(Permission.ViewFile, Some(ResourceRef(ResourceRef.file, id))) { implicit request =>
implicit val user = request.user
files.get(id) match {
case Some(file) => {
val sectionList = sections_service.findByFileId(id)
val sectionIds = sectionList.map { section => section.id }
Ok(toJson(sectionIds))
}
case None => NotFound(toJson("The requested file does not exist"))
}
}

def getMetadataDefinitions(id: UUID, space: Option[String]) = PermissionAction(Permission.AddMetadata, Some(ResourceRef(ResourceRef.file, id))) { implicit request =>
implicit val user = request.user
files.get(id) match {
Expand Down
10 changes: 8 additions & 2 deletions app/api/Sections.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ class Sections @Inject()(
Logger.debug("Getting info for section with id " + id)
sections.get(id) match {
case Some(section) =>
Ok(Json.obj("id" -> section.id.toString, "file_id" -> section.file_id.toString,
"startTime" -> section.startTime.getOrElse(-1).toString, "tags" -> Json.toJson(section.tags.map(_.name))))
Ok(Json.obj(
"id" -> section.id.toString,
"file_id" -> section.file_id.toString,
"startTime" -> section.startTime.getOrElse(-1).toString,
"tags" -> Json.toJson(section.tags.map(_.name)),
"area" -> Json.toJson(section.area.getOrElse(null)),
"description" -> Json.toJson(section.description.getOrElse(""))
))
case None => Logger.error("Section not found " + id); NotFound(toJson("Section not found, id: " + id))
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class Application @Inject()(files: FileService, collections: CollectionService,
api.routes.javascript.Files.unfollow,
api.routes.javascript.Files.getTechnicalMetadataJSON,
api.routes.javascript.Files.filePreviewsList,
api.routes.javascript.Files.sections,
api.routes.javascript.Files.updateMetadata,
api.routes.javascript.Files.addMetadata,
api.routes.javascript.Files.getMetadataDefinitions,
Expand All @@ -382,7 +383,9 @@ class Application @Inject()(files: FileService, collections: CollectionService,
api.routes.javascript.Search.search,
api.routes.javascript.Search.searchJson,
api.routes.javascript.Sections.add,
api.routes.javascript.Sections.get,
api.routes.javascript.Sections.delete,
api.routes.javascript.Sections.description,
api.routes.javascript.Sections.comment,
api.routes.javascript.Sections.getTags,
api.routes.javascript.Sections.addTags,
Expand Down
12 changes: 12 additions & 0 deletions app/models/Section.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ case class Rectangle(
h: Double) {
override def toString() = f"x: $x%.2f, y: $y%.2f, width: $w%.2f, height: $h%.2f"
}

object Rectangle {
implicit object RectangleWrites extends Writes[Rectangle] {
def writes(rectangle: Rectangle): JsObject = {
Json.obj(
"x" -> rectangle.x,
"y" -> rectangle.y,
"w" -> rectangle.w,
"h" -> rectangle.h)
}
}
}
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ GET /api/files/:id/blob
POST /api/files/:id/remove @api.Files.removeFile(id: UUID)
POST /api/files/bulkRemove @api.Files.bulkDeleteFiles()
GET /api/files/:id/metadata @api.Files.get(id: UUID)
GET /api/files/:id/sections @api.Files.sections(id: UUID)
POST /api/files/:id/metadata @api.Files.addMetadata(id: UUID)
GET /api/files/:id/metadataDefinitions @api.Files.getMetadataDefinitions(id: UUID, space: Option[String] ?= None)
POST /api/files/:id/updateMetadata @api.Files.updateMetadata(id: UUID, extractor_id: String)
Expand Down
26 changes: 26 additions & 0 deletions public/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,32 @@ paths:
404:
$ref: '#/components/responses/NotFound'

/files/{id}/sections:
get:
tags:
- files
summary: Get the sections of a file
description: |
Get the sections of a file.
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UUID'
404:
$ref: '#/components/responses/NotFound'


/files/{id}/paths:
get:
tags:
Expand Down