use of edu.harvard.iq.dataverse.IdServiceBean in project dataverse by IQSS.
the class DestroyDatasetCommand method executeImpl.
@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
// first check if dataset is released, and if so, if user is a superuser
if (doomed.isReleased() && (!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser())) {
throw new PermissionException("Destroy can only be called by superusers.", this, Collections.singleton(Permission.DeleteDatasetDraft), doomed);
}
// If there is a dedicated thumbnail DataFile, it needs to be reset
// explicitly, or we'll get a constraint violation when deleting:
doomed.setThumbnailFile(null);
final Dataset managedDoomed = ctxt.em().merge(doomed);
List<String> datasetAndFileSolrIdsToDelete = new ArrayList<>();
// files need to iterate through and remove 'by hand' to avoid
// optimistic lock issues... (plus the physical files need to be
// deleted too!)
Iterator<DataFile> dfIt = doomed.getFiles().iterator();
while (dfIt.hasNext()) {
DataFile df = dfIt.next();
// Gather potential Solr IDs of files. As of this writing deaccessioned files are never indexed.
String solrIdOfPublishedFile = IndexServiceBean.solrDocIdentifierFile + df.getId();
datasetAndFileSolrIdsToDelete.add(solrIdOfPublishedFile);
String solrIdOfDraftFile = IndexServiceBean.solrDocIdentifierFile + df.getId() + IndexServiceBean.draftSuffix;
datasetAndFileSolrIdsToDelete.add(solrIdOfDraftFile);
ctxt.engine().submit(new DeleteDataFileCommand(df, getRequest(), true));
dfIt.remove();
}
// also, lets delete the uploaded thumbnails!
deleteDatasetLogo(doomed);
// ASSIGNMENTS
for (RoleAssignment ra : ctxt.roles().directRoleAssignments(doomed)) {
ctxt.em().remove(ra);
}
// ROLES
for (DataverseRole ra : ctxt.roles().findByOwnerId(doomed.getId())) {
ctxt.em().remove(ra);
}
IdServiceBean idServiceBean = IdServiceBean.getBean(ctxt);
try {
if (idServiceBean.alreadyExists(doomed)) {
idServiceBean.deleteIdentifier(doomed);
}
} catch (Exception e) {
logger.log(Level.WARNING, "Identifier deletion was not successfull:", e.getMessage());
}
Dataverse toReIndex = managedDoomed.getOwner();
// dataset
ctxt.em().remove(managedDoomed);
// add potential Solr IDs of datasets to list for deletion
String solrIdOfPublishedDatasetVersion = IndexServiceBean.solrDocIdentifierDataset + doomed.getId();
datasetAndFileSolrIdsToDelete.add(solrIdOfPublishedDatasetVersion);
String solrIdOfDraftDatasetVersion = IndexServiceBean.solrDocIdentifierDataset + doomed.getId() + IndexServiceBean.draftSuffix;
datasetAndFileSolrIdsToDelete.add(solrIdOfDraftDatasetVersion);
String solrIdOfDeaccessionedDatasetVersion = IndexServiceBean.solrDocIdentifierDataset + doomed.getId() + IndexServiceBean.deaccessionedSuffix;
datasetAndFileSolrIdsToDelete.add(solrIdOfDeaccessionedDatasetVersion);
IndexResponse resultOfSolrDeletionAttempt = ctxt.solrIndex().deleteMultipleSolrIds(datasetAndFileSolrIdsToDelete);
logger.log(Level.FINE, "Result of attempt to delete dataset and file IDs from the search index: {0}", resultOfSolrDeletionAttempt.getMessage());
ctxt.index().indexDataverse(toReIndex);
}
use of edu.harvard.iq.dataverse.IdServiceBean 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.IdServiceBean in project dataverse by IQSS.
the class UpdateDatasetTargetURLCommand method executeImpl.
@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
if (!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser()) {
throw new PermissionException("Update Target URL can only be called by superusers.", this, Collections.singleton(Permission.EditDataset), target);
}
IdServiceBean idServiceBean = IdServiceBean.getBean(target.getProtocol(), ctxt);
HashMap<String, String> metadata = idServiceBean.getMetadataFromDatasetForTargetURL(target);
try {
String doiRetString = idServiceBean.modifyIdentifier(target, metadata);
if (doiRetString != null && doiRetString.contains(target.getIdentifier())) {
target.setGlobalIdCreateTime(new Timestamp(new Date().getTime()));
ctxt.em().merge(target);
ctxt.em().flush();
} else {
// do nothing - we'll know it failed because the global id create time won't have been updated.
}
} catch (Exception e) {
// do nothing - idem and the problem has been logged
}
}
use of edu.harvard.iq.dataverse.IdServiceBean in project dataverse by IQSS.
the class FinalizeDatasetPublicationCommand method publicizeExternalIdentifier.
private void publicizeExternalIdentifier(Dataset dataset, CommandContext ctxt) throws CommandException {
String protocol = theDataset.getProtocol();
IdServiceBean idServiceBean = IdServiceBean.getBean(protocol, ctxt);
if (idServiceBean != null)
try {
idServiceBean.publicizeIdentifier(dataset);
} catch (Throwable e) {
throw new CommandException(BundleUtil.getStringFromBundle("dataset.publish.error", idServiceBean.getProviderInformation()), this);
}
}
Aggregations