diff --git a/doc/release-notes/10819-publish-thumbnail-bug.md b/doc/release-notes/10819-publish-thumbnail-bug.md new file mode 100644 index 00000000000..46c9875a6ef --- /dev/null +++ b/doc/release-notes/10819-publish-thumbnail-bug.md @@ -0,0 +1,6 @@ +The initial release of the Dataverse v6.3 introduced a bug where publishing would break the dataset thumbnail, which in turn broke the rendering of the parent Collection ("dataverse") page. This problem was fixed in the PR 10820. + +This bug fix will prevent this from happening in the future, but does not fix any existing broken links. To restore any broken thumbnails caused by this bug, you can call the http://localhost:8080/api/admin/clearThumbnailFailureFlag API, which will attempt to clear the flag on all files (regardless of whether caused by this bug or some other problem with the file) or the http://localhost:8080/api/admin/clearThumbnailFailureFlag/id to clear the flag for individual files. Calling the former, batch API is recommended. + +Additionally, the same PR made it possible to turn off the feature that automatically selects of one of the image datafiles to serve as the thumbnail of the parent dataset. An admin can turn it off by raising the feature flag `-Ddataverse.feature.disable-dataset-thumbnail-autoselect=true`. When the feature is disabled, a user can still manually pick a thumbnail image, or upload a dedicated thumbnail image. + diff --git a/src/main/java/edu/harvard/iq/dataverse/Dataset.java b/src/main/java/edu/harvard/iq/dataverse/Dataset.java index e56ad723c46..52cb7d6f2dc 100644 --- a/src/main/java/edu/harvard/iq/dataverse/Dataset.java +++ b/src/main/java/edu/harvard/iq/dataverse/Dataset.java @@ -7,6 +7,7 @@ import edu.harvard.iq.dataverse.license.License; import edu.harvard.iq.dataverse.makedatacount.DatasetExternalCitations; import edu.harvard.iq.dataverse.makedatacount.DatasetMetrics; +import edu.harvard.iq.dataverse.settings.FeatureFlags; import java.nio.file.Path; import java.nio.file.Paths; import java.sql.Timestamp; @@ -211,6 +212,10 @@ public Dataset(boolean isHarvested) { StorageUse storageUse = new StorageUse(this); this.setStorageUse(storageUse); } + + if (FeatureFlags.DISABLE_DATASET_THUMBNAIL_AUTOSELECT.enabled()) { + this.setUseGenericThumbnail(true); + } } /** diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java index 8ddc9545763..762319884b9 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java @@ -9,6 +9,7 @@ import static edu.harvard.iq.dataverse.batch.jobs.importer.filesystem.FileRecordJobListener.SEP; import edu.harvard.iq.dataverse.batch.util.LoggingUtil; import edu.harvard.iq.dataverse.search.SolrSearchResult; +import edu.harvard.iq.dataverse.settings.FeatureFlags; import edu.harvard.iq.dataverse.settings.SettingsServiceBean; import edu.harvard.iq.dataverse.util.BundleUtil; import edu.harvard.iq.dataverse.util.MarkupChecker; @@ -807,36 +808,11 @@ public Long getThumbnailByVersionId(Long versionId) { return null; } - Long thumbnailFileId; - - // First, let's see if there are thumbnails that have already been - // generated: - try { - thumbnailFileId = (Long) em.createNativeQuery("SELECT df.id " - + "FROM datafile df, filemetadata fm, datasetversion dv, dvobject o " - + "WHERE dv.id = " + versionId + " " - + "AND df.id = o.id " - + "AND fm.datasetversion_id = dv.id " - + "AND fm.datafile_id = df.id " - + "AND df.restricted = false " - + "AND df.embargo_id is null " - + "AND df.retention_id is null " - + "AND o.previewImageAvailable = true " - + "ORDER BY df.id LIMIT 1;").getSingleResult(); - } catch (Exception ex) { - thumbnailFileId = null; - } - - if (thumbnailFileId != null) { - logger.fine("DatasetVersionService,getThumbnailByVersionid(): found already generated thumbnail for version " + versionId + ": " + thumbnailFileId); - assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); - return thumbnailFileId; - } - - if (!systemConfig.isThumbnailGenerationDisabledForImages()) { - // OK, let's try and generate an image thumbnail! - long imageThumbnailSizeLimit = systemConfig.getThumbnailSizeLimitImage(); + if (!FeatureFlags.DISABLE_DATASET_THUMBNAIL_AUTOSELECT.enabled()) { + Long thumbnailFileId; + // First, let's see if there are thumbnails that have already been + // generated: try { thumbnailFileId = (Long) em.createNativeQuery("SELECT df.id " + "FROM datafile df, filemetadata fm, datasetversion dv, dvobject o " @@ -844,63 +820,89 @@ public Long getThumbnailByVersionId(Long versionId) { + "AND df.id = o.id " + "AND fm.datasetversion_id = dv.id " + "AND fm.datafile_id = df.id " - + "AND o.previewimagefail = false " + "AND df.restricted = false " + "AND df.embargo_id is null " + "AND df.retention_id is null " - + "AND df.contenttype LIKE 'image/%' " - + "AND NOT df.contenttype = 'image/fits' " - + "AND df.filesize < " + imageThumbnailSizeLimit + " " - + "ORDER BY df.filesize ASC LIMIT 1;").getSingleResult(); + + "AND o.previewImageAvailable = true " + + "ORDER BY df.id LIMIT 1;").getSingleResult(); } catch (Exception ex) { thumbnailFileId = null; } if (thumbnailFileId != null) { - logger.fine("obtained file id: " + thumbnailFileId); - DataFile thumbnailFile = datafileService.find(thumbnailFileId); - if (thumbnailFile != null) { - if (datafileService.isThumbnailAvailable(thumbnailFile)) { - assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); - return thumbnailFileId; + logger.fine("DatasetVersionService,getThumbnailByVersionid(): found already generated thumbnail for version " + versionId + ": " + thumbnailFileId); + assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); + return thumbnailFileId; + } + + if (!systemConfig.isThumbnailGenerationDisabledForImages()) { + // OK, let's try and generate an image thumbnail! + long imageThumbnailSizeLimit = systemConfig.getThumbnailSizeLimitImage(); + + try { + thumbnailFileId = (Long) em.createNativeQuery("SELECT df.id " + + "FROM datafile df, filemetadata fm, datasetversion dv, dvobject o " + + "WHERE dv.id = " + versionId + " " + + "AND df.id = o.id " + + "AND fm.datasetversion_id = dv.id " + + "AND fm.datafile_id = df.id " + + "AND o.previewimagefail = false " + + "AND df.restricted = false " + + "AND df.embargo_id is null " + + "AND df.retention_id is null " + + "AND df.contenttype LIKE 'image/%' " + + "AND NOT df.contenttype = 'image/fits' " + + "AND df.filesize < " + imageThumbnailSizeLimit + " " + + "ORDER BY df.filesize ASC LIMIT 1;").getSingleResult(); + } catch (Exception ex) { + thumbnailFileId = null; + } + + if (thumbnailFileId != null) { + logger.fine("obtained file id: " + thumbnailFileId); + DataFile thumbnailFile = datafileService.find(thumbnailFileId); + if (thumbnailFile != null) { + if (datafileService.isThumbnailAvailable(thumbnailFile)) { + assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); + return thumbnailFileId; + } } } } - } - // And if that didn't work, try the same thing for PDFs: - if (!systemConfig.isThumbnailGenerationDisabledForPDF()) { - // OK, let's try and generate an image thumbnail! - long imageThumbnailSizeLimit = systemConfig.getThumbnailSizeLimitPDF(); - try { - thumbnailFileId = (Long) em.createNativeQuery("SELECT df.id " - + "FROM datafile df, filemetadata fm, datasetversion dv, dvobject o " - + "WHERE dv.id = " + versionId + " " - + "AND df.id = o.id " - + "AND fm.datasetversion_id = dv.id " - + "AND fm.datafile_id = df.id " - + "AND o.previewimagefail = false " - + "AND df.restricted = false " - + "AND df.embargo_id is null " - + "AND df.retention_id is null " - + "AND df.contenttype = 'application/pdf' " - + "AND df.filesize < " + imageThumbnailSizeLimit + " " - + "ORDER BY df.filesize ASC LIMIT 1;").getSingleResult(); - } catch (Exception ex) { - thumbnailFileId = null; - } + // And if that didn't work, try the same thing for PDFs: + if (!systemConfig.isThumbnailGenerationDisabledForPDF()) { + // OK, let's try and generate an image thumbnail! + long imageThumbnailSizeLimit = systemConfig.getThumbnailSizeLimitPDF(); + try { + thumbnailFileId = (Long) em.createNativeQuery("SELECT df.id " + + "FROM datafile df, filemetadata fm, datasetversion dv, dvobject o " + + "WHERE dv.id = " + versionId + " " + + "AND df.id = o.id " + + "AND fm.datasetversion_id = dv.id " + + "AND fm.datafile_id = df.id " + + "AND o.previewimagefail = false " + + "AND df.restricted = false " + + "AND df.embargo_id is null " + + "AND df.retention_id is null " + + "AND df.contenttype = 'application/pdf' " + + "AND df.filesize < " + imageThumbnailSizeLimit + " " + + "ORDER BY df.filesize ASC LIMIT 1;").getSingleResult(); + } catch (Exception ex) { + thumbnailFileId = null; + } - if (thumbnailFileId != null) { - DataFile thumbnailFile = datafileService.find(thumbnailFileId); - if (thumbnailFile != null) { - if (datafileService.isThumbnailAvailable(thumbnailFile)) { - assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); - return thumbnailFileId; + if (thumbnailFileId != null) { + DataFile thumbnailFile = datafileService.find(thumbnailFileId); + if (thumbnailFile != null) { + if (datafileService.isThumbnailAvailable(thumbnailFile)) { + assignDatasetThumbnailByNativeQuery(versionId, thumbnailFileId); + return thumbnailFileId; + } } } } } - return null; } diff --git a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java index 4c84384b271..cacd409b365 100644 --- a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java @@ -113,13 +113,19 @@ public static List getThumbnailCandidates(Dataset dataset, boo * * @param dataset * @param datasetVersion - * @return + * @param size of the requested thumbnail + * @return DatasetThumbnail object, or null if not available */ public static DatasetThumbnail getThumbnail(Dataset dataset, DatasetVersion datasetVersion, int size) { if (dataset == null) { return null; } + if (size == 0) { + // Size 0 will fail (and set the failure flag) and should never be sent + logger.warning("getThumbnail called with size 0"); + return null; + } StorageIO dataAccess = null; try{ diff --git a/src/main/java/edu/harvard/iq/dataverse/settings/FeatureFlags.java b/src/main/java/edu/harvard/iq/dataverse/settings/FeatureFlags.java index 021977ff8c6..2bfda69247a 100644 --- a/src/main/java/edu/harvard/iq/dataverse/settings/FeatureFlags.java +++ b/src/main/java/edu/harvard/iq/dataverse/settings/FeatureFlags.java @@ -91,6 +91,16 @@ public enum FeatureFlags { * @since Dataverse 6.3 */ DISABLE_RETURN_TO_AUTHOR_REASON("disable-return-to-author-reason"), + /** + * This flag disables the feature that automatically selects one of the + * DataFile thumbnails in the dataset/version as the dedicated thumbnail + * for the dataset. + * + * @apiNote Raise flag by setting + * "dataverse.feature.enable-dataset-thumbnail-autoselect" + * @since Dataverse 6.4 + */ + DISABLE_DATASET_THUMBNAIL_AUTOSELECT("disable-dataset-thumbnail-autoselect"), ; final String flag; diff --git a/src/main/java/propertyFiles/Bundle.properties b/src/main/java/propertyFiles/Bundle.properties index 7b6b8b83f5e..063ba484289 100644 --- a/src/main/java/propertyFiles/Bundle.properties +++ b/src/main/java/propertyFiles/Bundle.properties @@ -1074,7 +1074,7 @@ dataverse.theme.logo.imageFooter=Footer Image dataverse.theme.logo.image.title=The logo or image file you wish to display in the header of this dataverse. dataverse.theme.logo.image.footer=The logo or image file you wish to display in the footer of this dataverse. dataverse.theme.logo.image.uploadNewFile=Upload New File -dataverse.theme.logo.image.invalidMsg=The image could not be uploaded. Please try again with a JPG, TIF, or PNG file. +dataverse.theme.logo.image.invalidMsg=The image could not be uploaded. Please try again with a JPG or PNG file. dataverse.theme.logo.image.uploadImgFile=Upload Image File dataverse.theme.logo.format.title=The shape for the logo or image file you upload for this dataverse. dataverse.theme.logo.alignment.title=Where the logo or image should display in the header or footer. @@ -2176,7 +2176,7 @@ dataset.thumbnailsAndWidget.thumbnailImage.selectAvailable.title=Select a thumbn dataset.thumbnailsAndWidget.thumbnailImage.uploadNew=Upload New File dataset.thumbnailsAndWidget.thumbnailImage.uploadNew.title=Upload an image file as your dataset thumbnail, which will be stored separately from the data files that belong to your dataset. dataset.thumbnailsAndWidget.thumbnailImage.upload=Upload Image -dataset.thumbnailsAndWidget.thumbnailImage.upload.invalidMsg=The image could not be uploaded. Please try again with a JPG, TIF, or PNG file. +dataset.thumbnailsAndWidget.thumbnailImage.upload.invalidMsg=The image could not be uploaded. Please try again with a JPG or PNG file. dataset.thumbnailsAndWidget.thumbnailImage.alt=Thumbnail image selected for dataset dataset.thumbnailsAndWidget.success=Dataset thumbnail updated. dataset.thumbnailsAndWidget.removeThumbnail=Remove Thumbnail diff --git a/src/main/webapp/dataset.xhtml b/src/main/webapp/dataset.xhtml index 4cece74b67a..0118e6decb2 100644 --- a/src/main/webapp/dataset.xhtml +++ b/src/main/webapp/dataset.xhtml @@ -86,7 +86,7 @@ - +