@@ -2,6 +2,8 @@ package au.org.ala.profile.hub
2
2
3
3
import au.org.ala.ws.service.WebService
4
4
5
+
6
+
5
7
import static au.org.ala.profile.hub.Utils.*
6
8
import au.org.ala.images.thumb.ImageThumbnailer
7
9
import au.org.ala.images.thumb.ThumbDefinition
@@ -418,6 +420,7 @@ class ImageService {
418
420
Map profileUpdates = [:]
419
421
List<File > imageDirectories = []
420
422
List<File > imageFiles = []
423
+ List<File > imagesToPublish = []
421
424
String localDirPath = staged ? grailsApplication. config. image. staging. dir : grailsApplication. config. image. private . dir
422
425
// Check in old file directory structure
423
426
File localDir = new File (" ${ localDirPath} /${ profile.uuid} " )
@@ -434,7 +437,7 @@ class ImageService {
434
437
// these directories and take the image files without going into the subdirectories containing
435
438
// tiled images and thumbnails
436
439
imageDirectories. each { file ->
437
- file. traverse(maxDepth : 1 ) {
440
+ file. traverse(maxDepth : 0 ) {
438
441
if (it. file) {
439
442
imageFiles << it
440
443
}
@@ -445,44 +448,47 @@ class ImageService {
445
448
446
449
imageFiles. each {
447
450
String imageId = imageIdFromFile(it)
448
- Map localImage = images[imageId]
451
+ def image = images[imageId]
452
+ if (image) {
453
+ imagesToPublish << it
454
+ }
455
+ }
449
456
450
- if (! localImage) {
451
- log. error(" Skipping publishing $it with id $imageId because it is missing image metadata." )
452
- // Clean up staged / private file
453
- deleteFileAndDirIfEmpty(imageId, it, localDir)
454
- } else {
455
457
456
- List<Map > multimedia = localImage ? [
457
- [
458
- creator : localImage. creator ?: " " ,
459
- rights : localImage. rights ?: " " ,
460
- rightsHolder : localImage. rightsHolder ?: " " ,
461
- license : localImage. licence ?: " " ,
462
- title : localImage. title ?: " " ,
463
- description : localImage. description ?: " " ,
464
- dateCreated : localImage. dateCreated ?: " " ,
465
- originalFilename : localImage. originalFilename,
466
- contentType : localImage. contentType
467
- ]
468
- ] : []
469
- Map metadata = [multimedia : multimedia, scientificName : profile. scientificName]
470
-
471
- def uploadResponse = biocacheService. uploadImage(opus. uuid, profile. uuid, opus. dataResourceUid, it, metadata)
472
-
473
- if (uploadResponse?. resp) {
474
- // check if the local image was set as the primary, and swap the local id for the new permanent id
475
- if (profile. primaryImage == imageId) {
476
- profileUpdates. primaryImage = uploadResponse. resp. images[0 ]
477
- }
478
-
479
- // check for any display options that were set for the local image, and swap the local id for the new permanent id
480
- Map imageDisplayOption = profile. imageSettings?. find { it. imageId == imageId }
481
- if (imageDisplayOption) {
482
- imageDisplayOption?. imageId = uploadResponse. resp. images[0 ]
483
- }
458
+ imagesToPublish. each {
459
+ String imageId = imageIdFromFile(it)
460
+ List<Map > localImage = [images[imageId]]
461
+ List<Map > multimedia = localImage ? [
462
+ [
463
+ creator : localImage. creator ?: " " ,
464
+ rights : localImage. rights ?: " " ,
465
+ rightsHolder : localImage. rightsHolder ?: " " ,
466
+ license : localImage. licence ?: " " ,
467
+ title : localImage. title ?: " " ,
468
+ description : localImage. description ?: " " ,
469
+ dateCreated : localImage. dateCreated ?: " " ,
470
+ originalFilename : localImage. originalFileName,
471
+ contentType : localImage. contentType
472
+ ]
473
+ ] : []
474
+ Map metadata = [multimedia : multimedia, scientificName : profile. scientificName]
475
+
476
+ def uploadResponse = biocacheService. uploadImage(opus. uuid, profile. uuid, opus. dataResourceUid, it, metadata)
477
+
478
+ if (uploadResponse?. resp) {
479
+ // check if the local image was set as the primary, and swap the local id for the new permanent id
480
+ if (profile. primaryImage == imageId) {
481
+ profileUpdates. primaryImage = uploadResponse. resp. images[0 ]
484
482
}
485
483
484
+ // check for any display options that were set for the local image, and swap the local id for the new permanent id
485
+ // that has been assigned by uploadImage call
486
+ Map imageDisplayOption = profile. imageSettings?. find { it. imageId == imageId }
487
+ if (imageDisplayOption) {
488
+ imageDisplayOption?. imageId = uploadResponse. resp. images[0 ]
489
+ }
490
+ }
491
+ if ((uploadResponse?. statusCode. toInteger() >= 200 ) && (uploadResponse?. statusCode. toInteger() <= 299 )) { // don't delete the local images if the upload failed
486
492
if (staged) {
487
493
deleteStagedImage(opus. uuid, profile. uuid, imageId)
488
494
} else {
0 commit comments