use of edu.harvard.iq.dataverse.DatasetVersionUser 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.DatasetVersionUser 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;
}
use of edu.harvard.iq.dataverse.DatasetVersionUser 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;
}
use of edu.harvard.iq.dataverse.DatasetVersionUser in project dataverse by IQSS.
the class SubmitDatasetForReviewCommandTest 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 TestEntityManager() {
@Override
public <T> T merge(T entity) {
return entity;
}
@Override
public void flush() {
// nothing to do here
}
};
}
@Override
public DatasetServiceBean datasets() {
return new DatasetServiceBean() {
{
em = new NoOpTestEntityManager();
}
@Override
public DatasetVersionUser getDatasetVersionUser(DatasetVersion version, User user) {
return null;
}
@Override
public DatasetLock addDatasetLock(Long datasetId, DatasetLock.Reason reason, Long userId, String info) {
return null;
}
};
}
@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.DatasetVersionUser in project dataverse by IQSS.
the class FinalizeDatasetPublicationCommand method execute.
@Override
public Dataset execute(CommandContext ctxt) throws CommandException {
registerExternalIdentifier(theDataset, ctxt);
if (theDataset.getPublicationDate() == null) {
theDataset.setReleaseUser((AuthenticatedUser) getUser());
theDataset.setPublicationDate(new Timestamp(new Date().getTime()));
}
// update metadata
Timestamp updateTime = new Timestamp(new Date().getTime());
theDataset.getEditVersion().setReleaseTime(updateTime);
theDataset.getEditVersion().setLastUpdateTime(updateTime);
theDataset.setModificationTime(updateTime);
theDataset.setFileAccessRequest(theDataset.getLatestVersion().getTermsOfUseAndAccess().isFileAccessRequest());
updateFiles(updateTime, ctxt);
//
// TODO: Not sure if this .merge() is necessary here - ?
// I'm moving a bunch of code from PublishDatasetCommand here; and this .merge()
// comes from there. There's a chance that the final merge, at the end of this
// command, would be sufficient. -- L.A. Sep. 6 2017
theDataset = ctxt.em().merge(theDataset);
DatasetVersionUser ddu = ctxt.datasets().getDatasetVersionUser(theDataset.getLatestVersion(), getUser());
if (ddu == null) {
ddu = new DatasetVersionUser();
ddu.setDatasetVersion(theDataset.getLatestVersion());
String id = getUser().getIdentifier();
id = id.startsWith("@") ? id.substring(1) : id;
AuthenticatedUser au = ctxt.authentication().getAuthenticatedUser(id);
ddu.setAuthenticatedUser(au);
}
ddu.setLastUpdateDate((Timestamp) updateTime);
ctxt.em().merge(ddu);
updateParentDataversesSubjectsField(theDataset, ctxt);
publicizeExternalIdentifier(theDataset, ctxt);
PrivateUrl privateUrl = ctxt.engine().submit(new GetPrivateUrlCommand(getRequest(), theDataset));
if (privateUrl != null) {
ctxt.engine().submit(new DeletePrivateUrlCommand(getRequest(), theDataset));
}
theDataset.getEditVersion().setVersionState(DatasetVersion.VersionState.RELEASED);
exportMetadata(ctxt.settings());
boolean doNormalSolrDocCleanUp = true;
ctxt.index().indexDataset(theDataset, doNormalSolrDocCleanUp);
ctxt.solrIndex().indexPermissionsForOneDvObject(theDataset);
// Remove locks
ctxt.engine().submit(new RemoveLockCommand(getRequest(), theDataset, DatasetLock.Reason.Workflow));
if (theDataset.isLockedFor(DatasetLock.Reason.InReview)) {
ctxt.engine().submit(new RemoveLockCommand(getRequest(), theDataset, DatasetLock.Reason.InReview));
}
ctxt.workflows().getDefaultWorkflow(TriggerType.PostPublishDataset).ifPresent(wf -> {
try {
ctxt.workflows().start(wf, buildContext(doiProvider, TriggerType.PostPublishDataset));
} catch (CommandException ex) {
logger.log(Level.SEVERE, "Error invoking post-publish workflow: " + ex.getMessage(), ex);
}
});
Dataset resultSet = ctxt.em().merge(theDataset);
if (resultSet != null) {
notifyUsersDatasetPublish(ctxt, theDataset);
}
return resultSet;
}
Aggregations