Skip to content

Commit

Permalink
Merge pull request #10269 from QualitativeDataRepository/IQSS/10268-f…
Browse files Browse the repository at this point in the history
…ix-thumbnail-selection-logic

IQSS/10268 fix thumbnail selection logic
  • Loading branch information
sekmiller authored Jan 25, 2024
2 parents 752846f + 2f089b2 commit 274c6f0
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
*/
package edu.harvard.iq.dataverse;

import edu.harvard.iq.dataverse.dataaccess.DataAccess;
import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter;

import edu.harvard.iq.dataverse.dataaccess.StorageIO;
import edu.harvard.iq.dataverse.dataset.DatasetUtil;
import edu.harvard.iq.dataverse.search.SolrSearchResult;
import edu.harvard.iq.dataverse.util.SystemConfig;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
Expand Down Expand Up @@ -170,17 +173,30 @@ public String getDatasetCardImageAsUrl(Dataset dataset, Long versionId, boolean

if (thumbnailFile == null) {

// We attempt to auto-select via the optimized, native query-based method
boolean hasDatasetLogo = false;
StorageIO<DvObject> storageIO = null;
try {
storageIO = DataAccess.getStorageIO(dataset);
if (storageIO.isAuxObjectCached(DatasetUtil.datasetLogoFilenameFinal)) {
// If not, return null/use the default, otherwise pass the logo URL
hasDatasetLogo = true;
}
} catch (IOException ioex) {
logger.warning("getDatasetCardImageAsUrl(): Failed to initialize dataset StorageIO for "
+ dataset.getStorageIdentifier() + " (" + ioex.getMessage() + ")");
}
// If no other logo we attempt to auto-select via the optimized, native
// query-based method
// from the DatasetVersionService:
if (datasetVersionService.getThumbnailByVersionId(versionId) == null) {
if (!hasDatasetLogo && datasetVersionService.getThumbnailByVersionId(versionId) == null) {
return null;
}
}

String url = SystemConfig.getDataverseSiteUrlStatic() + "/api/datasets/" + dataset.getId() + "/logo";
logger.fine("getDatasetCardImageAsUrl: " + url);
this.dvobjectThumbnailsMap.put(datasetId,url);
return url;

}

// it's the responsibility of the user - to make sure the search result
Expand Down

0 comments on commit 274c6f0

Please sign in to comment.