@@ -424,7 +424,7 @@ class ImageStoreService {
424
424
}
425
425
}
426
426
427
- private ImageInfo ensureThumbnailExists (String imageIdentifier , StorageOperations operations , String type ) {
427
+ private ImageInfo ensureThumbnailExists (String imageIdentifier , String dataResourceUid , StorageOperations operations , String type ) {
428
428
type = normaliseThumbnailType(type)
429
429
return thumbnailCache. get(Pair . of(imageIdentifier, type), { pair ->
430
430
def imageIdentifierArg = pair. left
@@ -474,6 +474,7 @@ class ImageStoreService {
474
474
// override these based on behaviour of the thumbnailer
475
475
info. contentType = typeArg == ' square' ? ' image/png' : ' image/jpeg'
476
476
info. extension = typeArg == ' square' ? ' png' : ' jpg'
477
+ info. dataResourceUid = dataResourceUid
477
478
return info
478
479
} catch (e) {
479
480
log. error(" Error generating thumbnail for image ${ imageIdentifier} of type ${ typeArg} " , e)
@@ -489,7 +490,7 @@ class ImageStoreService {
489
490
int z
490
491
}
491
492
492
- private ImageInfo ensureTileExists (String identifier , int zoomLevels , StorageOperations operations , int x , int y , int z ) {
493
+ private ImageInfo ensureTileExists (String identifier , String dataResourceUid , int zoomLevels , StorageOperations operations , int x , int y , int z ) {
493
494
if (zoomLevels > 0 && z > zoomLevels) {
494
495
// requested zoom level is beyond the zoom levels of the image so the tile will never exist
495
496
return new ImageInfo (exists : false , imageIdentifier : identifier)
@@ -521,6 +522,7 @@ class ImageStoreService {
521
522
// or if the origin doesn't exist then any tile for the given zoom level won't exist either
522
523
// so return the non-existent origin info
523
524
if (x == 0 && y == 0 || ! originInfo. exists) {
525
+ originInfo. dataResourceUid = dataResourceUid
524
526
return originInfo
525
527
} else {
526
528
// otherwise now we get the info for the tile that was actually requested and cache it
@@ -535,96 +537,17 @@ class ImageStoreService {
535
537
return null // don't cache this error
536
538
}
537
539
}) ?: new ImageInfo (exists : false , imageIdentifier : identifier)
540
+ tileInfo. dataResourceUid = dataResourceUid
538
541
return tileInfo
539
542
}
540
543
}
541
544
542
- // delegating methods for Unit Testing
543
- InputStream originalInputStream (Image image , Range range ) {
544
- image. originalInputStream(range)
545
- }
546
-
547
- URI originalRedirectLocation (Image image ) {
548
- image. storageLocation. originalRedirectLocation(image. imageIdentifier)
549
- }
550
-
551
- long thumbnailStoredLength (Image image ) {
552
- def info = ensureThumbnailExists(image, ' ' )
553
- if (! info. exists) {
554
- return -1
555
- } else {
556
- return info. length
557
- }
558
- }
559
-
560
- InputStream thumbnailInputStream (Image image , Range range ) {
561
- def info = ensureThumbnailExists(image, ' ' )
562
- if (! info. exists) {
563
- return new ByteArrayInputStream (new byte [0 ])
564
- } else {
565
- return info. inputStreamSupplier(range)
566
- }
567
- }
568
-
569
- long thumbnailTypeStoredLength (Image image , String type ) {
570
- def info = ensureThumbnailExists(image, type)
571
- if (! info. exists) {
572
- return -1
573
- } else {
574
- return info. length
575
- }
576
- }
577
-
578
- InputStream thumbnailTypeInputStream (Image image , String type , Range range ) {
579
- def info = ensureThumbnailExists(image, type)
580
- if (! info. exists) {
581
- return new ByteArrayInputStream (new byte [0 ])
582
- } else {
583
- return info. inputStreamSupplier(range)
584
- }
585
- }
586
-
587
- long tileStoredLength (Image image , int x , int y , int z ) {
588
- def info = ensureTileExists(image, x, y, z)
589
- if (! info. exists) {
590
- return -1
591
- } else {
592
- info. length
593
- }
594
- }
595
-
596
- InputStream tileInputStream (Image image , Range range , int x , int y , int z ) {
597
- def info = ensureTileExists(image, x, y, z)
598
- if (! info. exists) {
599
- return new ByteArrayInputStream (new byte [0 ])
600
- } else {
601
- info. inputStreamSupplier(range)
602
- }
603
- }
604
-
605
- URI thumbnailRedirectLocation (Image image , String type ) {
606
- def info = ensureThumbnailExists(image, type)
607
- if (! info. exists) {
608
- return null
609
- } else {
610
- return info. redirectUri
611
- }
612
- }
613
-
614
- URI tileRedirectLocation (Image image , int x , int y , int z ) {
615
- def info = ensureTileExists(image, x, y, z)
616
- if (! info. exists) {
617
- return null
618
- } else {
619
- info. redirectUri
620
- }
621
- }
622
-
623
545
ImageInfo originalImageInfo (String imageIdentifier ) {
624
546
def image = Image . findByImageIdentifier(imageIdentifier, [ cache : true , fetch : [ storageLocation : ' join' ] ])
625
547
if (image) {
626
548
def imageInfo = image. storageLocation. originalImageInfo(image. imageIdentifier)
627
549
// override these to match original behaviour
550
+ imageInfo. dataResourceUid = image. dataResourceUid
628
551
imageInfo. etag = image. contentSHA1Hash
629
552
imageInfo. lastModified = image. dateUploaded
630
553
imageInfo. contentType = image. mimeType
@@ -638,15 +561,17 @@ class ImageStoreService {
638
561
ImageInfo thumbnailImageInfo (String imageIdentifier , String type ) {
639
562
Image image
640
563
StorageOperations operations = null
564
+ String dataResourceUid = null
641
565
Image . withNewTransaction(readOnly : true ) {
642
566
image = Image . findByImageIdentifier(imageIdentifier, [ cache : true , fetch : [ storageLocation : ' join' ] ])
643
567
if (image) {
644
568
operations = GrailsHibernateUtil . unwrapIfProxy(image. storageLocation). asStandaloneStorageOperations()
569
+ dataResourceUid = image. dataResourceUid
645
570
}
646
571
}
647
572
if (image) {
648
573
if (image. mimeType. startsWith(' image/' )) {
649
- def info = ensureThumbnailExists(imageIdentifier, operations, type)
574
+ def info = ensureThumbnailExists(imageIdentifier, dataResourceUid, operations, type)
650
575
if (info) {
651
576
return info
652
577
}
@@ -669,6 +594,7 @@ class ImageStoreService {
669
594
return new ImageInfo (
670
595
exists : true ,
671
596
imageIdentifier : imageIdentifier,
597
+ dataResourceUid : dataResourceUid,
672
598
length : resource. contentLength(),
673
599
lastModified : new Date (resource. lastModified()),
674
600
contentType : ' image/png' ,
@@ -686,15 +612,17 @@ class ImageStoreService {
686
612
687
613
Image image
688
614
StorageOperations operations = null
615
+ String dataResourceUid = null
689
616
Image . withNewTransaction(readOnly : true ) {
690
617
image = Image . findByImageIdentifier(imageIdentifier, [ cache : true , fetch : [ storageLocation : ' join' ] ])
691
618
if (image) {
692
619
operations = GrailsHibernateUtil . unwrapIfProxy(image. storageLocation). asStandaloneStorageOperations()
620
+ dataResourceUid = image. dataResourceUid
693
621
}
694
622
}
695
623
if (image) {
696
624
if (image. mimeType. startsWith(' image/' )) {
697
- def info = ensureTileExists(imageIdentifier, image. zoomLevels, operations, x, y, z)
625
+ def info = ensureTileExists(imageIdentifier, dataResourceUid, image. zoomLevels, operations, x, y, z)
698
626
return info
699
627
}
700
628
}
0 commit comments