|
9 | 9 | import static edu.harvard.iq.dataverse.batch.jobs.importer.filesystem.FileRecordJobListener.SEP; |
10 | 10 | import edu.harvard.iq.dataverse.batch.util.LoggingUtil; |
11 | 11 | import edu.harvard.iq.dataverse.search.SolrSearchResult; |
| 12 | +import edu.harvard.iq.dataverse.settings.FeatureFlags; |
12 | 13 | import edu.harvard.iq.dataverse.settings.SettingsServiceBean; |
13 | 14 | import edu.harvard.iq.dataverse.util.BundleUtil; |
14 | 15 | import edu.harvard.iq.dataverse.util.MarkupChecker; |
@@ -807,100 +808,101 @@ public Long getThumbnailByVersionId(Long versionId) { |
807 | 808 | return null; |
808 | 809 | } |
809 | 810 |
|
810 | | - Long thumbnailFileId; |
811 | | - |
812 | | - // First, let's see if there are thumbnails that have already been |
813 | | - // generated: |
814 | | - try { |
815 | | - thumbnailFileId = (Long) em.createNativeQuery("SELECT df.id " |
816 | | - + "FROM datafile df, filemetadata fm, datasetversion dv, dvobject o " |
817 | | - + "WHERE dv.id = " + versionId + " " |
818 | | - + "AND df.id = o.id " |
819 | | - + "AND fm.datasetversion_id = dv.id " |
820 | | - + "AND fm.datafile_id = df.id " |
821 | | - + "AND df.restricted = false " |
822 | | - + "AND df.embargo_id is null " |
823 | | - + "AND df.retention_id is null " |
824 | | - + "AND o.previewImageAvailable = true " |
825 | | - + "ORDER BY df.id LIMIT 1;").getSingleResult(); |
826 | | - } catch (Exception ex) { |
827 | | - thumbnailFileId = null; |
828 | | - } |
829 | | - |
830 | | - if (thumbnailFileId != null) { |
831 | | - logger.fine("DatasetVersionService,getThumbnailByVersionid(): found already generated thumbnail for version " + versionId + ": " + thumbnailFileId); |
832 | | - assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); |
833 | | - return thumbnailFileId; |
834 | | - } |
835 | | - |
836 | | - if (!systemConfig.isThumbnailGenerationDisabledForImages()) { |
837 | | - // OK, let's try and generate an image thumbnail! |
838 | | - long imageThumbnailSizeLimit = systemConfig.getThumbnailSizeLimitImage(); |
| 811 | + if (!FeatureFlags.DISABLE_DATASET_THUMBNAIL_AUTOSELECT.enabled()) { |
| 812 | + Long thumbnailFileId; |
839 | 813 |
|
| 814 | + // First, let's see if there are thumbnails that have already been |
| 815 | + // generated: |
840 | 816 | try { |
841 | 817 | thumbnailFileId = (Long) em.createNativeQuery("SELECT df.id " |
842 | 818 | + "FROM datafile df, filemetadata fm, datasetversion dv, dvobject o " |
843 | 819 | + "WHERE dv.id = " + versionId + " " |
844 | 820 | + "AND df.id = o.id " |
845 | 821 | + "AND fm.datasetversion_id = dv.id " |
846 | 822 | + "AND fm.datafile_id = df.id " |
847 | | - + "AND o.previewimagefail = false " |
848 | 823 | + "AND df.restricted = false " |
849 | 824 | + "AND df.embargo_id is null " |
850 | 825 | + "AND df.retention_id is null " |
851 | | - + "AND df.contenttype LIKE 'image/%' " |
852 | | - + "AND NOT df.contenttype = 'image/fits' " |
853 | | - + "AND df.filesize < " + imageThumbnailSizeLimit + " " |
854 | | - + "ORDER BY df.filesize ASC LIMIT 1;").getSingleResult(); |
| 826 | + + "AND o.previewImageAvailable = true " |
| 827 | + + "ORDER BY df.id LIMIT 1;").getSingleResult(); |
855 | 828 | } catch (Exception ex) { |
856 | 829 | thumbnailFileId = null; |
857 | 830 | } |
858 | 831 |
|
859 | 832 | if (thumbnailFileId != null) { |
860 | | - logger.fine("obtained file id: " + thumbnailFileId); |
861 | | - DataFile thumbnailFile = datafileService.find(thumbnailFileId); |
862 | | - if (thumbnailFile != null) { |
863 | | - if (datafileService.isThumbnailAvailable(thumbnailFile)) { |
864 | | - assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); |
865 | | - return thumbnailFileId; |
| 833 | + logger.fine("DatasetVersionService,getThumbnailByVersionid(): found already generated thumbnail for version " + versionId + ": " + thumbnailFileId); |
| 834 | + assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); |
| 835 | + return thumbnailFileId; |
| 836 | + } |
| 837 | + |
| 838 | + if (!systemConfig.isThumbnailGenerationDisabledForImages()) { |
| 839 | + // OK, let's try and generate an image thumbnail! |
| 840 | + long imageThumbnailSizeLimit = systemConfig.getThumbnailSizeLimitImage(); |
| 841 | + |
| 842 | + try { |
| 843 | + thumbnailFileId = (Long) em.createNativeQuery("SELECT df.id " |
| 844 | + + "FROM datafile df, filemetadata fm, datasetversion dv, dvobject o " |
| 845 | + + "WHERE dv.id = " + versionId + " " |
| 846 | + + "AND df.id = o.id " |
| 847 | + + "AND fm.datasetversion_id = dv.id " |
| 848 | + + "AND fm.datafile_id = df.id " |
| 849 | + + "AND o.previewimagefail = false " |
| 850 | + + "AND df.restricted = false " |
| 851 | + + "AND df.embargo_id is null " |
| 852 | + + "AND df.retention_id is null " |
| 853 | + + "AND df.contenttype LIKE 'image/%' " |
| 854 | + + "AND NOT df.contenttype = 'image/fits' " |
| 855 | + + "AND df.filesize < " + imageThumbnailSizeLimit + " " |
| 856 | + + "ORDER BY df.filesize ASC LIMIT 1;").getSingleResult(); |
| 857 | + } catch (Exception ex) { |
| 858 | + thumbnailFileId = null; |
| 859 | + } |
| 860 | + |
| 861 | + if (thumbnailFileId != null) { |
| 862 | + logger.fine("obtained file id: " + thumbnailFileId); |
| 863 | + DataFile thumbnailFile = datafileService.find(thumbnailFileId); |
| 864 | + if (thumbnailFile != null) { |
| 865 | + if (datafileService.isThumbnailAvailable(thumbnailFile)) { |
| 866 | + assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); |
| 867 | + return thumbnailFileId; |
| 868 | + } |
866 | 869 | } |
867 | 870 | } |
868 | 871 | } |
869 | | - } |
870 | 872 |
|
871 | | - // And if that didn't work, try the same thing for PDFs: |
872 | | - if (!systemConfig.isThumbnailGenerationDisabledForPDF()) { |
873 | | - // OK, let's try and generate an image thumbnail! |
874 | | - long imageThumbnailSizeLimit = systemConfig.getThumbnailSizeLimitPDF(); |
875 | | - try { |
876 | | - thumbnailFileId = (Long) em.createNativeQuery("SELECT df.id " |
877 | | - + "FROM datafile df, filemetadata fm, datasetversion dv, dvobject o " |
878 | | - + "WHERE dv.id = " + versionId + " " |
879 | | - + "AND df.id = o.id " |
880 | | - + "AND fm.datasetversion_id = dv.id " |
881 | | - + "AND fm.datafile_id = df.id " |
882 | | - + "AND o.previewimagefail = false " |
883 | | - + "AND df.restricted = false " |
884 | | - + "AND df.embargo_id is null " |
885 | | - + "AND df.retention_id is null " |
886 | | - + "AND df.contenttype = 'application/pdf' " |
887 | | - + "AND df.filesize < " + imageThumbnailSizeLimit + " " |
888 | | - + "ORDER BY df.filesize ASC LIMIT 1;").getSingleResult(); |
889 | | - } catch (Exception ex) { |
890 | | - thumbnailFileId = null; |
891 | | - } |
| 873 | + // And if that didn't work, try the same thing for PDFs: |
| 874 | + if (!systemConfig.isThumbnailGenerationDisabledForPDF()) { |
| 875 | + // OK, let's try and generate an image thumbnail! |
| 876 | + long imageThumbnailSizeLimit = systemConfig.getThumbnailSizeLimitPDF(); |
| 877 | + try { |
| 878 | + thumbnailFileId = (Long) em.createNativeQuery("SELECT df.id " |
| 879 | + + "FROM datafile df, filemetadata fm, datasetversion dv, dvobject o " |
| 880 | + + "WHERE dv.id = " + versionId + " " |
| 881 | + + "AND df.id = o.id " |
| 882 | + + "AND fm.datasetversion_id = dv.id " |
| 883 | + + "AND fm.datafile_id = df.id " |
| 884 | + + "AND o.previewimagefail = false " |
| 885 | + + "AND df.restricted = false " |
| 886 | + + "AND df.embargo_id is null " |
| 887 | + + "AND df.retention_id is null " |
| 888 | + + "AND df.contenttype = 'application/pdf' " |
| 889 | + + "AND df.filesize < " + imageThumbnailSizeLimit + " " |
| 890 | + + "ORDER BY df.filesize ASC LIMIT 1;").getSingleResult(); |
| 891 | + } catch (Exception ex) { |
| 892 | + thumbnailFileId = null; |
| 893 | + } |
892 | 894 |
|
893 | | - if (thumbnailFileId != null) { |
894 | | - DataFile thumbnailFile = datafileService.find(thumbnailFileId); |
895 | | - if (thumbnailFile != null) { |
896 | | - if (datafileService.isThumbnailAvailable(thumbnailFile)) { |
897 | | - assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); |
898 | | - return thumbnailFileId; |
| 895 | + if (thumbnailFileId != null) { |
| 896 | + DataFile thumbnailFile = datafileService.find(thumbnailFileId); |
| 897 | + if (thumbnailFile != null) { |
| 898 | + if (datafileService.isThumbnailAvailable(thumbnailFile)) { |
| 899 | + assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); |
| 900 | + return thumbnailFileId; |
| 901 | + } |
899 | 902 | } |
900 | 903 | } |
901 | 904 | } |
902 | 905 | } |
903 | | - |
904 | 906 | return null; |
905 | 907 | } |
906 | 908 |
|
|
0 commit comments