Skip to content

Commit

Permalink
Merge branch 'master' into hotfix/5.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-brinkman authored Dec 15, 2023
2 parents 178b8d6 + 7c3aa4c commit 57d5147
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions grails-app/controllers/au/org/ala/profile/UrlMappings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down
14 changes: 11 additions & 3 deletions src/scripts/FOAImport.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 <datadir> -o opusId -p <profileServiceBaseUrl> -d <delimiter default ,> -r <reportfile>")
def cli = new CliBuilder(usage: "groovy FOAImport -f <datadir> -o opusId -p <profileServiceBaseUrl> -d <delimiter default ,> -r <reportfile> -a <accessToken>")
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)

Expand All @@ -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 = []

Expand Down Expand Up @@ -104,7 +107,7 @@ class FOAImport {
StringBuilder volume = new StringBuilder("<p>")
volume.append(cleanupText(line.VOLUME_REFERENCE))
volume.append("</p>")
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

Expand Down Expand Up @@ -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)

Expand All @@ -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") {
Expand Down Expand Up @@ -249,7 +256,7 @@ class FOAImport {
println "Failed to extract attribute titles from line [${line}]"
}
}

println "Loaded ${attributeTitles.size()} attribute titles"
attributeTitles
}

Expand All @@ -274,6 +281,7 @@ class FOAImport {
}
}

println "Loaded ${attributes.size()} taxa attributes"
attributes
}

Expand Down
11 changes: 8 additions & 3 deletions src/scripts/UpdateProfileAttribute.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ 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 <datadir> -o opusId -p <profileServiceBaseUrl> -u <emailAddress> -r <reportfile>")
def cli = new CliBuilder(usage: "groovy UpdateProfileAttribute -f <datadir> -o opusId -p <profileServiceBaseUrl> -u <emailAddress> -r <reportfile> -a <accessToken>")
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.u(longOpt: "userId", "User id of a ALA user importing script", required: true, args: 1)
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) {
Expand All @@ -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<Integer, String> attributeTitles = loadAttributeTitles()
Map<Integer, Map<String, List<String>>> taxaAttributes = loadAttributes(attributeTitles)
Expand All @@ -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()
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -166,7 +171,7 @@ class UpdateProfileAttribute {
switch (ATTRIBUTE_OPTION) {
case APPEND:
if (!attribute.text?.contains(additionalContent)) {
return attribute.text + decorateText(additionalContent)
return attribute.text + "<br>--------------------<br>"+ decorateText(additionalContent)
}

return attribute.text
Expand Down

0 comments on commit 57d5147

Please sign in to comment.