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);
}
}
Aggregations