Search in sources :

Example 6 with IllegalCommandException

use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException 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 7 with IllegalCommandException

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

the class DeleteHarvestingClientCommand method executeImpl.

@Override
public void executeImpl(CommandContext ctxt) throws CommandException {
    if (harvestingClient == null) {
        throw new IllegalCommandException("DeleteHarvestingClientCommand: attempted to execute with null harvesting client; dataverse: " + motherDataverse.getAlias(), this);
    }
    HarvestingClient merged = ctxt.em().merge(harvestingClient);
    for (DataFile harvestedFile : ctxt.files().findHarvestedFilesByClient(merged)) {
        DataFile mergedFile = ctxt.em().merge(harvestedFile);
        ctxt.em().remove(mergedFile);
        harvestedFile = null;
    }
    ctxt.em().remove(merged);
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) HarvestingClient(edu.harvard.iq.dataverse.harvest.client.HarvestingClient)

Example 8 with IllegalCommandException

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

the class DeletePrivateUrlCommand method executeImpl.

@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
    logger.fine("Executing DeletePrivateUrlCommand....");
    if (dataset == null) {
        /**
         * @todo Internationalize this.
         */
        String message = "Can't delete Private URL. Dataset is null.";
        logger.info(message);
        throw new IllegalCommandException(message, this);
    }
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(dataset.getId());
    List<RoleAssignment> roleAssignments = ctxt.roles().directRoleAssignments(privateUrlUser, dataset);
    for (RoleAssignment roleAssignment : roleAssignments) {
        ctxt.engine().submit(new RevokeRoleCommand(roleAssignment, getRequest()));
    }
}
Also used : IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment)

Example 9 with IllegalCommandException

use of edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException 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 10 with IllegalCommandException

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

the class SubmitDatasetForReviewCommand method execute.

@Override
public Dataset execute(CommandContext ctxt) throws CommandException {
    if (theDataset == null) {
        throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.submit.failure.null"), this);
    }
    if (theDataset.getLatestVersion().isReleased()) {
        throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.submit.failure.isReleased"), this);
    }
    if (theDataset.getLatestVersion().isInReview()) {
        throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.submit.failure.inReview"), this);
    }
    // SEK 9-1 Add Lock before saving dataset
    DatasetLock inReviewLock = new DatasetLock(DatasetLock.Reason.InReview, getRequest().getAuthenticatedUser());
    ctxt.engine().submit(new AddLockCommand(getRequest(), theDataset, inReviewLock));
    Dataset updatedDataset = save(ctxt);
    return updatedDataset;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) DatasetLock(edu.harvard.iq.dataverse.DatasetLock)

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