Search in sources :

Example 36 with CommandException

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

the class HarvesterServiceBean method deleteHarvestedDataset.

private void deleteHarvestedDataset(Dataset dataset, DataverseRequest request, Logger hdLogger) {
    // Purge all the SOLR documents associated with this client from the
    // index server:
    indexService.deleteHarvestedDocuments(dataset);
    try {
        // DeleteFileCommand on them.
        for (DataFile harvestedFile : dataset.getFiles()) {
            DataFile merged = em.merge(harvestedFile);
            em.remove(merged);
            harvestedFile = null;
        }
        dataset.setFiles(null);
        Dataset merged = em.merge(dataset);
        engineService.submit(new DeleteDatasetCommand(request, merged));
    } catch (IllegalCommandException ex) {
    // TODO: log the result
    } catch (PermissionException ex) {
    // TODO: log the result
    } catch (CommandException ex) {
    // TODO: log the result
    }
// TODO: log the success result
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) Dataset(edu.harvard.iq.dataverse.Dataset) DeleteDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.DeleteDatasetCommand) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)

Example 37 with CommandException

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

the class FinalizeDatasetPublicationCommand method registerExternalIdentifier.

/**
 * Whether it's EZID or DataCite, if the registration is
 * refused because the identifier already exists, we'll generate another one
 * and try to register again... but only up to some
 * reasonably high number of times - so that we don't
 * go into an infinite loop here, if EZID is giving us
 * these duplicate messages in error.
 *
 * (and we do want the limit to be a "reasonably high" number!
 * true, if our identifiers are randomly generated strings,
 * then it is highly unlikely that we'll ever run into a
 * duplicate race condition repeatedly; but if they are sequential
 * numeric values, than it is entirely possible that a large
 * enough number of values will be legitimately registered
 * by another entity sharing the same authority...)
 * @param theDataset
 * @param ctxt
 * @param doiProvider
 * @throws CommandException
 */
private void registerExternalIdentifier(Dataset theDataset, CommandContext ctxt) throws CommandException {
    IdServiceBean idServiceBean = IdServiceBean.getBean(theDataset.getProtocol(), ctxt);
    if (theDataset.getGlobalIdCreateTime() == null) {
        if (idServiceBean != null) {
            try {
                if (!idServiceBean.alreadyExists(theDataset)) {
                    idServiceBean.createIdentifier(theDataset);
                    theDataset.setGlobalIdCreateTime(new Timestamp(new Date().getTime()));
                } else {
                    int attempts = 0;
                    while (idServiceBean.alreadyExists(theDataset) && attempts < FOOLPROOF_RETRIAL_ATTEMPTS_LIMIT) {
                        theDataset.setIdentifier(ctxt.datasets().generateDatasetIdentifier(theDataset, idServiceBean));
                        attempts++;
                    }
                    if (idServiceBean.alreadyExists(theDataset)) {
                        throw new IllegalCommandException("This dataset may not be published because its identifier is already in use by another dataset;gave up after " + attempts + " attempts. Current (last requested) identifier: " + theDataset.getIdentifier(), this);
                    }
                    idServiceBean.createIdentifier(theDataset);
                    theDataset.setGlobalIdCreateTime(new Timestamp(new Date().getTime()));
                }
            } catch (Throwable e) {
                throw new CommandException(BundleUtil.getStringFromBundle("dataset.publish.error", idServiceBean.getProviderInformation()), this);
            }
        } else {
            throw new IllegalCommandException("This dataset may not be published because its id registry service is not supported.", this);
        }
    }
}
Also used : IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) IdServiceBean(edu.harvard.iq.dataverse.IdServiceBean) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 38 with CommandException

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

the class GrantSuperuserStatusCommand method executeImpl.

@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
    if (!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser()) {
        throw new PermissionException("Revoke Superuser status command can only be called by superusers.", this, null, null);
    }
    try {
        targetUser.setSuperuser(true);
        ctxt.em().merge(targetUser);
        ctxt.em().flush();
    } catch (Exception e) {
        throw new CommandException("Failed to grant the superuser status to user " + targetUser.getIdentifier(), this);
    }
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) 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) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 39 with CommandException

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

the class RevokeAllRolesCommand method executeImpl.

@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
    if (!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser()) {
        throw new PermissionException("Revoke Superuser status command can only be called by superusers.", this, null, null);
    }
    try {
        ctxt.roles().revokeAll(assignee);
        ctxt.explicitGroups().revokeAllGroupsForAssignee(assignee);
    } catch (Exception ex) {
        throw new CommandException("Failed to revoke role assignments and/or group membership", this);
    }
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) 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) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 40 with CommandException

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

the class RevokeSuperuserStatusCommand method executeImpl.

@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
    if (!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser()) {
        throw new PermissionException("Revoke Superuser status command can only be called by superusers.", this, null, null);
    }
    try {
        targetUser.setSuperuser(false);
        ctxt.em().merge(targetUser);
        ctxt.em().flush();
    } catch (Exception e) {
        throw new CommandException("Failed to revoke the superuser status for user " + targetUser.getIdentifier(), this);
    }
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) 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) 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