From a87c340ca3ae4bda2e859382c3cb157d508e6f77 Mon Sep 17 00:00:00 2001 From: Jack Brinkman Date: Mon, 11 Dec 2023 11:32:34 +1000 Subject: [PATCH] Updated image metadata endpoint to include opusId --- gradle.properties | 2 +- .../javascripts/profileEditor/directives/imageUpload.js | 2 +- .../javascripts/profileEditor/services/ProfileService.js | 6 +++--- .../au/org/ala/profile/hub/ProfileController.groovy | 6 +++--- .../controllers/au/org/ala/profile/hub/UrlMappings.groovy | 3 +-- .../services/au/org/ala/profile/hub/ImageService.groovy | 4 ++-- src/test/js/specs/services/ProfileServiceSpec.js | 4 ++-- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4906e9dd..d9601d6c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -profileHubVersion=4.2 +profileHubVersion=4.2.1-SNAPSHOT grailsVersion=5.2.4 grailsGradlePluginVersion=5.2.3 groovyVersion=3.0.11 diff --git a/grails-app/assets/javascripts/profileEditor/directives/imageUpload.js b/grails-app/assets/javascripts/profileEditor/directives/imageUpload.js index 271ae4ee..3f021c82 100644 --- a/grails-app/assets/javascripts/profileEditor/directives/imageUpload.js +++ b/grails-app/assets/javascripts/profileEditor/directives/imageUpload.js @@ -103,7 +103,7 @@ profileEditor.directive('imageUpload', function ($browser, $http, config) { $scope.metadata.created = util.formatLocalDate($scope.metadata.created); $cacheFactory.get('$http').removeAll(); - profileService.saveImageMetadata($scope.image.imageId, $scope.metadata).then(function(data) { + profileService.saveImageMetadata($scope.opusId, $scope.image.imageId, $scope.metadata).then(function(data) { if (angular.isDefined($scope.callbackHandler)) { $scope.callbackHandler(data); } diff --git a/grails-app/assets/javascripts/profileEditor/services/ProfileService.js b/grails-app/assets/javascripts/profileEditor/services/ProfileService.js index 3e5dd931..5924513f 100644 --- a/grails-app/assets/javascripts/profileEditor/services/ProfileService.js +++ b/grails-app/assets/javascripts/profileEditor/services/ProfileService.js @@ -586,12 +586,12 @@ profileEditor.service('profileService', function ($http, util, $cacheFactory, co return util.toStandardPromise(future); }, - saveImageMetadata: function(imageId, data) { + saveImageMetadata: function(opusId, imageId, data) { $log.debug("Saving image metadata: " + imageId); var future = null; - if (imageId) { + if (opusId && imageId) { future = enqueue(function() { - return $http.post(util.contextRoot() + "/image/" + imageId + "/metadata", data) + return $http.post(util.contextRoot() + "/opus/" + opusId + "/image/" + imageId + "/metadata", data) }); } diff --git a/grails-app/controllers/au/org/ala/profile/hub/ProfileController.groovy b/grails-app/controllers/au/org/ala/profile/hub/ProfileController.groovy index ac5921b6..27026ee7 100644 --- a/grails-app/controllers/au/org/ala/profile/hub/ProfileController.groovy +++ b/grails-app/controllers/au/org/ala/profile/hub/ProfileController.groovy @@ -172,10 +172,10 @@ class ProfileController extends BaseController { @Secured(role = ROLE_PROFILE_EDITOR) def updateLocalImageMetadata() { def metadata = request.getJSON() - if (!params.imageId || !metadata) { - badRequest "imageId or metadata is required" + if (!params.opusId || !params.imageId || !metadata) { + badRequest "opusId, imageId and metadata is required" } else { - handle imageService.updateLocalImageMetadata(params.imageId, metadata) + handle imageService.updateLocalImageMetadata(params.opusId, params.imageId, metadata) } } diff --git a/grails-app/controllers/au/org/ala/profile/hub/UrlMappings.groovy b/grails-app/controllers/au/org/ala/profile/hub/UrlMappings.groovy index fab17344..8786a5f6 100644 --- a/grails-app/controllers/au/org/ala/profile/hub/UrlMappings.groovy +++ b/grails-app/controllers/au/org/ala/profile/hub/UrlMappings.groovy @@ -122,6 +122,7 @@ class UrlMappings { "/opus/$opusId/statistics" controller: "statistics", action: [GET: "index"] "/opus/$opusId/image/$filename" controller: "opus", action: [GET: "downloadImage", DELETE: "deleteImage"] + "/opus/$opusId/image/$imageId/metadata" controller: "profile", action: [POST: "updateLocalImageMetadata"] "/opus/$opusId/image" controller: "opus", action: [POST: "uploadImage", PUT: "uploadImage"] "/opus/$opusId/update" controller: "opus", action: [GET: "edit", POST: "updateOpus"] @@ -187,8 +188,6 @@ class UrlMappings { "/publication/$pubId" controller: "profile", action: [GET: "getPublication"] "/publication/$pubId/json" controller: "profile", action: [GET: "getPublicationJson"] - "/image/$imageId/metadata" controller: "profile", action: [POST: "updateLocalImageMetadata"] - "/" controller: "opus", action: [GET: "index"] "/logout/logout" controller: "logout", action: "logout" diff --git a/grails-app/services/au/org/ala/profile/hub/ImageService.groovy b/grails-app/services/au/org/ala/profile/hub/ImageService.groovy index 0c8c97d9..45762343 100644 --- a/grails-app/services/au/org/ala/profile/hub/ImageService.groovy +++ b/grails-app/services/au/org/ala/profile/hub/ImageService.groovy @@ -668,8 +668,8 @@ class ImageService { return ImageOption.byName(displayOptionStr, defaultOption) == ImageOption.INCLUDE } - def updateLocalImageMetadata(String imageId, Map metadata) { - webService.post("${grailsApplication.config.profile.service.url}/image/${encPath(imageId)}/metadata", metadata, [:], ContentType.APPLICATION_JSON, true, false, profileService.getCustomHeaderWithUserId()) + def updateLocalImageMetadata(String opusId, String imageId, Map metadata) { + webService.post("${grailsApplication.config.profile.service.url}/opus/${opusId}/image/${encPath(imageId)}/metadata", metadata, [:], ContentType.APPLICATION_JSON, true, false, profileService.getCustomHeaderWithUserId()) } def publishPrivateImage(String opusId, String profileId, String imageId) { diff --git a/src/test/js/specs/services/ProfileServiceSpec.js b/src/test/js/specs/services/ProfileServiceSpec.js index 5eab2231..bd2a47c5 100644 --- a/src/test/js/specs/services/ProfileServiceSpec.js +++ b/src/test/js/specs/services/ProfileServiceSpec.js @@ -428,9 +428,9 @@ describe("ProfileService tests", function () { it("should invoke the updateLocalImageMetadata service on the context root when saveImageMetadata is called", function() { var data = {creator: "one", createdDate: new Date(), rights: "rights", licence: "licence"}; - service.saveImageMetadata('abcdefghijlkmnop', data); + service.saveImageMetadata('opusId', 'abcdefghijlkmnop', data); - http.expectPOST("/someContext/image/abcdefghijlkmnop/metadata", data).respond("bla"); + http.expectPOST("/someContext/opus/opusId/image/abcdefghijlkmnop/metadata", data).respond("bla"); }); it("should invoke GET request when getImageMetadata is called", function() {