Search in sources :

Example 86 with CommandException

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

the class MoveDatasetCommand method executeImpl.

@Override
public void executeImpl(CommandContext ctxt) throws CommandException {
    // first check if  user is a superuser
    if ((!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser())) {
        throw new PermissionException("Move Dataset can only be called by superusers.", this, Collections.singleton(Permission.DeleteDatasetDraft), moved);
    }
    // validate the move makes sense
    if (moved.getOwner().equals(destination)) {
        throw new IllegalCommandException("Dataset already in this Dataverse ", this);
    }
    if (moved.isReleased() && !destination.isReleased()) {
        throw new IllegalCommandException("Published Dataset may not be moved to unpublished Dataverse. You may publish " + destination.getDisplayName() + " and re-try the move.", this);
    }
    // if the datasets guestbook is not contained in the new dataverse then remove it
    if (moved.getGuestbook() != null) {
        Guestbook gb = moved.getGuestbook();
        List<Guestbook> gbs = destination.getGuestbooks();
        boolean inheritGuestbooksValue = !destination.isGuestbookRoot();
        if (inheritGuestbooksValue && destination.getOwner() != null) {
            for (Guestbook pg : destination.getParentGuestbooks()) {
                gbs.add(pg);
            }
        }
        if (gbs == null || !gbs.contains(gb)) {
            if (force == null || !force) {
                throw new IllegalCommandException("Dataset guestbook is not in target dataverse. Please use the parameter ?forceMove=true to complete the move. This will delete the guestbook from the Dataset", this);
            }
            moved.setGuestbook(null);
        }
    }
    // OK, move
    moved.setOwner(destination);
    ctxt.em().merge(moved);
    try {
        boolean doNormalSolrDocCleanUp = true;
        ctxt.index().indexDataset(moved, doNormalSolrDocCleanUp);
    } catch (Exception e) {
        // RuntimeException e ) {
        // , e);
        logger.log(Level.WARNING, "Exception while indexing:" + e.getMessage());
        throw new CommandException("Dataset could not be moved. Indexing failed", this);
    }
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) Guestbook(edu.harvard.iq.dataverse.Guestbook) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

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