use of edu.harvard.iq.dataverse.export.ExportService in project dataverse by IQSS.
the class DeaccessionDatasetVersionCommand method execute.
@Override
public DatasetVersion execute(CommandContext ctxt) throws CommandException {
Dataset ds = theVersion.getDataset();
theVersion.setVersionState(DatasetVersion.VersionState.DEACCESSIONED);
/* We do not want to delete the identifier if the dataset is completely deaccessioned
logger.fine("deleteDOIIdentifier=" + deleteDOIIdentifier);
if (deleteDOIIdentifier) {
String nonNullDefaultIfKeyNotFound = "";
String protocol = ctxt.settings().getValueForKey(SettingsServiceBean.Key.Protocol, nonNullDefaultIfKeyNotFound);
ArrayList<String> currentProtocol = new ArrayList<>();
currentProtocol.add(protocol);
IdServiceBean idServiceBean = IdServiceBean.getBean(ctxt);
logger.fine("protocol=" + protocol);
try {
idServiceBean.deleteIdentifier(ds);
} catch (Exception e) {
if (e.toString().contains("Internal Server Error")) {
throw new CommandException(BundleUtil.getStringFromBundle("dataset.publish.error", idServiceBean.getProviderInformation()),this);
}
throw new CommandException(BundleUtil.getStringFromBundle("dataset.delete.error", currentProtocol),this);
}
}*/
DatasetVersion managed = ctxt.em().merge(theVersion);
boolean doNormalSolrDocCleanUp = true;
ctxt.index().indexDataset(managed.getDataset(), doNormalSolrDocCleanUp);
ExportService instance = ExportService.getInstance(ctxt.settings());
if (managed.getDataset().getReleasedVersion() != null) {
try {
instance.exportAllFormats(managed.getDataset());
} catch (ExportException ex) {
// Something went wrong!
// But we're not going to treat it as a fatal condition.
}
} else {
try {
// otherwise, we need to wipe clean the exports we may have cached:
instance.clearAllCachedFormats(managed.getDataset());
} catch (IOException ex) {
// Try catch required due to original method for clearing cached metadata (non fatal)
}
}
// And save the dataset, to get the "last exported" timestamp right:
Dataset managedDs = ctxt.em().merge(managed.getDataset());
return managed;
}
Aggregations