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();
}
};
}
});
}
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;
}
Aggregations