Skip to content

Commit

Permalink
Merge pull request #10886 from IQSS/10875-update-conditions-to-displa…
Browse files Browse the repository at this point in the history
…y-image_url

Update the conditions to display image_url in Solr search results for file type
  • Loading branch information
ofahimIQSS authored Oct 25, 2024
2 parents 858eab6 + cb6e44f commit 9faf32e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Search API (/api/search) responses for Datafiles include image_url for the thumbnail if each of the following are true:
1. The DataFile is not Harvested
2. A Thumbnail is available for the Datafile
3. If the Datafile is Restricted then the caller must have Download File Permission for the Datafile
4. The Datafile is NOT actively embargoed
5. The Datafile's retention period has NOT expired

See also #10875 and #10886.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package edu.harvard.iq.dataverse;

import edu.harvard.iq.dataverse.authorization.Permission;
import edu.harvard.iq.dataverse.dataaccess.DataAccess;
import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter;
import edu.harvard.iq.dataverse.dataaccess.StorageIO;
Expand All @@ -20,7 +21,6 @@

import jakarta.ejb.EJB;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;

/**
Expand All @@ -33,9 +33,8 @@
public class ThumbnailServiceWrapper implements java.io.Serializable {

private static final Logger logger = Logger.getLogger(ThumbnailServiceWrapper.class.getCanonicalName());

@Inject
PermissionsWrapper permissionsWrapper;
@EJB
PermissionServiceBean permissionService;
@EJB
DataverseServiceBean dataverseService;
@EJB
Expand All @@ -49,12 +48,15 @@ public class ThumbnailServiceWrapper implements java.io.Serializable {
private Map<Long, DvObject> dvobjectViewMap = new HashMap<>();
private Map<Long, Boolean> hasThumbMap = new HashMap<>();

private boolean hasDownloadFilePermission(DvObject dvo) {
return permissionService.on(dvo).has(Permission.DownloadFile) ;
}
public String getFileCardImageAsUrl(SolrSearchResult result) {
DataFile dataFile = result != null && result.getEntity() != null ? ((DataFile) result.getEntity()) : null;
if (dataFile == null || result.isHarvested()
if (dataFile == null
|| result.isHarvested()
|| !isThumbnailAvailable(dataFile)
|| dataFile.isRestricted()
|| !dataFile.isReleased()
|| (dataFile.isRestricted() && !hasDownloadFilePermission(dataFile))
|| FileUtil.isActivelyEmbargoed(dataFile)
|| FileUtil.isRetentionExpired(dataFile)) {
return null;
Expand Down Expand Up @@ -105,7 +107,7 @@ public String getFileCardImageAsBase64Url(SolrSearchResult result) {
}

if ((!((DataFile)result.getEntity()).isRestricted()
|| permissionsWrapper.hasDownloadFilePermission(result.getEntity()))
|| hasDownloadFilePermission(result.getEntity()))
&& isThumbnailAvailable((DataFile) result.getEntity())) {

cardImageUrl = ImageThumbConverter.getImageThumbnailAsBase64(
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/edu/harvard/iq/dataverse/api/SearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1308,8 +1308,8 @@ public void testSearchFilesAndUrlImages() {
.statusCode(200);
pathToFile = "src/main/webapp/resources/js/mydata.js";
Response uploadFile = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile, apiToken);
uploadImage.prettyPrint();
uploadImage.then().assertThat()
uploadFile.prettyPrint();
uploadFile.then().assertThat()
.statusCode(200);

Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken);
Expand Down Expand Up @@ -1337,14 +1337,14 @@ public void testSearchFilesAndUrlImages() {
.statusCode(OK.getStatusCode())
.body("data.items[0].type", CoreMatchers.is("dataverse"))
.body("data.items[0].url", CoreMatchers.containsString("/dataverse/"))
.body("data.items[0]", CoreMatchers.not(CoreMatchers.hasItem("url_image")));
.body("data.items[0]", CoreMatchers.not(CoreMatchers.hasItem("image_url")));

searchResp = UtilIT.search("mydata", apiToken);
searchResp.prettyPrint();
searchResp.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.items[0].type", CoreMatchers.is("file"))
.body("data.items[0].url", CoreMatchers.containsString("/datafile/"))
.body("data.items[0]", CoreMatchers.not(CoreMatchers.hasItem("url_image")));
.body("data.items[0]", CoreMatchers.not(CoreMatchers.hasItem("image_url")));
}
}

0 comments on commit 9faf32e

Please sign in to comment.