use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetVersionCommand in project dataverse by IQSS.
the class Datasets method updateDraftVersion.
@PUT
@Path("{id}/versions/{versionId}")
public Response updateDraftVersion(String jsonBody, @PathParam("id") String id, @PathParam("versionId") String versionId) {
if (!":draft".equals(versionId)) {
return error(Response.Status.BAD_REQUEST, "Only the :draft version can be updated");
}
try (StringReader rdr = new StringReader(jsonBody)) {
DataverseRequest req = createDataverseRequest(findUserOrDie());
Dataset ds = findDatasetOrDie(id);
JsonObject json = Json.createReader(rdr).readObject();
DatasetVersion incomingVersion = jsonParser().parseDatasetVersion(json);
// clear possibly stale fields from the incoming dataset version.
// creation and modification dates are updated by the commands.
incomingVersion.setId(null);
incomingVersion.setVersionNumber(null);
incomingVersion.setMinorVersionNumber(null);
incomingVersion.setVersionState(DatasetVersion.VersionState.DRAFT);
incomingVersion.setDataset(ds);
incomingVersion.setCreateTime(null);
incomingVersion.setLastUpdateTime(null);
boolean updateDraft = ds.getLatestVersion().isDraft();
DatasetVersion managedVersion = execCommand(updateDraft ? new UpdateDatasetVersionCommand(req, incomingVersion) : new CreateDatasetVersionCommand(req, ds, incomingVersion));
return ok(json(managedVersion));
} catch (JsonParseException ex) {
logger.log(Level.SEVERE, "Semantic error parsing dataset version Json: " + ex.getMessage(), ex);
return error(Response.Status.BAD_REQUEST, "Error parsing dataset version: " + ex.getMessage());
} catch (WrappedResponse ex) {
return ex.getResponse();
}
}
use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetVersionCommand in project dataverse by IQSS.
the class FileRecordWriter method updateDatasetVersion.
// utils
/**
* Update the dataset version using the command engine so permissions and constraints are enforced.
* Log errors to both the glassfish log and in the job context, as the exit status "failed".
*
* @param version dataset version
*/
private void updateDatasetVersion(DatasetVersion version) {
// update version using the command engine to enforce user permissions and constraints
if (dataset.getVersions().size() == 1 && version.getVersionState() == DatasetVersion.VersionState.DRAFT) {
try {
Command<DatasetVersion> cmd;
cmd = new UpdateDatasetVersionCommand(new DataverseRequest(user, (HttpServletRequest) null), version);
commandEngine.submit(cmd);
} catch (CommandException ex) {
String commandError = "CommandException updating DatasetVersion from batch job: " + ex.getMessage();
getJobLogger().log(Level.SEVERE, commandError);
jobContext.setExitStatus("FAILED");
}
} else {
String constraintError = "ConstraintException updating DatasetVersion form batch job: dataset must be a " + "single version in draft mode.";
getJobLogger().log(Level.SEVERE, constraintError);
jobContext.setExitStatus("FAILED");
}
}
Aggregations