Skip to content

Commit

Permalink
Making the size of the dataset thumbnail flexible.
Browse files Browse the repository at this point in the history
That's seemingly a lot of changes, but it was the assumption throughout the code base that
all the dataset-level thumbnails are always the same size. Removing it now will help with
making all the thumbnails for everything completely variable (as opposed to how they come in
the few pre-defined sizes now), which we are planning to add as well, sometime soon (?)
ref #6684
  • Loading branch information
landreev committed Apr 17, 2020
1 parent 76449b9 commit 4254a0f
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 61 deletions.
8 changes: 4 additions & 4 deletions src/main/java/edu/harvard/iq/dataverse/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,8 @@ public boolean isAncestorOf( DvObject other ) {
return equals(other) || equals(other.getOwner());
}

public DatasetThumbnail getDatasetThumbnail() {
return DatasetUtil.getThumbnail(this);
public DatasetThumbnail getDatasetThumbnail(int size) {
return DatasetUtil.getThumbnail(this, size);
}

/**
Expand All @@ -848,8 +848,8 @@ public DatasetThumbnail getDatasetThumbnail() {
* @param datasetVersion
* @return A thumbnail of the dataset (may be {@code null}).
*/
public DatasetThumbnail getDatasetThumbnail(DatasetVersion datasetVersion) {
return DatasetUtil.getThumbnail(this, datasetVersion);
public DatasetThumbnail getDatasetThumbnail(DatasetVersion datasetVersion, int size) {
return DatasetUtil.getThumbnail(this, datasetVersion, size);
}

}
7 changes: 5 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public String getThumbnailString() {
}

if (!readOnly) {
DatasetThumbnail datasetThumbnail = dataset.getDatasetThumbnail();
DatasetThumbnail datasetThumbnail = dataset.getDatasetThumbnail(ImageThumbConverter.DEFAULT_DATASETLOGO_SIZE);
if (datasetThumbnail == null) {
thumbnailString = "";
return null;
Expand All @@ -392,7 +392,10 @@ public String getThumbnailString() {

thumbnailString = datasetThumbnail.getBase64image();
} else {
thumbnailString = thumbnailServiceWrapper.getDatasetCardImageAsBase64Url(dataset, workingVersion.getId(),!workingVersion.isDraft());
thumbnailString = thumbnailServiceWrapper.getDatasetCardImageAsBase64Url(dataset,
workingVersion.getId(),
!workingVersion.isDraft(),
ImageThumbConverter.DEFAULT_DATASETLOGO_SIZE);
if (thumbnailString == null) {
thumbnailString = "";
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ public Dataset setNonDatasetFileAsThumbnail(Dataset dataset, InputStream inputSt
logger.fine("In setNonDatasetFileAsThumbnail but inputStream is null! Returning null.");
return null;
}
dataset = DatasetUtil.persistDatasetLogoToStorageAndCreateThumbnail(dataset, inputStream);
dataset = DatasetUtil.persistDatasetLogoToStorageAndCreateThumbnails(dataset, inputStream);
dataset.setThumbnailFile(null);
return merge(dataset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public String init() {
if (!permissionsWrapper.canIssueCommand(dataset, UpdateDatasetVersionCommand.class)) {
return permissionsWrapper.notAuthorized();
}
datasetThumbnails = DatasetUtil.getThumbnailCandidates(dataset, considerDatasetLogoAsCandidate);
datasetThumbnail = dataset.getDatasetThumbnail();
datasetThumbnails = DatasetUtil.getThumbnailCandidates(dataset, considerDatasetLogoAsCandidate, ImageThumbConverter.DEFAULT_DATASETLOGO_SIZE);
datasetThumbnail = dataset.getDatasetThumbnail(ImageThumbConverter.DEFAULT_DATASETLOGO_SIZE);
if (datasetThumbnail != null) {
DataFile dataFile = datasetThumbnail.getDataFile();
if (dataFile != null) {
Expand Down Expand Up @@ -117,7 +117,7 @@ public void setDatasetFileThumbnailToSwitchTo(DataFile datasetFileThumbnailToSwi
public void setDataFileAsThumbnail() {
logger.fine("setDataFileAsThumbnail clicked");
updateDatasetThumbnailCommand = new UpdateDatasetThumbnailCommand(dvRequestService.getDataverseRequest(), dataset, UpdateDatasetThumbnailCommand.UserIntent.setDatasetFileAsThumbnail, datasetFileThumbnailToSwitchTo.getId(), null);
String base64image = ImageThumbConverter.getImageThumbnailAsBase64(datasetFileThumbnailToSwitchTo, ImageThumbConverter.DEFAULT_DATASET_THUMBNAIL_SIZE);
String base64image = ImageThumbConverter.getImageThumbnailAsBase64(datasetFileThumbnailToSwitchTo, ImageThumbConverter.DEFAULT_DATASETLOGO_SIZE);
datasetThumbnail = new DatasetThumbnail(base64image, datasetFileThumbnailToSwitchTo);
}

Expand Down Expand Up @@ -146,7 +146,7 @@ public void handleImageFileUpload(FileUploadEvent event) {
Logger.getLogger(DatasetWidgetsPage.class.getName()).log(Level.SEVERE, null, ex);
return;
}
String base64image = ImageThumbConverter.generateImageThumbnailFromFileAsBase64(file, ImageThumbConverter.DEFAULT_DATASET_THUMBNAIL_SIZE);
String base64image = ImageThumbConverter.generateImageThumbnailFromFileAsBase64(file, ImageThumbConverter.DEFAULT_DATASETLOGO_SIZE);
if (base64image != null) {
datasetThumbnail = new DatasetThumbnail(base64image, datasetFileThumbnailToSwitchTo);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2586,7 +2586,7 @@ public void deleteDatasetLogoAndUseThisDataFileAsThumbnailInstead() {
}

public boolean isThumbnailIsFromDatasetLogoRatherThanDatafile() {
DatasetThumbnail datasetThumbnail = dataset.getDatasetThumbnail();
DatasetThumbnail datasetThumbnail = dataset.getDatasetThumbnail(ImageThumbConverter.DEFAULT_CARDIMAGE_SIZE);
return datasetThumbnail != null && !datasetThumbnail.isFromDataFile();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter;
import edu.harvard.iq.dataverse.dataset.DatasetUtil;
import static edu.harvard.iq.dataverse.dataset.DatasetUtil.datasetLogoThumbnail;
import static edu.harvard.iq.dataverse.dataset.DatasetUtil.thumb48addedByImageThumbConverter;
import edu.harvard.iq.dataverse.search.SolrSearchResult;
import edu.harvard.iq.dataverse.util.FileUtil;
import java.io.File;
Expand Down Expand Up @@ -51,7 +50,7 @@ public class ThumbnailServiceWrapper implements java.io.Serializable {
private Map<Long, String> dvobjectThumbnailsMap = new HashMap<>();
private Map<Long, DvObject> dvobjectViewMap = new HashMap<>();

private String getAssignedDatasetImage(Dataset dataset) {
private String getAssignedDatasetImage(Dataset dataset, int size) {
if (dataset == null) {
return null;
}
Expand All @@ -71,7 +70,8 @@ private String getAssignedDatasetImage(Dataset dataset) {
}

String imageSourceBase64 = ImageThumbConverter.getImageThumbnailAsBase64(assignedThumbnailFile,
ImageThumbConverter.DEFAULT_DATASET_THUMBNAIL_SIZE);
size);
//ImageThumbConverter.DEFAULT_CARDIMAGE_SIZE);

if (imageSourceBase64 != null) {
this.dvobjectThumbnailsMap.put(assignedThumbnailFileId, imageSourceBase64);
Expand Down Expand Up @@ -182,9 +182,10 @@ public String getDatasetCardImageAsBase64Url(SolrSearchResult result) {

Long versionId = result.getDatasetVersionId();

return getDatasetCardImageAsBase64Url(dataset, versionId, result.isPublishedState());
return getDatasetCardImageAsBase64Url(dataset, versionId, result.isPublishedState(), ImageThumbConverter.DEFAULT_CARDIMAGE_SIZE);
}
public String getDatasetCardImageAsBase64Url(Dataset dataset, Long versionId, boolean autoselect) {

public String getDatasetCardImageAsBase64Url(Dataset dataset, Long versionId, boolean autoselect, int size) {
Long datasetId = dataset.getId();
if (datasetId != null) {
if (this.dvobjectThumbnailsMap.containsKey(datasetId)) {
Expand Down Expand Up @@ -221,7 +222,8 @@ public String getDatasetCardImageAsBase64Url(Dataset dataset, Long versionId, bo
// an auxilary file on the dataset level:
// (don't bother checking if it exists; just try to open the input stream)
try {
in = dataAccess.getAuxFileAsInputStream(datasetLogoThumbnail + thumb48addedByImageThumbConverter);
in = dataAccess.getAuxFileAsInputStream(datasetLogoThumbnail + ".thumb" + size);
//thumb48addedByImageThumbConverter);
} catch (Exception ioex) {
//ignore
}
Expand All @@ -247,7 +249,7 @@ public String getDatasetCardImageAsBase64Url(Dataset dataset, Long versionId, bo

// If not, see if the dataset has one of its image files already assigned
// to be the designated thumbnail:
cardImageUrl = this.getAssignedDatasetImage(dataset);
cardImageUrl = this.getAssignedDatasetImage(dataset, size);

if (cardImageUrl != null) {
//logger.info("dataset id " + result.getEntity().getId() + " has a dedicated image assigned; returning " + cardImageUrl);
Expand Down Expand Up @@ -296,7 +298,8 @@ public String getDatasetCardImageAsBase64Url(Dataset dataset, Long versionId, bo
if (dataFileService.isThumbnailAvailable(thumbnailImageFile)) {
cardImageUrl = ImageThumbConverter.getImageThumbnailAsBase64(
thumbnailImageFile,
ImageThumbConverter.DEFAULT_CARDIMAGE_SIZE);
size);
//ImageThumbConverter.DEFAULT_CARDIMAGE_SIZE);
}

if (cardImageUrl != null) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/api/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import edu.harvard.iq.dataverse.authorization.RoleAssignee;
import edu.harvard.iq.dataverse.authorization.UserRecordIdentifier;
import edu.harvard.iq.dataverse.authorization.users.User;
import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter;
import edu.harvard.iq.dataverse.dataset.DatasetThumbnail;
import edu.harvard.iq.dataverse.dataset.DatasetUtil;
import edu.harvard.iq.dataverse.engine.command.DataverseRequest;
Expand Down Expand Up @@ -1178,9 +1179,9 @@ public Response getDatasetThumbnailMetadata(@PathParam("id") Long idSupplied) {
return error(Response.Status.NOT_FOUND, "Could not find dataset based on id supplied: " + idSupplied + ".");
}
JsonObjectBuilder data = Json.createObjectBuilder();
DatasetThumbnail datasetThumbnail = dataset.getDatasetThumbnail();
DatasetThumbnail datasetThumbnail = dataset.getDatasetThumbnail(ImageThumbConverter.DEFAULT_CARDIMAGE_SIZE);
data.add("isUseGenericThumbnail", dataset.isUseGenericThumbnail());
data.add("datasetLogoPresent", DatasetUtil.isDatasetLogoPresent(dataset));
data.add("datasetLogoPresent", DatasetUtil.isDatasetLogoPresent(dataset, ImageThumbConverter.DEFAULT_CARDIMAGE_SIZE));
if (datasetThumbnail != null) {
data.add("datasetThumbnailBase64image", datasetThumbnail.getBase64image());
DataFile dataFile = datasetThumbnail.getDataFile();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import edu.harvard.iq.dataverse.api.dto.RoleAssignmentDTO;
import edu.harvard.iq.dataverse.batch.util.LoggingUtil;
import edu.harvard.iq.dataverse.dataaccess.DataAccess;
import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter;
import edu.harvard.iq.dataverse.dataaccess.S3AccessIO;
import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
import edu.harvard.iq.dataverse.engine.command.exception.UnforcedCommandException;
Expand Down Expand Up @@ -1213,7 +1214,7 @@ public Response getDatasetThumbnailCandidates(@PathParam("id") String idSupplied
}
JsonArrayBuilder data = Json.createArrayBuilder();
boolean considerDatasetLogoAsCandidate = true;
for (DatasetThumbnail datasetThumbnail : DatasetUtil.getThumbnailCandidates(dataset, considerDatasetLogoAsCandidate)) {
for (DatasetThumbnail datasetThumbnail : DatasetUtil.getThumbnailCandidates(dataset, considerDatasetLogoAsCandidate, ImageThumbConverter.DEFAULT_CARDIMAGE_SIZE)) {
JsonObjectBuilder candidate = Json.createObjectBuilder();
String base64image = datasetThumbnail.getBase64image();
if (base64image != null) {
Expand All @@ -1238,7 +1239,7 @@ public Response getDatasetThumbnailCandidates(@PathParam("id") String idSupplied
public Response getDatasetThumbnail(@PathParam("id") String idSupplied) {
try {
Dataset dataset = findDatasetOrDie(idSupplied);
InputStream is = DatasetUtil.getThumbnailAsInputStream(dataset);
InputStream is = DatasetUtil.getThumbnailAsInputStream(dataset, ImageThumbConverter.DEFAULT_CARDIMAGE_SIZE);
if(is == null) {
return notFound("Thumbnail not available");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class ImageThumbConverter {

public static int DEFAULT_CARDIMAGE_SIZE = 48;
public static int DEFAULT_THUMBNAIL_SIZE = 64;
public static int DEFAULT_DATASET_THUMBNAIL_SIZE = 140;
public static int DEFAULT_DATASETLOGO_SIZE = 140;
public static int DEFAULT_PREVIEW_SIZE = 400;

private static final Logger logger = Logger.getLogger(ImageThumbConverter.class.getCanonicalName());
Expand Down
Loading

0 comments on commit 4254a0f

Please sign in to comment.