Search in sources :

Example 76 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class UpdateDatasetThumbnailCommandTest method testDatasetNull.

@Test
public void testDatasetNull() {
    dataset = null;
    String expected = "Can't update dataset thumbnail. Dataset is null.";
    String actual = null;
    DatasetThumbnail datasetThumbnail = null;
    try {
        datasetThumbnail = testEngine.submit(new UpdateDatasetThumbnailCommand(null, dataset, UpdateDatasetThumbnailCommand.UserIntent.setDatasetFileAsThumbnail, Long.MIN_VALUE, null));
    } catch (CommandException ex) {
        actual = ex.getMessage();
    }
    assertEquals(expected, actual);
    assertNull(datasetThumbnail);
}
Also used : DatasetThumbnail(edu.harvard.iq.dataverse.dataset.DatasetThumbnail) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Example 77 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class UpdateDatasetThumbnailCommandTest method testSetDatasetFileAsThumbnailFileThumbnailUnexpectedlyAbsent.

@Test
public void testSetDatasetFileAsThumbnailFileThumbnailUnexpectedlyAbsent() {
    String expected = "Dataset thumbnail is unexpectedly absent.";
    String actual = null;
    DatasetThumbnail datasetThumbnail = null;
    try {
        datasetThumbnail = testEngine.submit(new UpdateDatasetThumbnailCommand(null, dataset, UpdateDatasetThumbnailCommand.UserIntent.setDatasetFileAsThumbnail, thumbnailUnexpectedlyAbsent, null));
    } catch (CommandException ex) {
        actual = ex.getMessage();
    }
    assertEquals(expected, actual);
    assertNull(datasetThumbnail);
}
Also used : DatasetThumbnail(edu.harvard.iq.dataverse.dataset.DatasetThumbnail) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Example 78 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class CreatePrivateUrlCommandTest method testAttemptCreatePrivateUrlOnNonDraft.

@Test
public void testAttemptCreatePrivateUrlOnNonDraft() {
    dataset = new Dataset();
    List<DatasetVersion> versions = new ArrayList<>();
    DatasetVersion datasetVersion = new DatasetVersion();
    datasetVersion.setVersionState(DatasetVersion.VersionState.RELEASED);
    versions.add(datasetVersion);
    dataset.setVersions(versions);
    dataset.setId(latestVersionIsNotDraft);
    String expected = "Can't create Private URL because the latest version of dataset id " + latestVersionIsNotDraft + " is not a draft.";
    String actual = null;
    PrivateUrl privateUrl = null;
    try {
        privateUrl = testEngine.submit(new CreatePrivateUrlCommand(null, dataset));
    } catch (CommandException ex) {
        actual = ex.getMessage();
    }
    assertEquals(expected, actual);
    assertNull(privateUrl);
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Example 79 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class CreatePrivateUrlCommandTest method testDatasetNull.

@Test
public void testDatasetNull() {
    dataset = null;
    String expected = "Can't create Private URL. Dataset is null.";
    String actual = null;
    PrivateUrl privateUrl = null;
    try {
        privateUrl = testEngine.submit(new CreatePrivateUrlCommand(null, dataset));
    } catch (CommandException ex) {
        actual = ex.getMessage();
    }
    assertEquals(expected, actual);
    assertNull(privateUrl);
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Example 80 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class AddReplaceFileHelper method step_055_loadOptionalFileParams.

/**
 * Load optional file params such as description, tags, fileDataTags, etc..
 *
 * @param optionalFileParams
 * @return
 */
private boolean step_055_loadOptionalFileParams(OptionalFileParams optionalFileParams) {
    if (hasError()) {
        return false;
    }
    // --------------------------------------------
    if (optionalFileParams == null) {
        return true;
    }
    // --------------------------------------------
    for (DataFile df : finalFileList) {
        try {
            optionalFileParams.addOptionalParams(df);
            // call restriction command here
            boolean restrict = optionalFileParams.getRestriction();
            if (restrict != df.getFileMetadata().isRestricted()) {
                commandEngine.submit(new RestrictFileCommand(df, dvRequest, restrict));
            }
        } catch (DataFileTagException ex) {
            Logger.getLogger(AddReplaceFileHelper.class.getName()).log(Level.SEVERE, null, ex);
            addError(ex.getMessage());
            return false;
        } catch (CommandException ex) {
            addError(ex.getMessage());
        }
    }
    return true;
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) RestrictFileCommand(edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand)

Aggregations

CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)86 Dataset (edu.harvard.iq.dataverse.Dataset)21 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)20 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)19 Test (org.junit.Test)16 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)15 EJBException (javax.ejb.EJBException)13 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)12 DataFile (edu.harvard.iq.dataverse.DataFile)11 Dataverse (edu.harvard.iq.dataverse.Dataverse)9 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)9 ConstraintViolation (javax.validation.ConstraintViolation)9 DatasetThumbnail (edu.harvard.iq.dataverse.dataset.DatasetThumbnail)8 IOException (java.io.IOException)8 Timestamp (java.sql.Timestamp)8 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 FacesMessage (javax.faces.application.FacesMessage)7 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)6 SwordError (org.swordapp.server.SwordError)6