use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand in project dataverse by IQSS.
the class Files method restrictFileInDataset.
/**
* Restrict or Unrestrict an Existing File
* @author sarahferry
*
* @param fileToRestrictId
* @param restrictStr
* @return
*/
@PUT
@Path("{id}/restrict")
public Response restrictFileInDataset(@PathParam("id") Long fileToRestrictId, String restrictStr) {
// create request
DataverseRequest dataverseRequest = null;
// get the datafile
DataFile dataFile = fileService.find(fileToRestrictId);
if (dataFile == null) {
return error(BAD_REQUEST, "Could not find datafile with id " + fileToRestrictId);
}
boolean restrict = Boolean.valueOf(restrictStr);
try {
dataverseRequest = createDataverseRequest(findUserOrDie());
} catch (WrappedResponse wr) {
return error(BAD_REQUEST, "Couldn't find user to execute command: " + wr.getLocalizedMessage());
}
// try to restrict the datafile
try {
engineSvc.submit(new RestrictFileCommand(dataFile, dataverseRequest, restrict));
} catch (CommandException ex) {
return error(BAD_REQUEST, "Problem trying to update restriction status on " + dataFile.getDisplayName() + ": " + ex.getLocalizedMessage());
}
// update the dataset
try {
engineSvc.submit(new UpdateDatasetCommand(dataFile.getOwner(), dataverseRequest));
} catch (CommandException ex) {
return error(BAD_REQUEST, "Problem saving datafile " + dataFile.getDisplayName() + ": " + ex.getLocalizedMessage());
}
String text = restrict ? "restricted." : "unrestricted.";
return ok("File " + dataFile.getDisplayName() + " " + text);
}
use of edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand in project dataverse by IQSS.
the class FilePage method save.
public String save() {
// Validate
Set<ConstraintViolation> constraintViolations = this.fileMetadata.getDatasetVersion().validate();
if (!constraintViolations.isEmpty()) {
// JsfHelper.addFlashMessage(JH.localize("dataset.message.validationError"));
fileDeleteInProgress = false;
JH.addMessage(FacesMessage.SEVERITY_ERROR, JH.localize("dataset.message.validationError"));
// FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Validation Error", "See below for details."));
return "";
}
Command<Dataset> cmd;
try {
cmd = new UpdateDatasetCommand(editDataset, dvRequestService.getDataverseRequest(), filesToBeDeleted);
commandEngine.submit(cmd);
} catch (EJBException ex) {
StringBuilder error = new StringBuilder();
error.append(ex).append(" ");
error.append(ex.getMessage()).append(" ");
Throwable cause = ex;
while (cause.getCause() != null) {
cause = cause.getCause();
error.append(cause).append(" ");
error.append(cause.getMessage()).append(" ");
}
return null;
} catch (CommandException ex) {
fileDeleteInProgress = false;
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Dataset Save Failed", " - " + ex.toString()));
return null;
}
if (fileDeleteInProgress) {
JsfHelper.addSuccessMessage(JH.localize("file.message.deleteSuccess"));
fileDeleteInProgress = false;
} else {
JsfHelper.addSuccessMessage(JH.localize("file.message.editSuccess"));
}
setVersion("DRAFT");
return "";
}
Aggregations