Search in sources :

Example 6 with ExportException

use of edu.harvard.iq.dataverse.export.ExportException in project dataverse by IQSS.

the class OAIServlet method addSupportedMetadataFormats.

private void addSupportedMetadataFormats(Context context) {
    for (String[] provider : ExportService.getInstance(settingsService).getExportersLabels()) {
        String formatName = provider[1];
        Exporter exporter;
        try {
            exporter = ExportService.getInstance(settingsService).getExporter(formatName);
        } catch (ExportException ex) {
            exporter = null;
        }
        if (exporter != null && exporter.isXMLFormat() && exporter.isHarvestable()) {
            MetadataFormat metadataFormat;
            try {
                metadataFormat = MetadataFormat.metadataFormat(formatName);
                metadataFormat.withNamespace(exporter.getXMLNameSpace());
                metadataFormat.withSchemaLocation(exporter.getXMLSchemaLocation());
            } catch (ExportException ex) {
                metadataFormat = null;
            }
            if (metadataFormat != null) {
                context.withMetadataFormat(metadataFormat);
            }
        }
    }
// return context;
}
Also used : MetadataFormat(com.lyncode.xoai.dataprovider.model.MetadataFormat) Exporter(edu.harvard.iq.dataverse.export.spi.Exporter) ExportException(edu.harvard.iq.dataverse.export.ExportException)

Example 7 with ExportException

use of edu.harvard.iq.dataverse.export.ExportException in project dataverse by IQSS.

the class Xrecord method writeToStream.

public void writeToStream(OutputStream outputStream) throws IOException {
    outputStream.flush();
    String headerString = itemHeaderToString(this.header);
    if (headerString == null) {
        throw new IOException("Xrecord: failed to stream item header.");
    }
    outputStream.write(headerString.getBytes());
    if (!isExtendedDataverseMetadataMode(formatName)) {
        outputStream.write(METADATA_START_ELEMENT.getBytes());
        outputStream.flush();
        if (dataset != null && formatName != null) {
            InputStream inputStream = null;
            try {
                inputStream = ExportService.getInstance().getExport(dataset, formatName);
            } catch (ExportException ex) {
                inputStream = null;
            }
            if (inputStream == null) {
                throw new IOException("Xrecord: failed to open metadata stream.");
            }
            writeMetadataStream(inputStream, outputStream);
        }
        outputStream.write(METADATA_END_ELEMENT.getBytes());
    } else {
        outputStream.write(customMetadataExtensionRef(this.dataset.getGlobalId()).getBytes());
    }
    outputStream.flush();
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) ExportException(edu.harvard.iq.dataverse.export.ExportException)

Example 8 with ExportException

use of edu.harvard.iq.dataverse.export.ExportException 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

ExportException (edu.harvard.iq.dataverse.export.ExportException)8 ExportService (edu.harvard.iq.dataverse.export.ExportService)4 IOException (java.io.IOException)4 Exporter (edu.harvard.iq.dataverse.export.spi.Exporter)3 ArrayList (java.util.ArrayList)2 MetadataFormat (com.lyncode.xoai.dataprovider.model.MetadataFormat)1 Dataset (edu.harvard.iq.dataverse.Dataset)1 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)1 SchemaDotOrgExporter (edu.harvard.iq.dataverse.export.SchemaDotOrgExporter)1 InputStream (java.io.InputStream)1 TransactionAttribute (javax.ejb.TransactionAttribute)1