Search in sources :

Example 1 with RestrictFileCommand

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);
        }
    }
}
Also used : LinkDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.LinkDatasetCommand) GetPrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.GetPrivateUrlCommand) DestroyDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.DestroyDatasetCommand) CreateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand) ReturnDatasetToAuthorCommand(edu.harvard.iq.dataverse.engine.command.impl.ReturnDatasetToAuthorCommand) SubmitDatasetForReviewCommand(edu.harvard.iq.dataverse.engine.command.impl.SubmitDatasetForReviewCommand) CreatePrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.CreatePrivateUrlCommand) UpdateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand) RestrictFileCommand(edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand) GetLatestPublishedDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.GetLatestPublishedDatasetVersionCommand) PublishDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.PublishDatasetCommand) PublishDataverseCommand(edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand) Command(edu.harvard.iq.dataverse.engine.command.Command) DeaccessionDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.DeaccessionDatasetVersionCommand) DeletePrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.DeletePrivateUrlCommand) DeleteDatasetVersionCommand(edu.harvard.iq.dataverse.engine.command.impl.DeleteDatasetVersionCommand) RequestRsyncScriptCommand(edu.harvard.iq.dataverse.engine.command.impl.RequestRsyncScriptCommand) RestrictFileCommand(edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand)

Example 2 with RestrictFileCommand

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);
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DataFile(edu.harvard.iq.dataverse.DataFile) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) RestrictFileCommand(edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand) UpdateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 3 with RestrictFileCommand

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();
}
Also used : RestrictFileCommand(edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand) Command(edu.harvard.iq.dataverse.engine.command.Command) CreateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand) UpdateDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand) RestrictFileCommand(edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand)

Example 4 with RestrictFileCommand

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;
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) RestrictFileCommand(edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand)

Aggregations

RestrictFileCommand (edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand)4 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)3 DataFile (edu.harvard.iq.dataverse.DataFile)2 Command (edu.harvard.iq.dataverse.engine.command.Command)2 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)2 CreateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand)2 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)1 CreatePrivateUrlCommand (edu.harvard.iq.dataverse.engine.command.impl.CreatePrivateUrlCommand)1 DeaccessionDatasetVersionCommand (edu.harvard.iq.dataverse.engine.command.impl.DeaccessionDatasetVersionCommand)1 DeleteDatasetVersionCommand (edu.harvard.iq.dataverse.engine.command.impl.DeleteDatasetVersionCommand)1 DeletePrivateUrlCommand (edu.harvard.iq.dataverse.engine.command.impl.DeletePrivateUrlCommand)1 DestroyDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.DestroyDatasetCommand)1 GetLatestPublishedDatasetVersionCommand (edu.harvard.iq.dataverse.engine.command.impl.GetLatestPublishedDatasetVersionCommand)1 GetPrivateUrlCommand (edu.harvard.iq.dataverse.engine.command.impl.GetPrivateUrlCommand)1 LinkDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.LinkDatasetCommand)1 PublishDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.PublishDatasetCommand)1 PublishDataverseCommand (edu.harvard.iq.dataverse.engine.command.impl.PublishDataverseCommand)1 RequestRsyncScriptCommand (edu.harvard.iq.dataverse.engine.command.impl.RequestRsyncScriptCommand)1 ReturnDatasetToAuthorCommand (edu.harvard.iq.dataverse.engine.command.impl.ReturnDatasetToAuthorCommand)1 SubmitDatasetForReviewCommand (edu.harvard.iq.dataverse.engine.command.impl.SubmitDatasetForReviewCommand)1