use of edu.harvard.iq.dataverse.dataset.DatasetThumbnail in project dataverse by IQSS.
the class DatasetPage method getThumbnailString.
// This is the Dataset-level thumbnail;
// it's either the thumbnail of the designated datafile,
// or scaled down uploaded "logo" file, or randomly selected
// image datafile from this dataset.
public String getThumbnailString() {
if (thumbnailString != null) {
if ("".equals(thumbnailString)) {
return null;
}
return thumbnailString;
}
if (!readOnly) {
DatasetThumbnail datasetThumbnail = dataset.getDatasetThumbnail();
if (datasetThumbnail == null) {
thumbnailString = "";
return null;
}
if (datasetThumbnail.isFromDataFile()) {
if (!datasetThumbnail.getDataFile().equals(dataset.getThumbnailFile())) {
datasetService.assignDatasetThumbnailByNativeQuery(dataset, datasetThumbnail.getDataFile());
dataset = datasetService.find(dataset.getId());
}
}
thumbnailString = datasetThumbnail.getBase64image();
} else {
thumbnailString = thumbnailServiceWrapper.getDatasetCardImageAsBase64Url(dataset, workingVersion.getId());
if (thumbnailString == null) {
thumbnailString = "";
return null;
}
}
return thumbnailString;
}
use of edu.harvard.iq.dataverse.dataset.DatasetThumbnail in project dataverse by IQSS.
the class DatasetWidgetsPage method save.
public String save() {
logger.fine("save clicked");
if (updateDatasetThumbnailCommand == null) {
logger.fine("The user clicked saved without making any changes.");
return null;
}
try {
DatasetThumbnail datasetThumbnailFromCommand = commandEngine.submit(updateDatasetThumbnailCommand);
JsfHelper.addSuccessMessage(BundleUtil.getStringFromBundle("dataset.thumbnailsAndWidget.success"));
return "/dataset.xhtml?persistentId=" + dataset.getGlobalId() + "&faces-redirect=true";
} catch (CommandException ex) {
String error = ex.getLocalizedMessage();
/**
* @todo Should this go in the ActionLogRecord instead?
*/
// Username @dataverseAdmin experienced a problem executing UpdateDatasetThumbnailCommand on a DVObject {=[Dataset id:1377 ]} and saw this error: Just testing what an error would look like in the GUI.
logger.info("Username " + updateDatasetThumbnailCommand.getRequest().getUser().getIdentifier() + " experienced a problem executing " + updateDatasetThumbnailCommand.getClass().getSimpleName() + " on a DVObject " + updateDatasetThumbnailCommand.getAffectedDvObjects() + " and saw this error: " + error);
JsfHelper.addErrorMessage(error);
return null;
}
}
use of edu.harvard.iq.dataverse.dataset.DatasetThumbnail in project dataverse by IQSS.
the class DatasetWidgetsPage method handleImageFileUpload.
public void handleImageFileUpload(FileUploadEvent event) {
logger.fine("handleImageFileUpload clicked");
UploadedFile uploadedFile = event.getFile();
try {
updateDatasetThumbnailCommand = new UpdateDatasetThumbnailCommand(dvRequestService.getDataverseRequest(), dataset, UpdateDatasetThumbnailCommand.UserIntent.setNonDatasetFileAsThumbnail, null, uploadedFile.getInputstream());
} catch (IOException ex) {
String error = "Unexpected error while uploading file.";
logger.warning("Problem uploading dataset thumbnail to dataset id " + dataset.getId() + ". " + error + " . Exception: " + ex);
updateDatasetThumbnailCommand = null;
return;
}
File file = null;
try {
file = FileUtil.inputStreamToFile(uploadedFile.getInputstream());
} catch (IOException ex) {
Logger.getLogger(DatasetWidgetsPage.class.getName()).log(Level.SEVERE, null, ex);
return;
}
String base64image = ImageThumbConverter.generateImageThumbnailFromFileAsBase64(file, ImageThumbConverter.DEFAULT_CARDIMAGE_SIZE);
if (base64image != null) {
datasetThumbnail = new DatasetThumbnail(base64image, datasetFileThumbnailToSwitchTo);
} else {
Logger.getLogger(DatasetWidgetsPage.class.getName()).log(Level.SEVERE, "Failed to produce a thumbnail from the uploaded dataset logo.");
}
}
use of edu.harvard.iq.dataverse.dataset.DatasetThumbnail in project dataverse by IQSS.
the class DatasetWidgetsPage method setDataFileAsThumbnail.
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_CARDIMAGE_SIZE);
datasetThumbnail = new DatasetThumbnail(base64image, datasetFileThumbnailToSwitchTo);
}
use of edu.harvard.iq.dataverse.dataset.DatasetThumbnail in project dataverse by IQSS.
the class UpdateDatasetThumbnailCommandTest method testSetDatasetFileAsThumbnailFileNull.
@Test
public void testSetDatasetFileAsThumbnailFileNull() {
String expected = "A file was not selected to be the new dataset thumbnail.";
String actual = null;
DatasetThumbnail datasetThumbnail = null;
try {
datasetThumbnail = testEngine.submit(new UpdateDatasetThumbnailCommand(null, dataset, UpdateDatasetThumbnailCommand.UserIntent.setDatasetFileAsThumbnail, null, null));
} catch (CommandException ex) {
actual = ex.getMessage();
}
assertEquals(expected, actual);
assertNull(datasetThumbnail);
}
Aggregations