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