From 02aeba89d7f887e4f2ce2936d83c85cc05dfc4eb Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Thu, 20 Apr 2023 10:40:19 +1000 Subject: [PATCH 1/3] Add some missing sections endpoints --- CHANGELOG.md | 1 + app/api/Files.scala | 13 +++++++++++++ app/api/Sections.scala | 10 ++++++++-- app/controllers/Application.scala | 3 +++ app/models/Section.scala | 12 ++++++++++++ conf/routes | 1 + public/swagger.yml | 26 ++++++++++++++++++++++++++ 7 files changed, 64 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5d811d50..fd81f5541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,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 getSections to file API and fix missing section routes in javascriptRoutes [#410](https://github.com/clowder-framework/clowder/pull/410) ### Fixed - Updated lastModifiesDate when updating file or metadata to a dataset, added lastModified to UI [386](https://github.com/clowder-framework/clowder/issues/386) diff --git a/app/api/Files.scala b/app/api/Files.scala index 18c0602b8..aad723cb1 100644 --- a/app/api/Files.scala +++ b/app/api/Files.scala @@ -32,6 +32,7 @@ class Files @Inject()( collections: CollectionService, queries: MultimediaQueryService, tags: TagService, + sections: SectionService, comments: CommentService, extractions: ExtractionService, dtsrequests:ExtractionRequestsService, @@ -207,6 +208,18 @@ class Files @Inject()( } } + def getSections(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.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 { diff --git a/app/api/Sections.scala b/app/api/Sections.scala index 0b7abf8c9..0e15460f4 100644 --- a/app/api/Sections.scala +++ b/app/api/Sections.scala @@ -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)) } } diff --git a/app/controllers/Application.scala b/app/controllers/Application.scala index 344474f35..5e7e4ac25 100644 --- a/app/controllers/Application.scala +++ b/app/controllers/Application.scala @@ -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.getSections, api.routes.javascript.Files.updateMetadata, api.routes.javascript.Files.addMetadata, api.routes.javascript.Files.getMetadataDefinitions, @@ -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, diff --git a/app/models/Section.scala b/app/models/Section.scala index 59f40c85c..8bf5da309 100644 --- a/app/models/Section.scala +++ b/app/models/Section.scala @@ -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) + } + } +} diff --git a/conf/routes b/conf/routes index 9ab4f1b56..0120fcff9 100644 --- a/conf/routes +++ b/conf/routes @@ -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/getSections @api.Files.getSections(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) diff --git a/public/swagger.yml b/public/swagger.yml index b76ba7c2a..e6a662507 100644 --- a/public/swagger.yml +++ b/public/swagger.yml @@ -351,6 +351,32 @@ paths: 404: $ref: '#/components/responses/NotFound' + /files/{id}/getSections: + 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: From 61f451d50d9871f06d1fa9b47f570c69d5075c38 Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Tue, 12 Sep 2023 13:54:45 +1000 Subject: [PATCH 2/3] rename getSections endpoint to sections --- CHANGELOG.md | 2 +- app/api/Files.scala | 2 +- app/controllers/Application.scala | 2 +- conf/routes | 2 +- public/swagger.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd81f5541..476f1931e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,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 getSections to file API and fix missing section routes in javascriptRoutes [#410](https://github.com/clowder-framework/clowder/pull/410) +- Add sections endpoint to file API and fix missing section routes in javascriptRoutes [#410](https://github.com/clowder-framework/clowder/pull/410) ### Fixed - Updated lastModifiesDate when updating file or metadata to a dataset, added lastModified to UI [386](https://github.com/clowder-framework/clowder/issues/386) diff --git a/app/api/Files.scala b/app/api/Files.scala index aad723cb1..bbe768ef7 100644 --- a/app/api/Files.scala +++ b/app/api/Files.scala @@ -208,7 +208,7 @@ class Files @Inject()( } } - def getSections(id: UUID) = PermissionAction(Permission.ViewFile, Some(ResourceRef(ResourceRef.file, id))) { implicit request => + 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) => { diff --git a/app/controllers/Application.scala b/app/controllers/Application.scala index 5e7e4ac25..34cd2a0fa 100644 --- a/app/controllers/Application.scala +++ b/app/controllers/Application.scala @@ -369,7 +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.getSections, + api.routes.javascript.Files.sections, api.routes.javascript.Files.updateMetadata, api.routes.javascript.Files.addMetadata, api.routes.javascript.Files.getMetadataDefinitions, diff --git a/conf/routes b/conf/routes index 0120fcff9..786757f97 100644 --- a/conf/routes +++ b/conf/routes @@ -390,7 +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/getSections @api.Files.getSections(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) diff --git a/public/swagger.yml b/public/swagger.yml index e6a662507..c312d4462 100644 --- a/public/swagger.yml +++ b/public/swagger.yml @@ -351,7 +351,7 @@ paths: 404: $ref: '#/components/responses/NotFound' - /files/{id}/getSections: + /files/{id}/sections: get: tags: - files From 3384f721896d1c7af36969bab80e33d1c6341a11 Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Tue, 12 Sep 2023 16:14:27 +1000 Subject: [PATCH 3/3] Fix name clash in 61f451d50 --- app/api/Files.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/api/Files.scala b/app/api/Files.scala index bbe768ef7..1bcb50fa5 100644 --- a/app/api/Files.scala +++ b/app/api/Files.scala @@ -32,7 +32,7 @@ class Files @Inject()( collections: CollectionService, queries: MultimediaQueryService, tags: TagService, - sections: SectionService, + sections_service: SectionService, comments: CommentService, extractions: ExtractionService, dtsrequests:ExtractionRequestsService, @@ -212,7 +212,7 @@ class Files @Inject()( implicit val user = request.user files.get(id) match { case Some(file) => { - val sectionList = sections.findByFileId(id) + val sectionList = sections_service.findByFileId(id) val sectionIds = sectionList.map { section => section.id } Ok(toJson(sectionIds)) }