Search in sources :

Example 11 with IllegalCommandException

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;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)

Example 12 with IllegalCommandException

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;
}
Also used : CreateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)

Example 13 with IllegalCommandException

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);
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)

Example 14 with IllegalCommandException

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);
    }
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) DatasetThumbnail(edu.harvard.iq.dataverse.dataset.DatasetThumbnail) Dataset(edu.harvard.iq.dataverse.Dataset) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) FileNotFoundException(java.io.FileNotFoundException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) IOException(java.io.IOException) DataFile(edu.harvard.iq.dataverse.DataFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 15 with IllegalCommandException

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;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)

Aggregations

IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)25 Dataset (edu.harvard.iq.dataverse.Dataset)6 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)6 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)6 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)6 Timestamp (java.sql.Timestamp)6 Date (java.util.Date)6 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)4 ConstraintViolation (javax.validation.ConstraintViolation)4 DataFile (edu.harvard.iq.dataverse.DataFile)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)3 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)3 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)3 DatasetField (edu.harvard.iq.dataverse.DatasetField)2 DataverseFieldTypeInputLevel (edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)2 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)2 User (edu.harvard.iq.dataverse.authorization.users.User)2 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)2 CreateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand)2 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)2