use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetThumbnailCommand in project dataverse by IQSS.
the class DatasetWidgetsPage method flagDatasetThumbnailForRemoval.
public void flagDatasetThumbnailForRemoval() {
logger.fine("flagDatasetThumbnailForRemoval");
updateDatasetThumbnailCommand = new UpdateDatasetThumbnailCommand(dvRequestService.getDataverseRequest(), dataset, UpdateDatasetThumbnailCommand.UserIntent.removeThumbnail, null, null);
datasetFileThumbnailToSwitchTo = null;
datasetThumbnail = null;
}
use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetThumbnailCommand 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.engine.command.impl.UpdateDatasetThumbnailCommand 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.engine.command.impl.UpdateDatasetThumbnailCommand in project dataverse by IQSS.
the class EditDatafilesPage method deleteDatasetLogoAndUseThisDataFileAsThumbnailInstead.
public void deleteDatasetLogoAndUseThisDataFileAsThumbnailInstead() {
logger.log(Level.FINE, "For dataset id {0} the current thumbnail is from a dataset logo rather than a dataset file, blowing away the logo and using this FileMetadata id instead: {1}", new Object[] { dataset.getId(), fileMetadataSelectedForThumbnailPopup });
/**
* @todo Rather than deleting and merging right away, try to respect how
* this page seems to stage actions and giving the user a chance to
* review before clicking "Save Changes".
*/
try {
DatasetThumbnail datasetThumbnail = commandEngine.submit(new UpdateDatasetThumbnailCommand(dvRequestService.getDataverseRequest(), dataset, UpdateDatasetThumbnailCommand.UserIntent.setDatasetFileAsThumbnail, fileMetadataSelectedForThumbnailPopup.getDataFile().getId(), null));
// look up the dataset again because the UpdateDatasetThumbnailCommand mutates (merges) the dataset
dataset = datasetService.find(dataset.getId());
} catch (CommandException ex) {
String error = "Problem setting thumbnail for dataset id " + dataset.getId() + ".: " + ex;
// show this error to the user?
logger.info(error);
}
}
Aggregations