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