Search in sources :

Example 6 with ExportService

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;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) ExportService(edu.harvard.iq.dataverse.export.ExportService) IOException(java.io.IOException) ExportException(edu.harvard.iq.dataverse.export.ExportException)

Aggregations

ExportService (edu.harvard.iq.dataverse.export.ExportService)6 ExportException (edu.harvard.iq.dataverse.export.ExportException)4 IOException (java.io.IOException)3 Dataset (edu.harvard.iq.dataverse.Dataset)2 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)1 DataCaptureModuleException (edu.harvard.iq.dataverse.datacapturemodule.DataCaptureModuleException)1 DataFileTagException (edu.harvard.iq.dataverse.datasetutility.DataFileTagException)1 NoFilesException (edu.harvard.iq.dataverse.datasetutility.NoFilesException)1 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)1 JsonParseException (edu.harvard.iq.dataverse.util.json.JsonParseException)1 EJBException (javax.ejb.EJBException)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1