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()));
}
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());
}
}
Aggregations