diff --git a/grails-app/controllers/au/org/ala/profile/ImageController.groovy b/grails-app/controllers/au/org/ala/profile/ImageController.groovy index 107b0a5..08e018f 100644 --- a/grails-app/controllers/au/org/ala/profile/ImageController.groovy +++ b/grails-app/controllers/au/org/ala/profile/ImageController.groovy @@ -18,9 +18,10 @@ class ImageController extends BaseController { def updateMetadata() { String imageId = params.imageId + String opusId = params.opusId final metadata = request.getJSON() - if (!imageId || !metadata) { - badRequest "imageId and request body are required parameters" + if (!opusId || !imageId || !metadata) { + badRequest "opusId, imageId and request body are required parameters" } else { def image = localImageService.updateMetadata(imageId, metadata) render image as JSON diff --git a/grails-app/controllers/au/org/ala/profile/UrlMappings.groovy b/grails-app/controllers/au/org/ala/profile/UrlMappings.groovy index 411899a..2b380d5 100644 --- a/grails-app/controllers/au/org/ala/profile/UrlMappings.groovy +++ b/grails-app/controllers/au/org/ala/profile/UrlMappings.groovy @@ -118,6 +118,9 @@ class UrlMappings { "/opus/$opusId/restore/$profileId" controller: "profile", action: [POST: "restoreArchivedProfile"] "/opus/$opusId/reindex" controller: "opus", action: [POST: "reindex"] + "/opus/$opusId/image/$imageId/metadata" controller: "image", action: [GET: "getImageInfo", POST: "updateMetadata"] + "/image/$imageId" controller: "image", action: [GET: "getImageInfo"] + "/checkName" controller: "profile", action: [GET: "checkName"] "/report/archivedProfiles" controller: "report", action: [GET: "archivedProfiles"] @@ -131,9 +134,6 @@ class UrlMappings { "/job/$jobType" controller: "job", action: [GET: "listAllPendingJobs", PUT: "createJob"] "/job/" controller: "job", action: [GET: "listAllPendingJobs", PUT: "createJob"] - "/image/$imageId" controller: "image", action: [GET: "getImageInfo"] - "/image/$imageId/metadata" controller: "image", action: [GET: "getImageInfo", POST: "updateMetadata"] - "/statistics/" controller: "statistics", action: [GET: "index"] "/import/profile" controller: "import", action: [POST: "profile"] diff --git a/src/scripts/FOAImport.groovy b/src/scripts/FOAImport.groovy index bd510ee..6e9cd0d 100644 --- a/src/scripts/FOAImport.groovy +++ b/src/scripts/FOAImport.groovy @@ -27,15 +27,17 @@ class FOAImport { static String PROFILE_SERVICE_IMPORT_URL static String PROFILE_SERVICE_REPORT_URL static String DELIMITER + static String ACCESS_TOKEN static void main(args) { - def cli = new CliBuilder(usage: "groovy FOAImport -f -o opusId -p -d -r ") + def cli = new CliBuilder(usage: "groovy FOAImport -f -o opusId -p -d -r -a ") cli.f(longOpt: "dir", "source data directory", required: true, args: 1) cli.o(longOpt: "opusId", "UUID of the FOA Opus", required: true, args: 1) cli.p(longOpt: "profileServiceBaseUrl", "Base URL of the profile service", required: true, args: 1) cli.d(longOpt: "delimiter", "Data file delimiter (defaults to ,)", required: false, args: 1) cli.r(longOpt: "reportFile", "File to write the results of the import to", required: false, args: 1) + cli.a(longOpt: "accessToken", "Bearer token to access profiles service", required: true, args: 1) OptionAccessor opt = cli.parse(args) @@ -50,6 +52,7 @@ class FOAImport { PROFILE_SERVICE_IMPORT_URL = "${opt.p}/import/profile" PROFILE_SERVICE_REPORT_URL = "${opt.p}/" DELIMITER = opt.d ?: "," + ACCESS_TOKEN = opt.a ?: "" List profiles = [] @@ -104,7 +107,7 @@ class FOAImport { StringBuilder volume = new StringBuilder("

") volume.append(cleanupText(line.VOLUME_REFERENCE)) volume.append("

") - attributes << [title: "Source citation", text: volume.toString(), creators: [], stripHtml: false] +// attributes << [title: "Source citation", text: volume.toString(), creators: [], stripHtml: false] String author = attrs ? attrs["Author"]?.join(", ") : null @@ -135,6 +138,8 @@ class FOAImport { println "Importing ${profiles.size()} profiles..." println(PROFILE_SERVICE_IMPORT_URL) def service = new RESTClient(PROFILE_SERVICE_IMPORT_URL) + service.setHeaders(["Authorization": "Bearer ${ACCESS_TOKEN}"]) + service.handler.failure = { resp -> println "Unexpected failure: ${resp.statusLine}" } def resp = service.post(body: opus, requestContentType: JSON) @@ -148,6 +153,8 @@ class FOAImport { Thread.sleep(sleepTime) service = new RESTClient("${PROFILE_SERVICE_REPORT_URL}import/${importId}/report") + service.setHeaders(["Authorization": "Bearer ${ACCESS_TOKEN}"]) + service.handler.failure = { re -> println "Unexpected failure: ${re.statusLine}" } resp = service.get([:]).data while (resp.status == "IN_PROGRESS") { @@ -249,7 +256,7 @@ class FOAImport { println "Failed to extract attribute titles from line [${line}]" } } - + println "Loaded ${attributeTitles.size()} attribute titles" attributeTitles } @@ -274,6 +281,7 @@ class FOAImport { } } + println "Loaded ${attributes.size()} taxa attributes" attributes } diff --git a/src/scripts/UpdateProfileAttribute.groovy b/src/scripts/UpdateProfileAttribute.groovy index 762aa3d..d59df58 100644 --- a/src/scripts/UpdateProfileAttribute.groovy +++ b/src/scripts/UpdateProfileAttribute.groovy @@ -47,9 +47,10 @@ class UpdateProfileAttribute { static String USER_DISPLAY_NAME static String OUTPUT_FILE static String IMPORT_OUTPUT_FILE + static String ACCESS_TOKEN static void main(args) { - def cli = new CliBuilder(usage: "groovy UpdateProfileAttribute -f -o opusId -p -u -r ") + def cli = new CliBuilder(usage: "groovy UpdateProfileAttribute -f -o opusId -p -u -r -a ") cli.f(longOpt: "dir", "source data directory", required: true, args: 1) cli.o(longOpt: "opusId", "UUID of the FOA Opus", required: true, args: 1) cli.p(longOpt: "profileServiceBaseUrl", "Base URL of the profile service", required: true, args: 1) @@ -57,6 +58,7 @@ class UpdateProfileAttribute { cli.d(longOpt: "displayName", "Display name of a ALA user importing script", required: true, args: 1) cli.i(longOpt: "importFile", "Email address of the ALA user importing script", required: true, args: 1) cli.r(longOpt: "reportFile", "File to write the results of the import to", required: false, args: 1) + cli.a(longOpt: "accessToken", "Bearer token to access profiles service", required: true, args: 1) OptionAccessor opt = cli.parse(args) if(!opt) { @@ -71,7 +73,8 @@ class UpdateProfileAttribute { DATA_DIR = opt.f IMPORT_OUTPUT_FILE = opt.i OUTPUT_FILE = opt.r ?: "updatedAttributes.json" - ATTRIBUTE_OPTION = OVERWRITE + ACCESS_TOKEN = opt.a ?: "" + ATTRIBUTE_OPTION = APPEND Map attributeTitles = loadAttributeTitles() Map>> taxaAttributes = loadAttributes(attributeTitles) @@ -94,6 +97,7 @@ class UpdateProfileAttribute { println PROFILE_SERVICE_PROFILE_URL RESTClient client = new RESTClient(PROFILE_SERVICE_PROFILE_URL) + client.setHeaders(["Authorization": "Bearer ${ACCESS_TOKEN}"]) def resp = client.get([:]) def profile = resp.getData() println new JsonBuilder(profile).toPrettyString() @@ -128,6 +132,7 @@ class UpdateProfileAttribute { try { if (body.text != attribute?.text) { client = new RESTClient(ATTRIBUTE_URL) + client.setHeaders(["Authorization": "Bearer ${ACCESS_TOKEN}"]) def respData = client.post(body: body, requestContentType: JSON) if (respData.success) { println "Successfully updated $PROFILE_ID $name" @@ -166,7 +171,7 @@ class UpdateProfileAttribute { switch (ATTRIBUTE_OPTION) { case APPEND: if (!attribute.text?.contains(additionalContent)) { - return attribute.text + decorateText(additionalContent) + return attribute.text + "
--------------------
"+ decorateText(additionalContent) } return attribute.text