use of edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand in project dataverse by IQSS.
the class DatasetPage method restrictFiles.
public void restrictFiles(boolean restricted) throws CommandException {
// when the code between the 2 beans is merged in 4.3.
if (editMode != EditMode.CREATE) {
previouslyRestrictedFiles = new ArrayList<>();
for (FileMetadata fmd : workingVersion.getFileMetadatas()) {
if (fmd.isRestricted()) {
previouslyRestrictedFiles.add(fmd);
}
}
Command cmd;
String fileNames = null;
for (FileMetadata fmw : workingVersion.getFileMetadatas()) {
for (FileMetadata fmd : this.getSelectedFiles()) {
if (restricted && !fmw.isRestricted()) {
// message isn't used, normally)
if (fileNames == null) {
fileNames = fmd.getLabel();
} else {
fileNames = fileNames.concat(fmd.getLabel());
}
}
if (fmd.getDataFile().equals(fmw.getDataFile())) {
cmd = new RestrictFileCommand(fmw.getDataFile(), dvRequestService.getDataverseRequest(), restricted);
commandEngine.submit(cmd);
// fmw.setRestricted(restricted);
// if (workingVersion.isDraft() && !fmw.getDataFile().isReleased()) {
// // We do not really need to check that the working version is
// // a draft here - it must be a draft, if we've gotten this
// // far. But just in case. -- L.A. 4.2.1
// fmw.getDataFile().setRestricted(restricted);
// }
}
}
}
if (fileNames != null) {
String successMessage = JH.localize("file.restricted.success");
logger.fine(successMessage);
successMessage = successMessage.replace("{0}", fileNames);
JsfHelper.addFlashMessage(successMessage);
}
}
}
use of edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand 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.RestrictFileCommand in project dataverse by IQSS.
the class FilePage method restrictFile.
public String restrictFile(boolean restricted) throws CommandException {
String fileNames = null;
String termsOfAccess = this.fileMetadata.getDatasetVersion().getTermsOfUseAndAccess().getTermsOfAccess();
Boolean allowRequest = this.fileMetadata.getDatasetVersion().getTermsOfUseAndAccess().isFileAccessRequest();
editDataset = this.file.getOwner();
Command cmd;
for (FileMetadata fmw : editDataset.getEditVersion().getFileMetadatas()) {
if (fmw.getDataFile().equals(this.fileMetadata.getDataFile())) {
fileNames += fmw.getLabel();
// fmw.setRestricted(restricted);
cmd = new RestrictFileCommand(fmw.getDataFile(), dvRequestService.getDataverseRequest(), restricted);
commandEngine.submit(cmd);
}
}
editDataset.getEditVersion().getTermsOfUseAndAccess().setTermsOfAccess(termsOfAccess);
editDataset.getEditVersion().getTermsOfUseAndAccess().setFileAccessRequest(allowRequest);
if (fileNames != null) {
String successMessage = JH.localize("file.restricted.success");
successMessage = successMessage.replace("{0}", fileNames);
JsfHelper.addFlashMessage(successMessage);
}
save();
init();
return returnToDraftVersion();
}
use of edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand in project dataverse by IQSS.
the class AddReplaceFileHelper method step_055_loadOptionalFileParams.
/**
* Load optional file params such as description, tags, fileDataTags, etc..
*
* @param optionalFileParams
* @return
*/
private boolean step_055_loadOptionalFileParams(OptionalFileParams optionalFileParams) {
if (hasError()) {
return false;
}
// --------------------------------------------
if (optionalFileParams == null) {
return true;
}
// --------------------------------------------
for (DataFile df : finalFileList) {
try {
optionalFileParams.addOptionalParams(df);
// call restriction command here
boolean restrict = optionalFileParams.getRestriction();
if (restrict != df.getFileMetadata().isRestricted()) {
commandEngine.submit(new RestrictFileCommand(df, dvRequest, restrict));
}
} catch (DataFileTagException ex) {
Logger.getLogger(AddReplaceFileHelper.class.getName()).log(Level.SEVERE, null, ex);
addError(ex.getMessage());
return false;
} catch (CommandException ex) {
addError(ex.getMessage());
}
}
return true;
}
Aggregations