use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException in project dataverse by IQSS.
the class SetDatasetCitationDateCommand method execute.
@Override
public Dataset execute(CommandContext ctxt) throws CommandException {
if (dsfType == null || dsfType.getFieldType().equals(FieldType.DATE)) {
dataset.setCitationDateDatasetFieldType(dsfType);
} else {
throw new IllegalCommandException("Provided DatasetFieldtype is not a Date", this);
}
Dataset savedDataset = ctxt.datasets().merge(dataset);
ctxt.index().indexDataset(savedDataset, false);
return savedDataset;
}
use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException in project dataverse by IQSS.
the class DatasetPage method isLockedFromDownload.
public boolean isLockedFromDownload() {
if (null == lockedFromDownloadVar) {
try {
permissionService.checkDownloadFileLock(dataset, dvRequestService.getDataverseRequest(), new CreateDatasetCommand(dataset, dvRequestService.getDataverseRequest()));
lockedFromDownloadVar = false;
} catch (IllegalCommandException ex) {
lockedFromDownloadVar = true;
return true;
}
}
return lockedFromDownloadVar;
}
use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException in project dataverse by IQSS.
the class UpdateDatasetCommand method execute.
@Override
public Dataset execute(CommandContext ctxt) throws CommandException {
ctxt.permissions().checkEditDatasetLock(theDataset, getRequest(), this);
// first validate
// @todo for now we run through an initFields method that creates empty fields for anything without a value
// that way they can be checked for required
theDataset.getEditVersion().setDatasetFields(theDataset.getEditVersion().initDatasetFields());
Set<ConstraintViolation> constraintViolations = theDataset.getEditVersion().validate();
if (!constraintViolations.isEmpty()) {
if (validateLenient) {
// for example, saving files, shouldn't validate metadata
for (ConstraintViolation v : constraintViolations) {
DatasetField f = ((DatasetField) v.getRootBean());
f.setSingleValue(DatasetField.NA_VALUE);
}
} else {
String validationFailedString = "Validation failed:";
for (ConstraintViolation constraintViolation : constraintViolations) {
validationFailedString += " " + constraintViolation.getMessage();
}
throw new IllegalCommandException(validationFailedString, this);
}
}
if (!(getUser() instanceof AuthenticatedUser)) {
throw new IllegalCommandException("Only authenticated users can update datasets", this);
}
return save(ctxt);
}
use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException in project dataverse by IQSS.
the class UpdateDatasetThumbnailCommand method execute.
@Override
public DatasetThumbnail execute(CommandContext ctxt) throws CommandException {
if (dataset == null) {
String message = "Can't update dataset thumbnail. Dataset is null.";
logger.info(message);
throw new IllegalCommandException(message, this);
}
// }
if (userIntent == null) {
throw new IllegalCommandException("No changes to save.", this);
}
switch(userIntent) {
case setDatasetFileAsThumbnail:
if (dataFileIdSupplied == null) {
throw new CommandException("A file was not selected to be the new dataset thumbnail.", this);
}
DataFile datasetFileThumbnailToSwitchTo = ctxt.files().find(dataFileIdSupplied);
if (datasetFileThumbnailToSwitchTo == null) {
throw new CommandException("Could not find file based on id supplied: " + dataFileIdSupplied + ".", this);
}
Dataset ds1 = ctxt.datasets().setDatasetFileAsThumbnail(dataset, datasetFileThumbnailToSwitchTo);
DatasetThumbnail datasetThumbnail = ds1.getDatasetThumbnail();
if (datasetThumbnail != null) {
DataFile dataFile = datasetThumbnail.getDataFile();
if (dataFile != null) {
if (dataFile.getId().equals(dataFileIdSupplied)) {
return datasetThumbnail;
} else {
throw new CommandException("Dataset thumbnail is should be based on file id " + dataFile.getId() + " but instead it is " + dataFileIdSupplied + ".", this);
}
}
} else {
throw new CommandException("Dataset thumbnail is unexpectedly absent.", this);
}
case setNonDatasetFileAsThumbnail:
File uploadedFile;
try {
uploadedFile = FileUtil.inputStreamToFile(inputStream);
} catch (IOException ex) {
throw new CommandException("In setNonDatasetFileAsThumbnail caught exception calling inputStreamToFile: " + ex, this);
}
if (uploadedFile == null) {
throw new CommandException("In setNonDatasetFileAsThumbnail uploadedFile was null.", this);
}
long uploadLogoSizeLimit = ctxt.systemConfig().getUploadLogoSizeLimit();
if (uploadedFile.length() > uploadLogoSizeLimit) {
throw new IllegalCommandException("File is larger than maximum size: " + uploadLogoSizeLimit + ".", this);
}
FileInputStream fileAsStream = null;
try {
fileAsStream = new FileInputStream(uploadedFile);
} catch (FileNotFoundException ex) {
Logger.getLogger(UpdateDatasetThumbnailCommand.class.getName()).log(Level.SEVERE, null, ex);
}
Dataset datasetWithNewThumbnail = ctxt.datasets().setNonDatasetFileAsThumbnail(dataset, fileAsStream);
if (datasetWithNewThumbnail != null) {
return datasetWithNewThumbnail.getDatasetThumbnail();
} else {
return null;
}
case removeThumbnail:
Dataset ds2 = ctxt.datasets().removeDatasetThumbnail(dataset);
DatasetThumbnail datasetThumbnail2 = ds2.getDatasetThumbnail();
if (datasetThumbnail2 == null) {
return null;
} else {
throw new CommandException("User wanted to remove the thumbnail it still has one!", this);
}
default:
throw new IllegalCommandException("Whatever you are trying to do to the dataset thumbnail is not supported.", this);
}
}
use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException in project dataverse by IQSS.
the class ReturnDatasetToAuthorCommand method execute.
@Override
public Dataset execute(CommandContext ctxt) throws CommandException {
if (theDataset == null) {
throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.reject.datasetNull"), this);
}
if (!theDataset.getLatestVersion().isInReview()) {
throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.reject.datasetNotInReview"), this);
}
/*
if(theDataset.getLatestVersion().getReturnReason() == null || theDataset.getLatestVersion().getReturnReason().isEmpty()){
throw new IllegalCommandException("You must enter a reason for returning a dataset to the author(s).", this);
}
*/
ctxt.engine().submit(new RemoveLockCommand(getRequest(), theDataset, DatasetLock.Reason.InReview));
Dataset updatedDataset = save(ctxt);
return updatedDataset;
}
Aggregations