Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the conditions to display image_url in Solr search results for file type #10886

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")));
}
}
Loading