Search in sources :

Example 1 with WorkflowComment

use of edu.harvard.iq.dataverse.workflows.WorkflowComment in project dataverse by IQSS.

the class ReturnDatasetToAuthorCommandTest method setUp.

@Before
public void setUp() {
    dataset = new Dataset();
    HttpServletRequest aHttpServletRequest = null;
    dataverseRequest = new DataverseRequest(MocksFactory.makeAuthenticatedUser("First", "Last"), aHttpServletRequest);
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public AuthenticationServiceBean authentication() {
            return new AuthenticationServiceBean() {

                @Override
                public AuthenticatedUser getAuthenticatedUser(String id) {
                    return MocksFactory.makeAuthenticatedUser("First", "Last");
                }
            };
        }

        @Override
        public IndexServiceBean index() {
            return new IndexServiceBean() {

                @Override
                public Future<String> indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) {
                    return null;
                }
            };
        }

        @Override
        public EntityManager em() {
            return new NoOpTestEntityManager();
        }

        @Override
        public DatasetServiceBean datasets() {
            return new DatasetServiceBean() {

                {
                    em = new NoOpTestEntityManager();
                }

                @Override
                public DatasetVersionUser getDatasetVersionUser(DatasetVersion version, User user) {
                    return null;
                }

                @Override
                public WorkflowComment addWorkflowComment(WorkflowComment comment) {
                    return comment;
                }

                @Override
                public void removeDatasetLocks(Long datasetId, DatasetLock.Reason aReason) {
                }
            };
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return new DataverseRoleServiceBean() {

                @Override
                public DataverseRole findBuiltinRoleByAlias(String alias) {
                    return new DataverseRole();
                }

                @Override
                public RoleAssignment save(RoleAssignment assignment) {
                    // no-op
                    return assignment;
                }
            };
        }

        @Override
        public PermissionServiceBean permissions() {
            return new PermissionServiceBean() {

                @Override
                public List<AuthenticatedUser> getUsersWithPermissionOn(Permission permission, DvObject dvo) {
                    // We only need permissions for notifications, which we are testing in InReviewWorkflowIT.
                    return Collections.emptyList();
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) PermissionServiceBean(edu.harvard.iq.dataverse.PermissionServiceBean) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) WorkflowComment(edu.harvard.iq.dataverse.workflows.WorkflowComment) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) NoOpTestEntityManager(edu.harvard.iq.dataverse.engine.NoOpTestEntityManager) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) AuthenticationServiceBean(edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DatasetServiceBean(edu.harvard.iq.dataverse.DatasetServiceBean) Permission(edu.harvard.iq.dataverse.authorization.Permission) IndexServiceBean(edu.harvard.iq.dataverse.search.IndexServiceBean) Before(org.junit.Before)

Example 2 with WorkflowComment

use of edu.harvard.iq.dataverse.workflows.WorkflowComment 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)

Aggregations

Dataset (edu.harvard.iq.dataverse.Dataset)2 DatasetVersionUser (edu.harvard.iq.dataverse.DatasetVersionUser)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 WorkflowComment (edu.harvard.iq.dataverse.workflows.WorkflowComment)2 DatasetLock (edu.harvard.iq.dataverse.DatasetLock)1 DatasetServiceBean (edu.harvard.iq.dataverse.DatasetServiceBean)1 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)1 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)1 DvObject (edu.harvard.iq.dataverse.DvObject)1 PermissionServiceBean (edu.harvard.iq.dataverse.PermissionServiceBean)1 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)1 AuthenticationServiceBean (edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean)1 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)1 Permission (edu.harvard.iq.dataverse.authorization.Permission)1 User (edu.harvard.iq.dataverse.authorization.users.User)1 NoOpTestEntityManager (edu.harvard.iq.dataverse.engine.NoOpTestEntityManager)1 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)1 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)1 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)1 IndexServiceBean (edu.harvard.iq.dataverse.search.IndexServiceBean)1