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