Search in sources :

Example 1 with JsonPrinter

use of edu.harvard.iq.dataverse.util.json.JsonPrinter in project dataverse by IQSS.

the class ExportService method exportAllFormats.

// This method goes through all the Exporters and calls
// the "chacheExport()" method that will save the produced output
// in a file in the dataset directory, on each Exporter available.
public void exportAllFormats(Dataset dataset) throws ExportException {
    try {
        clearAllCachedFormats(dataset);
    } catch (IOException ex) {
        Logger.getLogger(ExportService.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        DatasetVersion releasedVersion = dataset.getReleasedVersion();
        if (releasedVersion == null) {
            throw new ExportException("No released version for dataset " + dataset.getGlobalId());
        }
        JsonPrinter jsonPrinter = new JsonPrinter(settingsService);
        final JsonObjectBuilder datasetAsJsonBuilder = jsonPrinter.jsonAsDatasetDto(releasedVersion);
        JsonObject datasetAsJson = datasetAsJsonBuilder.build();
        Iterator<Exporter> exporters = loader.iterator();
        while (exporters.hasNext()) {
            Exporter e = exporters.next();
            String formatName = e.getProviderName();
            cacheExport(releasedVersion, formatName, datasetAsJson, e);
        }
    } catch (ServiceConfigurationError serviceError) {
        throw new ExportException("Service configuration error during export. " + serviceError.getMessage());
    }
    // Finally, if we have been able to successfully export in all available
    // formats, we'll increment the "last exported" time stamp:
    dataset.setLastExportTime(new Timestamp(new Date().getTime()));
}
Also used : DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) JsonObject(javax.json.JsonObject) ServiceConfigurationError(java.util.ServiceConfigurationError) IOException(java.io.IOException) Exporter(edu.harvard.iq.dataverse.export.spi.Exporter) Timestamp(java.sql.Timestamp) Date(java.util.Date) JsonPrinter(edu.harvard.iq.dataverse.util.json.JsonPrinter) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 2 with JsonPrinter

use of edu.harvard.iq.dataverse.util.json.JsonPrinter in project dataverse by IQSS.

the class ExportService method exportFormat.

// This method finds the exporter for the format requested,
// then produces the dataset metadata as a JsonObject, then calls
// the "cacheExport()" method that will save the produced output
// in a file in the dataset directory.
public void exportFormat(Dataset dataset, String formatName) throws ExportException {
    try {
        Iterator<Exporter> exporters = loader.iterator();
        while (exporters.hasNext()) {
            Exporter e = exporters.next();
            if (e.getProviderName().equals(formatName)) {
                DatasetVersion releasedVersion = dataset.getReleasedVersion();
                if (releasedVersion == null) {
                    throw new IllegalStateException("No Released Version");
                }
                JsonPrinter jsonPrinter = new JsonPrinter(settingsService);
                final JsonObjectBuilder datasetAsJsonBuilder = jsonPrinter.jsonAsDatasetDto(releasedVersion);
                cacheExport(releasedVersion, formatName, datasetAsJsonBuilder.build(), e);
            }
        }
    } catch (ServiceConfigurationError serviceError) {
        throw new ExportException("Service configuration error during export. " + serviceError.getMessage());
    } catch (IllegalStateException e) {
        throw new ExportException("No published version found during export. " + dataset.getGlobalId());
    }
}
Also used : DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) ServiceConfigurationError(java.util.ServiceConfigurationError) Exporter(edu.harvard.iq.dataverse.export.spi.Exporter) JsonObjectBuilder(javax.json.JsonObjectBuilder) JsonPrinter(edu.harvard.iq.dataverse.util.json.JsonPrinter)

Aggregations

DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)2 Exporter (edu.harvard.iq.dataverse.export.spi.Exporter)2 JsonPrinter (edu.harvard.iq.dataverse.util.json.JsonPrinter)2 ServiceConfigurationError (java.util.ServiceConfigurationError)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 JsonObject (javax.json.JsonObject)1