Search in sources :

Example 66 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class RestrictFileCommand method executeImpl.

@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
    // check if public install & don't allow
    boolean defaultValue = false;
    boolean publicInstall = ctxt.settings().isTrueForKey(SettingsServiceBean.Key.PublicInstall, defaultValue);
    if (publicInstall) {
        throw new CommandExecutionException("Restricting files is not permitted on a public installation.", this);
    }
    if (file.getOwner() == null) {
        // this is a new file through upload, restrict
        file.getFileMetadata().setRestricted(restrict);
        file.setRestricted(restrict);
    } else {
        Dataset dataset = file.getOwner();
        DatasetVersion workingVersion = dataset.getEditVersion();
        // check if this file is already restricted or already unrestricted
        if ((restrict && file.getFileMetadata().isRestricted()) || (!restrict && !file.getFileMetadata().isRestricted())) {
            String text = restrict ? "restricted" : "unrestricted";
            throw new CommandExecutionException("File " + file.getDisplayName() + " is already " + text, this);
        }
        // check if this dataset is a draft (should be), then we can update restrict
        if (workingVersion.isDraft()) {
            // because we must update the working version metadata
            if (dataset.isReleased()) {
                for (FileMetadata fmw : workingVersion.getFileMetadatas()) {
                    if (file.equals(fmw.getDataFile())) {
                        fmw.setRestricted(restrict);
                        if (!file.isReleased()) {
                            file.setRestricted(restrict);
                        }
                    }
                }
            } else {
                file.getFileMetadata().setRestricted(restrict);
                if (!file.isReleased()) {
                    file.setRestricted(restrict);
                }
                if (file.getFileMetadata().isRestricted() != restrict) {
                    throw new CommandExecutionException("Failed to update the file metadata", this);
                }
            }
        } else {
            throw new CommandExecutionException("Working version must be a draft", this);
        }
    }
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) CommandExecutionException(edu.harvard.iq.dataverse.engine.command.exception.CommandExecutionException)

Example 67 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class SubmitDatasetForReviewCommand method execute.

@Override
public Dataset execute(CommandContext ctxt) throws CommandException {
    if (theDataset == null) {
        throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.submit.failure.null"), this);
    }
    if (theDataset.getLatestVersion().isReleased()) {
        throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.submit.failure.isReleased"), this);
    }
    if (theDataset.getLatestVersion().isInReview()) {
        throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.submit.failure.inReview"), this);
    }
    // SEK 9-1 Add Lock before saving dataset
    DatasetLock inReviewLock = new DatasetLock(DatasetLock.Reason.InReview, getRequest().getAuthenticatedUser());
    ctxt.engine().submit(new AddLockCommand(getRequest(), theDataset, inReviewLock));
    Dataset updatedDataset = save(ctxt);
    return updatedDataset;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) DatasetLock(edu.harvard.iq.dataverse.DatasetLock)

Example 68 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class SubmitDatasetForReviewCommand method save.

public Dataset save(CommandContext ctxt) throws CommandException {
    Timestamp updateTime = new Timestamp(new Date().getTime());
    theDataset.getEditVersion().setLastUpdateTime(updateTime);
    theDataset.setModificationTime(updateTime);
    Dataset savedDataset = ctxt.em().merge(theDataset);
    ctxt.em().flush();
    DatasetVersionUser ddu = ctxt.datasets().getDatasetVersionUser(theDataset.getLatestVersion(), this.getUser());
    if (ddu != null) {
        ddu.setLastUpdateDate(updateTime);
        ctxt.em().merge(ddu);
    } else {
        // TODO: This logic to update the DatasetVersionUser was copied from UpdateDatasetCommand and also appears in CreateDatasetCommand, PublishDatasetCommand UpdateDatasetCommand, and ReturnDatasetToAuthorCommand. Consider consolidating.
        DatasetVersionUser datasetDataverseUser = new DatasetVersionUser();
        datasetDataverseUser.setDatasetVersion(savedDataset.getLatestVersion());
        datasetDataverseUser.setLastUpdateDate((Timestamp) updateTime);
        String id = getUser().getIdentifier();
        id = id.startsWith("@") ? id.substring(1) : id;
        AuthenticatedUser au = ctxt.authentication().getAuthenticatedUser(id);
        datasetDataverseUser.setAuthenticatedUser(au);
        ctxt.em().merge(datasetDataverseUser);
    }
    List<AuthenticatedUser> authUsers = ctxt.permissions().getUsersWithPermissionOn(Permission.PublishDataset, savedDataset);
    for (AuthenticatedUser au : authUsers) {
        ctxt.notifications().sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.SUBMITTEDDS, savedDataset.getLatestVersion().getId());
    }
    // TODO: What should we do with the indexing result? Print it to the log?
    boolean doNormalSolrDocCleanUp = true;
    Future<String> indexingResult = ctxt.index().indexDataset(savedDataset, doNormalSolrDocCleanUp);
    return savedDataset;
}
Also used : DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) Dataset(edu.harvard.iq.dataverse.Dataset) Timestamp(java.sql.Timestamp) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Date(java.util.Date)

Example 69 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class ReturnDatasetToAuthorCommand method save.

public Dataset save(CommandContext ctxt) throws CommandException {
    Timestamp updateTime = new Timestamp(new Date().getTime());
    theDataset.getEditVersion().setLastUpdateTime(updateTime);
    // We set "in review" to false because now the ball is back in the author's court.
    theDataset.setModificationTime(updateTime);
    // TODO: ctxt.datasets().removeDatasetLocks() doesn't work. Try RemoveLockCommand?
    AuthenticatedUser authenticatedUser = null;
    for (DatasetLock lock : theDataset.getLocks()) {
        if (DatasetLock.Reason.InReview.equals(lock.getReason())) {
            theDataset.removeLock(lock);
            // TODO: Are we supposed to remove the dataset lock from the user? What's going on here?
            authenticatedUser = lock.getUser();
        }
    }
    Dataset savedDataset = ctxt.em().merge(theDataset);
    ctxt.em().flush();
    DatasetVersionUser ddu = ctxt.datasets().getDatasetVersionUser(theDataset.getLatestVersion(), this.getUser());
    WorkflowComment workflowComment = new WorkflowComment(theDataset.getEditVersion(), WorkflowComment.Type.RETURN_TO_AUTHOR, comment, (AuthenticatedUser) this.getUser());
    ctxt.datasets().addWorkflowComment(workflowComment);
    if (ddu != null) {
        ddu.setLastUpdateDate(updateTime);
        ctxt.em().merge(ddu);
    } else {
        // TODO: This logic to update the DatasetVersionUser was copied from UpdateDatasetCommand and also appears in CreateDatasetCommand, PublishDatasetCommand UpdateDatasetCommand, and SubmitDatasetForReviewCommand. Consider consolidating.
        DatasetVersionUser datasetDataverseUser = new DatasetVersionUser();
        datasetDataverseUser.setDatasetVersion(savedDataset.getLatestVersion());
        datasetDataverseUser.setLastUpdateDate(updateTime);
        String id = getUser().getIdentifier();
        id = id.startsWith("@") ? id.substring(1) : id;
        AuthenticatedUser au = ctxt.authentication().getAuthenticatedUser(id);
        datasetDataverseUser.setAuthenticatedUser(au);
        ctxt.em().merge(datasetDataverseUser);
    }
    /*
            So what we're doing here is sending notifications to the authors who do not have publish permissions
            First get users who can publish - or in this case review
            Then get authors.
            Then remove reviewers from the autors list
            Finally send a notification to the remaining (non-reviewing) authors - Hey! your dataset was rejected.
        */
    List<AuthenticatedUser> reviewers = ctxt.permissions().getUsersWithPermissionOn(Permission.PublishDataset, savedDataset);
    List<AuthenticatedUser> authors = ctxt.permissions().getUsersWithPermissionOn(Permission.EditDataset, savedDataset);
    for (AuthenticatedUser au : reviewers) {
        authors.remove(au);
    }
    for (AuthenticatedUser au : authors) {
        ctxt.notifications().sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.RETURNEDDS, savedDataset.getLatestVersion().getId(), comment);
    }
    // TODO: What should we do with the indexing result? Print it to the log?
    boolean doNormalSolrDocCleanUp = true;
    Future<String> indexingResult = ctxt.index().indexDataset(savedDataset, doNormalSolrDocCleanUp);
    return savedDataset;
}
Also used : DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) Dataset(edu.harvard.iq.dataverse.Dataset) WorkflowComment(edu.harvard.iq.dataverse.workflows.WorkflowComment) DatasetLock(edu.harvard.iq.dataverse.DatasetLock) Timestamp(java.sql.Timestamp) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Date(java.util.Date)

Example 70 with Dataset

use of edu.harvard.iq.dataverse.Dataset in project dataverse by IQSS.

the class SetDatasetCitationDateCommand method execute.

@Override
public Dataset execute(CommandContext ctxt) throws CommandException {
    if (dsfType == null || dsfType.getFieldType().equals(FieldType.DATE)) {
        dataset.setCitationDateDatasetFieldType(dsfType);
    } else {
        throw new IllegalCommandException("Provided DatasetFieldtype is not a Date", this);
    }
    Dataset savedDataset = ctxt.datasets().merge(dataset);
    ctxt.index().indexDataset(savedDataset, false);
    return savedDataset;
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)

Aggregations

Dataset (edu.harvard.iq.dataverse.Dataset)142 Test (org.junit.Test)53 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)44 DataFile (edu.harvard.iq.dataverse.DataFile)41 Dataverse (edu.harvard.iq.dataverse.Dataverse)34 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)27 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)22 Path (javax.ws.rs.Path)22 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)17 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)17 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)16 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)16 Date (java.util.Date)16 JsonObjectBuilder (javax.json.JsonObjectBuilder)16 JsonObject (javax.json.JsonObject)15 DvObject (edu.harvard.iq.dataverse.DvObject)14 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)14 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)14